Shop OBEX P1 Docs P2 Docs Learn Events
Parallax Servos off MC9s12 — Parallax Forums

Parallax Servos off MC9s12

w8f8w8f8 Posts: 5
edited 2010-04-19 20:41 in Robotics
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 roll.gif

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 SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2010-04-19 20:41
    Sounds like low batteries. Have you tried a fresh set? With the LCD and Servo drawing current even moderately low batteries can cause a brownout when the servio moves.· OTOH, I am not familiar with your micro, so it could be something entirely different.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage

    Parallax Engineering
    ·
Sign In or Register to comment.