View previous topic :: View next topic |
Author |
Message |
Harry Mueller
Joined: 17 Oct 2005 Posts: 116
|
No luck with centering servo using interrupts |
Posted: Sat Oct 22, 2005 11:50 am |
|
|
This newbie is trying to control (center) a servo using an interrupt on Timer_0 overflow. The code is compiling but nothing is happening at PIN_A0 and I'm a little over my head here so I'd appreciate some help. Here's the code: Code: |
#include <16F628.h>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#define quar_mov 250
#int_TIMER0 // This function is called every time
void servo_isr() // the RTCC (timer0) overflows (255->0).
{
int position; // For this program this shld be :) 50 times
int quarter = 2; // per second.
position = quarter*quar_mov;
output_high(PIN_A0);
delay_ms(1);
delay_us(position);
output_low(PIN_A0);
}
void main()
{
set_timer0(0);
setup_timer_0( RTCC_INTERNAL | RTCC_DIV_64 );
enable_interrupts(INT_TIMER0);
while(1);
}
|
Thanks.....Harry
Last edited by Harry Mueller on Sat Oct 22, 2005 7:05 pm; edited 2 times in total |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Sat Oct 22, 2005 12:03 pm |
|
|
Harry,
If you look at the data sheet you will find the pin is also used for a comparator input. To get Pin A0 to work try disabling the comparators.
Code: |
setup_comparator(NC_NC_NC_NC);
|
|
|
|
Harry Mueller
Joined: 17 Oct 2005 Posts: 116
|
|
Posted: Sat Oct 22, 2005 1:13 pm |
|
|
dyeatman wrote: | Harry,
To get Pin A0 to work try disabling the comparators.
|
Tried that but it didn't seem to help.
Thanks....Harry |
|
|
Guest
|
|
Posted: Sat Oct 22, 2005 1:40 pm |
|
|
Harry,
It works fine for me. |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Sat Oct 22, 2005 1:44 pm |
|
|
Sorry,
That last post was mine.
I had to enable global interrupts to get the timer interrupt to work and it worked just fine for me. Make sure your oscillator is running.
Code: | setup_comparator(NC_NC_NC_NC);
set_timer0(100);
setup_timer_0( RTCC_INTERNAL | RTCC_DIV_256 );
enable_interrupts(INT_TIMER0);
enable_interrupts(GLOBAL);
|
Adding the lines below allows you to see if the oscillator is running.
Code: | while(1)
{
output_toggle(PIN_B1);
delay_ms(100);
}; |
|
|
|
Harry Mueller
Joined: 17 Oct 2005 Posts: 116
|
|
Posted: Sat Oct 22, 2005 2:02 pm |
|
|
Great...it worked! Thanks!
I noticed some thing odd but it just turned out to be a timing issue.
Harry |
|
|
|