jude57
Newbie level 4
- Joined
- Mar 18, 2010
- Messages
- 6
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Location
- newzealand
- Activity points
- 1,344
hi,im trying to do a simple software pwm with pic16f877 on pin RC2,im using timer0 to create a count then using that to control the pins on /off position(u guys must have seen hips of this),the problem is i cnt use the timer to get my variable period to count down(period--),as im using it to use with my ISR.
i am on XT and the rest of the configuration bit disabled.
pls guys cn u point me to the right direction,what did i do wrong???. oh the xt is 20mhz.
#include<pic.h>
unsigned char period = 32;
unsigned char duty_cycle = 16;
//#define PWM_SWITCH RC5;
void init_INT(void)
{
TMR0 = 132; // Interupt every 0.1 ms
T0IE = 1; // Enable interrupt on TMR0 overflow
GIE = 1; // Global interrupt enable
PSA = 0;
PS2 = 1;
PS1 = 1;
PS0 = 1;
}
void interrupt Timer0_ISR(void)
{
if(T0IF){
period--; // TMR0 interrupts flag reset
if ((period > duty_cycle) || (period = duty_cycle))
{
RC2= 0;
}
else
{
if (period > 0)
{
RC2 = 0;
}
else
{
RC2 = 1;
period = 32;
}
}
T0IF = 0;
TMR0 = 132;
}
}
void main(void)
{
TRISC = 0x00;
PORTC = 0x00;
init_INT();
}
i am on XT and the rest of the configuration bit disabled.
pls guys cn u point me to the right direction,what did i do wrong???. oh the xt is 20mhz.
#include<pic.h>
unsigned char period = 32;
unsigned char duty_cycle = 16;
//#define PWM_SWITCH RC5;
void init_INT(void)
{
TMR0 = 132; // Interupt every 0.1 ms
T0IE = 1; // Enable interrupt on TMR0 overflow
GIE = 1; // Global interrupt enable
PSA = 0;
PS2 = 1;
PS1 = 1;
PS0 = 1;
}
void interrupt Timer0_ISR(void)
{
if(T0IF){
period--; // TMR0 interrupts flag reset
if ((period > duty_cycle) || (period = duty_cycle))
{
RC2= 0;
}
else
{
if (period > 0)
{
RC2 = 0;
}
else
{
RC2 = 1;
period = 32;
}
}
T0IF = 0;
TMR0 = 132;
}
}
void main(void)
{
TRISC = 0x00;
PORTC = 0x00;
init_INT();
}