Open GoogleCodeExporter opened 8 years ago
What steps will reproduce the problem? Out of sync PPM generation. 1. Put Spektrum DX8 in programmable slave on all channel. 2- Connect Arduino pin 10 to Trainer port input. 3- Press Trainer switch when NO SLAVE switches to MASTER. 4- Go to monitoring screen and watch outputs ...All screwed up. What is the expected output? What do you see instead? Stable signals as per ISR usage from another code I downloaded. What version of the product are you using? On what operating system? Arduino Nano V3.0, pin 10. Try this one ;) /* PPM Tester (8 channel) By Kelly Perreault INFORMATION: See ReadMe.txt for lots of info including I/O allocation. */ #include "EEPROM.h" char* Version[]={"Version", " 1.0 "}; // User adjustable settings int pulseMin =420, pulseMid = 1250, pulseMax = 1250; // PPM Pulse widths in uS // Manual Timer, Interrupt Timer vars unsigned char TimerStart = 0; int secflag = 0, minflag = 0; int PPM_array[9]; int PPMFreq_uS = 22000; // PPM frame length total in uS int Fixed_uS = 400; // PPM frame padding LOW phase in uS // Assign analogue & digital I/O pins int AI_Raw[7] = { 0, 1, 2, 3, 4, 5, 6 }; // actual analog input pins int AI_Val[7]; // analogue input vars int DI_Raw[10] = { 2, 3, 4, 5, 6, 7, 8, 9, 13, 11 }; // actual digital input pins int DI_Val[10]; // digital input vars unsigned char AI_pincount = 7; // analogue pin count unsigned char DI_pincount = 10; // digital pin count unsigned char outPinPPM = 10; // PPM output pin (do not change - pin 10 tied to ISR // Sub timing vars int tick0 = 0, tick1 = 0, tick2 = 0, tick3 = 0, tick4=0, band=0,band2=0, currch=1; unsigned char slowflag; int ACC_PPM_length = 0; // Pulse length current total, used to calculate sync pulse int *PPM_pointer = PPM_array; int PPM_len; // *********************** Setup ************************** void setup() { // Setup Digital I/O pinMode(outPinPPM, OUTPUT); // sets as output for(char i=0; i<DI_pincount; i++) { pinMode(DI_Raw[i], INPUT); } // set digital inputs for(char i=0; i<DI_pincount; i++) { digitalWrite(DI_Raw[i], HIGH); } // turn on pull-up resistors // Initialize PPM channel array char i=0; for(i=0; i<8; i++) { PPM_array[i] = pulseMin; } PPM_array[i] = -1; // Mark end // Initialise ISR Timer 1 - PPM generation TCCR1A = B00110001; // Compare register B used in mode 3 TCCR1B = B00010010; // WGM13 & CS11 set to 1 TCCR1C = B00000000; // All set to 0 TIMSK1 = B00000010; // Interrupt on compare B TIFR1 = B00000010; // Interrupt on compare B OCR1A = PPMFreq_uS; // PPM frequency OCR1B = Fixed_uS; // PPM off time (lo padding) // Initialise ISR Timer 2 - Subroutine timing // Interrupt rate = 16MHz / (prescaler * (255 - TCNT2)) // period [sec] = (1 / f_clock [sec]) * prescale * (255-count) // (1/16000000) * 1024 * (255-178) = .004992sec = 4.992mS TCCR2B = B00000000; // Disable Timer2 while we set it up TCNT2 = 178; // Reset Timer Count (255-"178") TIFR2 = B00000000; // Timer2 INT Flag Reg: Clear Timer Overflow Flag TIMSK2 = B00000001; // Timer2 INT Reg: Timer2 Overflow Interrupt Enable TCCR2A = B00000000; // Timer2 Control Reg A: Wave Gen Mode normal TCCR2B = B00000111; // Timer2 Control Reg B: Timer Prescaler set to 1024 // INFO ******************************************** //1150 all except 1 for start at -108% to 38% (thr at 60%), 400 for array 1, band 250 , skip 1 //1170 all except 1 for start at -92% to 32%, 680 for array 1, band 250 , skip 1 //1150 all except 1 for start at -108% to 38% (thr at 45%), 600 for array 1, band 250 , skip 1 //1139 all except 1 for start at -100% to 32%, 500 for array 1, band 250 , skip 1 //940 all except 1 for start at -150% to 0% , 700 for array 1, band 230 , skip 1 //940 all except 1 for start at -150% to 40% , 420 for array 1, band 100/2=50 , skip 1 PPM_array[0] = 940; //Ax3 CH1 PPM_array[1] = 420; //Ax2 CH2 default put to 1000=NO SYNC , 900=40%, 800=40% 700= 34%, 600=34% , 500=39%, 400=39% , 300=NO SYNC(toggle min or max) ,varies with AX1 PPM_array[2] = 940; //THR CH3 PPM_array[3] = 940; //AIL CH4 PPM_array[4] = 940; //ELE CH5 PPM_array[5] = 940; //RUD CH6 PPM_array[6] = 940; //GER CH7 PPM_array[7] = 940; //AX1 CH8 } // *********************** Main Loop ************************** void loop() { // Main loop // Read all input pins into AI var array 1 for(byte i=0; i<AI_pincount; i++) { AI_Val[i] = analogRead(AI_Raw[i]); } if (tick0 >= 25) { // Run these subs every 124.8mS tick0 = 0; } band=103; band2=band*2; // Generate slow changing flag if (tick4 <= band) { PPM_array[currch] = PPM_array[currch]+ 1; //ELE if ( currch <> 0 currch < 7 ) { PPM_array[currch+1] = PPM_array[currch+1]+ 1; //ELE } } if (tick4 > band && tick4 <= band2) { PPM_array[currch] = PPM_array[currch]- 1; //ELE if ( currch <> 0 && currch < 7 ) { PPM_array[currch+1] = PPM_array[currch+1]- 1; //ELE } if (tick4 > band2) { PPM_array[currch]=PPM_array[currch]-7; currch= currch +1; tick4 = 0; } if (currch == 1) { currch=2; //skip ch 2 - Ax2 - array 1 } if (currch >= 8) { currch=0; } if (tick1 <= 50) { slowflag = 0; } if (tick1 >= 50 && tick1 <=100) { slowflag = 1; } if (tick1 == 100) { tick1 = 0; } // generate 1sec tick if (TimerStart == 0) { if (tick2 >= 160) { // 1000mS secflag++; tick2 = 0; } if (secflag >= 60) { secflag = 0; minflag++; } if (minflag >= 100) { minflag = 0; } } } // *********************** TIMER 1 ************************** ISR(TIMER1_COMPA_vect) { PPM_len = *(PPM_pointer++); if(PPM_len > -1) { OCR1A = PPM_len; // Set pulse length ACC_PPM_length += PPM_len; // Add pulse length to accumulator } else { PPM_pointer = PPM_array; // Reset table position pointer OCR1A = PPMFreq_uS - ACC_PPM_length; // Calculate final sync pulse length ACC_PPM_length = 0; // Reset accumulator } } // *********************** TIMER 2 ************************** ISR(TIMER2_OVF_vect) { tick0 = tick0 + 1; // update timing tick tick1 = tick1 + 1; // update timing tick tick2 = tick2 + 1; // update timing tick tick3 = tick3 + 1; // update timing tick tick4 = tick4 + 1; // update timing tick TCNT2 = 155; // reset timer cnt to 155 out of 255 TIFR2 = 0x00; // timer2 int flag reg: clear timer overflow flag }
Original issue reported on code.google.com by clearchr...@gmail.com on 25 Jan 2015 at 9:07
clearchr...@gmail.com
Oups , step 1 should be programmable MASTER ...not Programmable Slave.
Original comment by clearchr...@gmail.com on 25 Jan 2015 at 9:08
Original issue reported on code.google.com by
clearchr...@gmail.com
on 25 Jan 2015 at 9:07