Thanx for the rply. I am running PWM on Timer 0 interrupt. But when PWM starts flicker for LOAD on/off increses. What must be the reason.
when PWM starts flicker for LOAD on/off increses??
LOAD is nothing but array of LED's which are getting ON/OFF on Interrupt.
I am running PWM on Timer 0 interrupt. But when PWM starts flicker for LOAD on/off increses. What must be the reason
I am varying PWM duty cycle using timer0.
#define ON 1
#define OFF 0
#define timer_val 0
#define BATTERY_CHARGE PORTC.B5
#define LOAD PORTC.B4
unsigned int i = 0,Battery_Value = 0;
void interrupt(){
if(INTCON.T0IF){
T0IF_bit = 0;
TMR0 = 0;
}
//i++;
LOAD = ON;
}
void main() {
TRISA = 0xff; //port A as input
TRISC = 0x00; //port C as output
PORTC = 0X00; //INITIAL VALUE ON PORTC
ADCON0 = 0b00000000; //Left Justified
ADCON1 = 0b00110000; //Clock derived from internal RC oscilator
ANSEL = 0b00000011; //channel AN0 and AN1 as analog input
INTCON = 0b10100000;
INTCON.T0IF = 0;
//CMCON0 = 0x07; //Disable the comparators
T0CS_bit = 0;
PSA_bit = 0; //Prescaler is assigned to Timer0 module
PS0_bit = 0; //TMR0 rate 1:1
PS1_bit = 0;
PS2_bit = 0;
while(1){
Battery_Value = ADC_Read(1);
Battery_value = (Battery_Value/4);
if(TMR0>=Battery_Value){
LOAD = OFF;
}
}
}
This is a code
Code:#define ON 1 #define OFF 0 #define timer_val 0 #define BATTERY_CHARGE PORTC.B5 #define LOAD PORTC.B4 unsigned int i = 0,Battery_Value = 0; void interrupt(){ if(INTCON.T0IF){ T0IF_bit = 0; TMR0 = 0; } //i++; LOAD = ON; } void main() { TRISA = 0xff; //port A as input TRISC = 0x00; //port C as output PORTC = 0X00; //INITIAL VALUE ON PORTC ADCON0 = 0b00000000; //Left Justified ADCON1 = 0b00110000; //Clock derived from internal RC oscilator ANSEL = 0b00000011; //channel AN0 and AN1 as analog input INTCON = 0b10100000; INTCON.T0IF = 0; //CMCON0 = 0x07; //Disable the comparators T0CS_bit = 0; PSA_bit = 0; //Prescaler is assigned to Timer0 module PS0_bit = 0; //TMR0 rate 1:1 PS1_bit = 0; PS2_bit = 0; while(1){ Battery_Value = ADC_Read(1); Battery_value = (Battery_Value/4); if(TMR0>=Battery_Value){ LOAD = OFF; } } }
I am using Internal clock frequency of 4 Mhz.
Interrupt is for timer 0. When count in 8 bit timer0 reaches from 255 to 0 interrupt occurs. In interrupt load gets on. Now in main i m checking if timer value reaches to particular intensity level by checking timer0 count. It it reaches then LOAD is OFF. Using this technique we can change intensity of LED or load. There is no hardware PWM in 16f676 so i have to do it through software. So there is no PWM interrupt as such. I am varying PWM duty cycle using timer0.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?