Jump to content

mcookieman

Members
  • Content Count

    4
  • Joined

  • Last visited

  1. 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?
  2. 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.
  3. 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
×
×
  • Create New...