Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[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
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: 135
  • main.txt
    15 KB · Views: 75

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
 

Nedded help i get struck in that problem if possible quick reply

thnx in advance
 

Still waiting for reply------anyone of delay in timer interrupt service routine
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top