PDA

View Full Version : [Question(s)] Precision Timer0 settings @ 48mhz on PIC18f26j50 to drive servoo



Addidis
09-11-2010, 10:40 AM
I have been trying to set up an interrupt based pwm signal to drive a servo. Im having allot of trouble on the calculations to set up the timer0 delay time to 18ms. Im using an 18f26j50, running 12 mhz crystal, system clock is at 48mhz.

Here is what I am figuring out :
instruction cycle time = .083 uS (via mplab stop watch)


I think with timer0 on with no prescaler , in 8 bit mode,
18ms = 217 count on Timer0

Would some one be so kind to show me the maths , and show me how to set up the timer.

Ive been using http://www.pyroelectro.com/tutorials/servo_motor/software.html
so Ive got :

Clock frequency = 48mhz = 48,000,000 hz
Ive looked threw the data sheet and didnt find this, but assumed its also 1 instruction per 4 clock cycles.
Instruction frequency = 40/4mhz = 12mhz = 12000000 hz

This is as far as im getting with out knowing im messing something up. Any help is appreciated.

Addidis
09-11-2010, 06:46 PM
I figured it out , incase any one wants to make a servo dance on similar hardware.



for(count=0;count<250;count++)
{
rFID_on();
Delay1KTCYx(12); //delay 1ms
Delay10TCYx(4);
rFID_Off(); //cw
Delay10KTCYx(22);
Delay1KTCYx(8); //delay 19ms
Delay100TCYx(9);
Delay10TCYx(1);
}

for(count=0;count<250;count++)
{
rFID_on();
Delay1KTCYx(18); //delay 1.5ms
Delay10TCYx(1);
rFID_Off(); //center?
Delay10KTCYx(22);
Delay100TCYx(28); //delay 18.5ms
Delay10TCYx(9);
}

for(count=0;count<250;count++)
{
rFID_on();
Delay1KTCYx(24); //delay 2ms
Delay10TCYx(9);
rFID_Off(); //ccw?
Delay10KTCYx(21);
Delay1KTCYx(6); //delay 18ms
Delay100TCYx(8);
Delay10TCYx(6);
}

Addidis
09-11-2010, 11:27 PM
YouTube - RFID prototype V2