View previous topic :: View next topic |
Author |
Message |
karimpain
Joined: 15 Feb 2012 Posts: 39 Location: italia
|
Generating 50Hz by calling Timer0 Interrupt |
Posted: Tue Jun 19, 2012 5:42 pm |
|
|
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
|
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Wed Jun 20, 2012 3:02 pm |
|
|
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 |
|
|
|