mcookieman 3 Posted October 6, 2011 Share Posted October 6, 2011 First post! Hello, I'm currently making a RC remote for my quadcopter which I am in the process of building. The idea is to output a ppm frame which then goes into a FrSky module which beams it to a receiver on my quadcopter. I currently have the code for ppm generation done. I am reading up on i2c with the UCSI module in the msp430g2553 right now and will hook it up to a wii nunchuk for testing. The end product will have recycled gymbals from an esky transmitter remote hooked up to it's own microcontroller acting as an i2c slave to the ppm generation microcontroller. #include #include int Pnum = 1; //Stores the number of pulses triggered so far in current ppm frame int servo[8] = {1000,1150,1300,1450,1500,1750,1900,2000}; // Servo pulse values void main(void) { WDTCTL = WDTPW|WDTHOLD; //stop watchdog timer BCSCTL1 = CALBC1_1MHZ; DCOCTL = CALDCO_1MHZ; P1OUT = BIT6|BIT0; //Preload P1.2 on P1DIR = BIT6|BIT0; //Set P1.2 to output TA0CCR0 = 100; //Timerinitiallycountsuptothisvalue.Mustbelongenoughforeverythingtosetup TA0CCTL0 = CCIE; //Enable interrupts on CCR0 TA1CCR0 = 20000; //Length of PPM frame minus one TA0CTL = MC_1|ID_0|TASSEL_2|TACLR; //Setup TimerA0 (up mode|clock divide by 1|SMCLK|Clear timer) TA1CTL = MC_1|ID_0|TASSEL_2|TACLR; //Setup TimerA1 (up mode|clock divide by 1|SMCLK|Clear timer) __enable_interrupt(); //enable interrupts for(; //infinite loop { } } #pragma vector = TIMER0_A0_VECTOR //T0A0_ISR __interrupt void T0A0_ISR (void) { P1OUT &= ~BIT6; _delay_cycles(300); P1OUT |= BIT6; if(Pnum != 9) { TA0CCR0 = servo[(Pnum-1)]; //Servo pulse Pnum++; //increment Pnum } else { TA0CCR0 = (20000-(TA1R)); //Sync pulse Pnum = 1; //Reset Pnum } } This is the code I have right now. The way it works is Timer0 is set to count up to the value in TA0CCR0 (the length of the servo pulse). When TA0CCR0 overflows an interuppt is requested and the interrupt service routine T0A0_ISR runs. T0A0_ISR changes the value of TA0CCR0 to the next value in the array servo. After 8 pulses TA0CCR0 is set to fill in the time remaining until 20ms has passed since the start of the ppm frame. This is done by setting Timer1 to count up to 20 000 (TA1CCR0), after the 8th pulse TA0CCR0 is set to 20 000 minus the amount that Timer1 has currently counted up to, thus giving the time remaing until the end of the 20 ms. The positions of the servos are stored in the array servo as the length of each servo pulse. This array can be modified in the main loop. This code can also be used to control 8 or more(i think, depends how many pulses you can fit in a 20ms period) servos through 1 pin (selectable). All that is required is a 4017 decade counter to demultiplex the ppm signal into standard servo pwm. But there's a catch. I actually haven't tested any of this code in real life. (I accidentally killed 3 servos somehow before making this) My pickit2 logic analyzer shows me that everything is working fine though. Thanks for reading. edit: fixed array values, should range from 1000 - 2000 not 500 - 1500 bluehash, hiatus138 and oPossum 3 Quote Link to post Share on other sites
oPossum 1,083 Posted October 6, 2011 Share Posted October 6, 2011 Thanks for sharing your code. I made a PPM decoder board a few months ago, but have not had time to write the code and test it. Here are the EAGLE files for anyone who may be interested... servo_ppm.brd servo_ppm.sch mcookieman and bluehash 2 Quote Link to post Share on other sites
mcookieman 3 Posted October 7, 2011 Author Share Posted October 7, 2011 That's a nice board you have made there. Quote Link to post Share on other sites
mcookieman 3 Posted October 8, 2011 Author Share Posted October 8, 2011 I just fixed a mistake in my code, a servo pulse ranges from 1000 to 2000 microseconds not 500 to 1500. This has been changed in the first post. Quote Link to post Share on other sites
hiatus138 14 Posted October 8, 2011 Share Posted October 8, 2011 Such perfect timing! This is exactly what I need for the halloween decoration i'm making. I'll use this to control the mouths of 8 small jack-o-lanterns (see evil mad scientist labs' "snap-o-lantern) and make them "sing" a different note each, to play "tubular bells" (the theme to "The Exorcist") I'll ptobably make each pumpkin lit up with a different coloref LED also, to emphasize that each is a different note. Thanks! Quote Link to post Share on other sites
mcookieman 3 Posted October 11, 2011 Author Share Posted October 11, 2011 Good to see that someone has a use for it. Be sure to post a video of the decoration when you finish making it. Still trying to figure out how to I2C with a nunchuck. Does anyone have any code examples for the USCI module? Quote Link to post Share on other sites
Mission 0 Posted April 7, 2020 Share Posted April 7, 2020 i have build a homemade ppm decoder with CD4017 ic together with 27mhz fm transmitter and receiver. The 27mhz transmitter/receiver work correctly because i can hear the tune when connected to a small speaker, but the problem here is: despite that the encoder and the decoder working correctly when connected via negative and signal terminal directly to the decoder, it refuses to work with the remote module that i made and i dont know why is happening so. is there anyone who can tell me the problem? Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.