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 CCS Technical Support

Generating 50Hz by calling Timer0 Interrupt

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



Joined: 15 Feb 2012
Posts: 39
Location: italia

View user's profile Send private message AIM Address MSN Messenger ICQ Number

Generating 50Hz by calling Timer0 Interrupt
PostPosted: Tue Jun 19, 2012 5:42 pm     Reply with quote

Hello Everybody!
I want to generate a 50hz signal using timer0, and I want to vary the duty cycle of the signal from 1ms to 2ms(servo control). I didn't test it, so I want to take in consideration all of your opinions because really I didn't understand timer0 so much, this is the code:
Code:

#include <16F877a.h>
//#device adc=10
#Fuses HS,NOPROTECT,NOWDT,NOLVP
#use delay(clock=20000000)
int32 x=0;

#int_timer0
void timer0_isr()
{
x=x+1;
if(x>2500)
 {
  output_low(pin_b6);
 }
  if(x<2500)
 {
  output_high(pin_b6);
 }
if(x==50000) //each 50000 counts equal 20ms
{
x=0;//reset count each 20ms
}

void main()
{
set_tris_b(0x00);
setup_timer_0(rtcc_internal | rtcc_div_2);
set_timer0(255);//         interrupt will called each 0.4us
enable_interrupts(global);
enable_interrupts(int_timer0);
while(1)
{
}
}

Thax 4 reading !!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jun 19, 2012 6:03 pm     Reply with quote

50 Hz software PWM using Timer0:
http://www.ccsinfo.com/forum/viewtopic.php?t=37807&start=3

Servo examples using the CCP module in Compare mode:
http://www.ccsinfo.com/forum/viewtopic.php?t=34560&start=22
http://www.ccsinfo.com/forum/viewtopic.php?t=44328
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Wed Jun 20, 2012 3:02 pm     Reply with quote

Quote:
I want to generate a 50hz signal using timer0, and I want to vary the duty cycle of the signal from 1ms to 2ms(servo control). I didn't test it, so I want to take in consideration all of your opinions because really I didn't understand timer0 so much, this is the code:

You don't tell us how many steps you want from 1ms to 2ms.

Mike
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