Hi everybody,
I got stuck to keep my program running on real time.
The program suppose to turn off the O/P at 57th second, & back on the O/P at 60th second, however I noticed the 57th second kept shifting backwards! say after power up chip running for about 5 minutes or so the O/P no more off at 57th second, but off at 60+ seconds, and on at 3 seconds later, and…keep on shifting back! When compared to the real time clock. I could not figure out my mistake.
Is there any way to keep the cycle stays with the real time?
I’m using PIC12F615, interrupt timer0 overflow, program with mikroCpro version 6.0.0.
If the WDT can play apart to overcome this problem, how do I program? Please any advice?
Thanks!
The source code:
I got stuck to keep my program running on real time.
The program suppose to turn off the O/P at 57th second, & back on the O/P at 60th second, however I noticed the 57th second kept shifting backwards! say after power up chip running for about 5 minutes or so the O/P no more off at 57th second, but off at 60+ seconds, and on at 3 seconds later, and…keep on shifting back! When compared to the real time clock. I could not figure out my mistake.
Is there any way to keep the cycle stays with the real time?
I’m using PIC12F615, interrupt timer0 overflow, program with mikroCpro version 6.0.0.
If the WDT can play apart to overcome this problem, how do I program? Please any advice?
Thanks!
The source code:
Rich (BB code):
unsigned pwm, count;
void interrupt(){ //ISR
if(intcon.t0if ){ // interrupt timer0 flag overflow
intcon.t0if=0; // reset timer0 flag
count++; // increase counter by 1
tmr0=0; } //reset timer0
}
void init(){
count=0;
tmr0=0;
option_reg.t0cs=0; // use internal clock
option_reg.psa=0; //prescaler assigned to timer0
//Prescaler timer0 rate setting 1:256
option_reg.ps0=1;
option_reg.ps1=1;
option_reg.ps2=1;
intcon.t0ie=1; //enable timer0 interrupt
intcon.gie=1; //enable global interrupt
trisio=0; // all ports as output
pwm=25; // 10%
pwm1_init(10000); //initial pwm F=10khz
}
void main() {
init();
while(1){
while(count<1954){ //about 57sec
pwm1_start();
pwm1_set_duty(pwm);
} //ends while(<1954)
while(count<2054){ //about another 3sec
pwm1_stop();
gpio.f2=0;
}
//ends while(<2054)
count=0; // reset counter
}// ends while(1)
} //ends main()
Last edited by a moderator: