[PIC] interrupt routine calculates variable time

Status
Not open for further replies.

JAI PRAKASH LAMBA

Newbie level 5
Joined
Nov 12, 2013
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
81
Hi All,

I am new to pic,m designing a project using pic16f676 (4Mhz),the controller unit drives the relay which furthur drives a Water purifier motor.
i have to save the total runtime of the motor when it turn ON using timer1(16 bit), I have set a flag from my main code which is available to isr, on which it starts calculting motor run time & when motor is off i just clear the flag from main and clearing the isr variable.

I am facing two main problems that are:-

1) when motor elapse 1 hr i turn ON 1 led, after 2 hrs 2nd led and so on for three leds but led turns after 1 hr 2 min & for second led it will turn ON after 2 Hrs 1min 35 sec so on, means every time i Turn on my device it will turn on led's at variable interval of time.

2) some time my led state will not changes it gets struck in only one mode.

Attach my main code and isr routine

waiting for quick reply........

Thanks in advance
 

Attachments

  • interrupt routine.txt
    5.9 KB · Views: 151
  • main.txt
    15 KB · Views: 99

When compiler optimizations are enabled, the main code may cache a variable in a CPU register, instead of reading it from memory each time it is referenced. If an ISR changes the real memory value in the meantime, the main code won't immediately know and can continue operating with an outdated or incorrect value from the cache. This can lead to all sorts of weird, often random behavior; even if your code is otherwise bug-free.

You must tell the compiler explicitly which global variables should not be cached because they may be changed unexpectedly, for example by an ISR, by adding volatile to the variable declarations. Try that first and see if that helps.
 

still i am facing same problem still i am getting a variable time to turn on led's on the basis of motor ON/OFF run time. Nedded quick reply if possible
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…