Hi Folks,
I know this is quite an old thread, but I thought you might be interested in this.
I decided to replace the PPM encoder board in my old Micron transmitter that I built from a kit some 15+ years ago with an arduino based solution.
This solution reads the four sticks, along with four switches and encodes them into the appropreate PPM pulse train. I have also included code for v-tail, differential and delta mixing.
The way my code differs from yours is in the way I generate the pulse train: I have used the 16bit timer (timer 1) set to phase and frequency correct PWM to generate the pulse train from an array of values.
The timer settings are:
TCCR1A = B00110001; // Compare register B used in mode '3'
TCCR1B = B00010010; // WGM13 and CS11 set to 1
TCCR1C = B00000000; // All set to 0
TIMSK1 = B00000010; // Interrupt on compare B
TIFR1 = B00000010; // Interrupt on compare B
OCR1A = timer_framelength;
OCR1B = timer_pause;
and the ISR code is:
ISR(TIMER1_COMPA_vect)
{
if (timer_ptr == number_of_outputs) {
timer_ptr = 0; //reset the pointer to 0
OCR1A = timer_framelength - (timer_accumulator * timer_correction_factor); //calculate the padding
timer_accumulator = 0; //set the accumulator to 0
}
else {
OCR1A = (pulses[timer_ptr] + timer_pause) * timer_correction_factor; //set the pulse length
timer_accumulator += pulses[timer_ptr] + timer_pause; //add the pulse length to the accumulator
timer_ptr++; //increment the pointer
}
}
and the required variables and constants are:
#define timer_correction_factor 1.09 //timer correction factor. This is needed if your arduino is too fast or slow, like mine. :(
#define timer_framelength 20000 * timer_correction_factor //Maximum framelength in counter ticks
#define timer_pause 300 * timer_correction_factor //Pause between pluses in counter ticks
int timer_accumulator = 0; //accumulator. Used to calculate the frame padding
int timer_ptr = 0; //timer array pointer
int pulses[7];
To generate the pulse train, enter values into the array corrisponding to the channel pulse in micro seconds, so for a 2000 micro seconds pulse enter 2000. The frame padding is calculated automatically.
If anyone would like to take a look at the complete source code, feel free to download it; it's just too big to post here:
http://www.miselph.co.uk/arduino/Version_0_2.zipI hope this can be of use to someone. When I have finished the project I will post the details on this forum.
If anyone needs any help with timers, I have become quite adept at dealing with them and would be more than happy to help
Chris