Buy an Axon, Axon II, or Axon Mote and build a great robot, while helping to support SoR.
0 Members and 1 Guest are viewing this topic.
#define PWM(port, pin, spd) { PORT_ON(port, pin); delay_cycles(spd); PORT_OFF(port, pin); delay_cycles(1600); }...int x=240, y=0, z=0;...if (x != 0) PWM(PORTD, 2, x);if (y != 0) PWM(PORTD, 3, y);if (z != 0) PWM(PORTD, 4, z);
Second, how fine of positioning can I get with servos?
And can I send a single pulse to get a servo to move into a position, or must I keep sending pulses until it's in position?
/************************************* Semi - PsuedoCode * I don't know all the nessecary code yet,* but I can figure it out if this idea might work.************************************/volatile int cnt;Timer_Interupt_Handler(...) { cnt++; }int main(void) { int sx=500, sy=400, sz=600; int bx=0, by=0, bz=0; cnt=0; Initialize_16bit_Timer(Trigger Fast); while(1) { Handle_Uart_IO(...); //Turn on when it is time. if ((cnt < sx) && (bx == 0)) { port_on(portd, 2); bx = 1; } if ((cnt < sy) && (by == 0)) { port_on(portd, 3); by = 1; } if ((cnt < sz) && (bz == 0)) { port_on(portd, 4); bz = 1; } //Turn off when it is time. if ((cnt > sx) && (bx == 1)) { port_off(portd, 2); bx = 0; } if ((cnt > sy) && (by == 1)) { port_off(portd, 3); by = 0; } if ((cnt > sy) && (by == 1)) { port_off(portd, 4); bz = 0; } //Reset Counter (when one cycle is done) if (cnt > 32000) cnt -= 32000; } return 0;}
I'm running an 8.6 batt pack (freshly charged).
QuoteI'm running an 8.6 batt pack (freshly charged).8.6V freshly charged?! You do realize most servos max out at around 6V, and your battery is probably around 9.5V fully charged
I've never run a servo at that voltage . . . but its a possibility that's causing your problem.
Also I noticed you have an interrupt running.
isn't timers the only way to get decent servo response?
void pwm_init(unsigned long freq){ timer2_init(freq); //initialize the timer to overflow at a given frequency // Initialize Output Compare Module OC1CONbits.OCM = 0b000; // Disable Output Compare Module OC1R = 0; // Write the duty cycle for the first PWM pulse OC1RS = 0; // Write the duty cycle for the second PWM pulse OC1CONbits.OCTSEL = 0; // Select Timer 2 as output compare time base OC1CONbits.OCM = 0b110; // Select the Output Compare mode}//Change the PWM duty cyclevoid pwm_dutycycle(unsigned int percent){ //PRx+1 is the period in cycles OC1RS=(PR2+1)/100*percent;}