![]() | ![]() | ![]() |
| | #31 |
|
I'll have to give this a try with the junebug Looks good Mike. futz It's good to see you been a long time haven't seen you glad to see your still with us.I just tried it with a cheapo parallax servo works great Thanks Mike. good work.
Last edited by be80be; 16th June 2009 at 01:39 AM. | |
| |
| | #32 | |
| Quote:
Mike. | ||
| |
| | #33 |
| | |
| |
| | #34 | |
|
That why I didn't see it till today Triode stated it back up Quote:
Last edited by be80be; 16th June 2009 at 03:54 AM. | ||
| |
| | #35 |
|
Well, like I said when I replied to it, I googled for exactly what this thread was about and ended up finding it here, where I already post, so why not bring it back. Thanks for clairifying that pommie, I had found the list of what each bit did in the variables, but I had never seen "bits" written in like that. | |
| |
| | #36 |
|
If anyone is having problems with the interrupt driven version it is because I used the wrong interrupt vector. The line, Code: #pragma code low_vector=0x18 //setup the ISR vector Code: #pragma code low_vector=0x08 //setup the ISR vector I noticed this as I needed the code to align a servo that had stripped its gears. Mike. Last edited by Pommie; 10th October 2009 at 03:46 AM. | |
| |
| | #37 | |
| Quote:
thanks for putting this code up. my application basically uses a PIC18 with a 10Mhx crystal connected to it. Will i have to make any modifications to this code, especially with regards to the delays?or is it the same regardless of the clock speed? | ||
| |
| | #38 |
|
With a 10MHz clock a 1mS pulse will be 1250 cycles. So multiply all time by 1.25 to get the new times. The line ServoPos=ADRES+1000; will need to be ServoPos=ADRES*5/4+1250; Note also the interrupt vector is wrong. See the post above yours. Mike. | |
| |
| | #39 |
|
how did you do the maths for it?im a bit confused :S no mike, ur interrupt vector is correct..low priority interrupts are a 0x0018 and high priority is at 0x0008... | |
| |
| | #40 |
|
The maths is simple, at 8MHz the timer would be clocked at 2MHz if the prescaler wasn't used. I set the prescaler to 2 and so the timer is clocked once every microsecond. With a 10MHz clock it is 10/8 (=1.25) times faster. The interrupt vector would be correct if I used interrupt priorities but I chose to use compatibility mode and so all interrupts go to the vector at 0x08. Mike. | |
| |
| | #41 |
| Code: #include <p18f452.h>
#define ServoPin PORTAbits.RA2
int ServoPosition;
void CCP2_ISR();
#pragma code high_pri_vec = 0x0008
void high_pri_vec()
{
_asm
GOTO CCP2_ISR
_endasm
}
#pragma interrupt CCP2_ISR
void CCP2_ISR()
{
if(ServoPin==1)
{
ServoPin = 0;
CCPR2 = 25000 - ServoPosition;
}
else
{
ServoPin = 1;
CCPR2 = ServoPosition;
}
PIR2bits.CCP2IF = 0;
}
#pragma code
void main()
{
ServoPin = 0;
TRISAbits.TRISA2 = 0; //Set Pin A2 as an output for the Servo
CCP2CON = 0b00001011; //Setup CCP2 to generate special event
CCPR2 = ServoPosition;
T3CON = 0b10011001; //Setup timer3, prescaler=2
ServoPosition = 1875; //Mid point position for Servo
TMR3H = 0;
TMR3L = 0;
PIE2bits.CCP2IE = 1; //Enable CCP2 interrupt
INTCONbits.PEIE = 1; //Enable peripheral interrupts
INTCONbits.GIE = 1; //Enable all interrupts
while(1);
}
ok.so it seems like timer3 isnt accessing the high byte and counting up only to 256. what am i doing wrong? Last edited by yohanevindra; 25th October 2009 at 07:50 AM. | |
| |
| | #42 |
|
You are still using Timer1 for the CCP module. Try T3CON = 0b11011001; Mike. | |
| |
| | #43 |
|
i changed tht...its still the same..now it seems to be giving me random values... any other registers i need to configure? | |
| |
| | #44 |
|
You need to make A2 digital with ADCON1=0x07; Analogue pins always read back as zero. Mike. | |
| |
| | #45 |
|
same problem...for some reason the timer is not counting into the high byte, so hence its maximum value is only 256. im looking at the timer through the watch window, and it doesnt seem to go upto the value specified in the CCPR register, but then when i looked at the simulator logic analyser, and measured the pulses, it seems like its working. to measure the frequency of pulses in the logic analyser, do i just need to line the cursor with the respective point and then multiply the no of cycles by (Fosc/4)? Last edited by yohanevindra; 25th October 2009 at 10:23 AM. Reason: Seems like it works now | |
| |
|
| Tags |
| c18, code, junebug, servo |
| Thread Tools | |
| Display Modes | |
| |
Similar | ||||
| Title | Starter | Forum | Replies | Latest |
| MP Lab Program Help | bamafan54 | Micro Controllers | 5 | 7th January 2009 03:16 PM |
| servo motor program code | basf_12 | Electronic Projects Design/Ideas/Reviews | 8 | 31st October 2006 03:57 AM |
| Tough assembly program for the PIC16F84 | asmpic | Micro Controllers | 34 | 3rd December 2004 07:50 PM |
| how to understand this code!!! | indie | Electronic Projects Design/Ideas/Reviews | 3 | 11th September 2004 08:39 PM |
| An error in pic16f84a, why? | Zener_Diode | Micro Controllers | 6 | 11th April 2004 03:55 AM |