Parallax Servos off MC9s12
I am trying to get my Servos running for my Boe bot, and I am doing something wrong... My directional LCD output refreshes fine, but when I go to pump out my pulse train to the servo, I get about a half a second of turning, then my board is cycling, and I get just a tiny pulse to the servo from reset, rinse and repeat. I have only hard coded one direction just to get it working.
Do I have my period and duty cycle wrong? What is causing my board to cycle?
Here is my code. Sorry if I left out some specifics, ask me and I will give it. My brain is fried right now
Do I have my period and duty cycle wrong? What is causing my board to cycle?
Here is my code. Sorry if I left out some specifics, ask me and I will give it. My brain is fried right now
void set24MHzClock(void); void init_PWM(void); void main(void) { unsigned char VT; while(1) { set24MHzClock(); LCD_init(); init_PWM(); VT = PORTB & 0x1F; if(VT & 0x10) { switch(VT) { case 0x17: writeLine("Right ", 0); break; case 0x1B: writeLine("Left ", 0); break; case 0x1E: writeLine("Forward ", 0); PWME = 0x03; PWMPER01 = 43400; PWMDTY01 = 3400; break; case 0x1D: writeLine("Reverse ", 0); break; default: writeLine("Invalid ", 0); break; } } else { writeLine("Stopped ", 0); } } } //PWM INIT// void init_PWM(void) { PWMPOL = 0x01; // High at beginning, low at end (active high). PWMPRCLK = 0x00; // Prescaler. PWMCLK = 0x00; // Sets clock A to be ch 1 clock. PWMCTL = 0x10; // Sets up ch0+1 16bit. PWME = 0xFF; } /*--------------------------------------------------------------------------- - set24MHzClock - - Sets up phase-locked-loop and clock source, etc., for 24 MHz operation ----------------------------------------------------------------------------*/ void set24MHzClock(void) { CLKSEL = 0; // Use crystal oscillator for E clock PLLCTL = 0; // PLL off SYNR = 2; // PLL X3 REFDV = 0; // ??? PLLCTL = 0x40; // PLL on while( !( CRGFLG & 8) ) { } // Wait for lock-up CLKSEL = 0x80; // Use PLL for system clock }
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering
·