09-09-2015 03:20 PM
Help!
I am reading different voltage at an interval of 500ms in a producer loop and passing it to the consumer loop. However, I notice that the values in the consumer loop dont change even when the voltage has changed?
What can I do?
Solved! Go to Solution.
09-09-2015 03:47 PM
Post your code.
09-09-2015 04:00 PM
The code is attached. Still WIP.
Thanks
09-09-2015 04:29 PM
You are probably stuck in the inner loops. Since the value of your capacitor voltage is fed in from outside the loop, only that value will be used inside the loop unitl the loop stops executing. So, if the first capacitor voltage is less than the Upper Threshold Voltage, then the inner loop in the Charging case will never end.
You do not need the inner loops at all. You want to test against the thresholds exactly once for each reading of the voltage. Wire the output of the comparison to a case structure. If the condition is met, Write to the output channel and change the state. Otherwise, do not write and return to the same state on the next reading.
One other thing. When you stop the program you may want to set the output to discharging before shutting down so your capacitors do not sit there charged.
Lynn
09-09-2015 04:32 PM - edited 09-09-2015 04:33 PM
Your code will deadlock in your while loop if you are in the Charging state and receive a voltage less than the Upper Threshold voltage.
Your logic in the consumer needs some more thought.
Just use a case structure on the output of your voltage comparison to either pass through and remain in charging or to set your output and switch to discharging.
EDIT: Lynn beat me to it.
09-09-2015 06:12 PM
Thanks Lynn and Taki!
I was able to see clearly what I was doing all wrong and now, I can produce and consume appropriately! Thanks for your help.