CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

No luck with centering servo using interrupts

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Harry Mueller



Joined: 17 Oct 2005
Posts: 116

View user's profile Send private message

No luck with centering servo using interrupts
PostPosted: Sat Oct 22, 2005 11:50 am     Reply with quote

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: 1924
Location: Norman, OK

View user's profile Send private message

PostPosted: Sat Oct 22, 2005 12:03 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Oct 22, 2005 1:13 pm     Reply with quote

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








PostPosted: Sat Oct 22, 2005 1:40 pm     Reply with quote

Harry,
It works fine for me.
dyeatman



Joined: 06 Sep 2003
Posts: 1924
Location: Norman, OK

View user's profile Send private message

PostPosted: Sat Oct 22, 2005 1:44 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Oct 22, 2005 2:02 pm     Reply with quote

Great...it worked! Thanks!

I noticed some thing odd but it just turned out to be a timing issue.

Harry
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group