I'm trying to set up pin H3 as an output to generate servo pulse signals to the Axon in MCU mode.
The target timer count for servo pulse signals are calculated as follows:
Target timer count = (1 / target frequency) / (1 / timer frequency)
1.) For Axon the timer frequency is 16 MHz at 1000 us pulse:
target timer count = (1 / 1000 Hz) / ( 1 / 16 MHz) = 16,000
2.) For 1500 us:
target timer count = 10,666. 6667
3.) For 2000 us:
target timer count = 8000
Running at 16MHz, our timer needs to count to 8,000, 10,667, and
16000 counts before 1000 u, 1500 us and 2000 us has elapsed,
respectively.
Set up the DDRH (data direction register for H) as an output:
DDRH |= (1 << 3); // Set H3 as output on Register H
Start the timer at the top of our main routine, and upply a clock of Fcpu to the timer 1
circuits.
TCCR1B |= (1 << CS10); // Set up timer to system clock with no prescaler
TCNT1 = 0;
// generate 2000 usec pulse on H3
while(TCNT1 <= 8000)
{
PORTH = (1 << 3); // Send a pulse to H3
}
PORTH ^= (1<<3); // set the pulse to 0 on H3
TCNT1=0; // reset counter
// generate 1500 us pulse
while( TCNT <= 10,667){
PORTH = (1<<3);
}
PORTH ^= (1 << 3); // return to 0
TCNT1 = 0;
// generate 1000 us pulse
while(TCNT <= 16,000)
{
PORTH = (1<<3);
}
PORTH ^= (1<<3)
TCNT1 = 0;
Does this seem right?