3 Replies Latest reply on Dec 17, 2018 11:07 AM by KyTr_1955226

    Variables lose value over time

      I found an interesting issue in PSOC5 (059 kit) and I'd like to share it.


      So I was using a variable array for the gain of my ADC channels (8 places). I was confused about the code and did not define them as "const" just normal "double".


      What happened was that after 10-12 hours of continuous running, the ADC result started giving garbage values. After much troubleshooting, I realized that the Gain[ADC_Channel] value had changed for some reason. When I used a "# define" macro to assign the gains, everything ran beautifully.


      For now I have used 8 different Gain macros and coded the lines manually. However this is tedious and prone to errors.


      Any ideas on what is wrong and how to fix it? Will "CYCODE" help here.


      I speculate that the variable value is being loaded on to some registers while programming and maybe the register cells are only powered during a write operation. So since there is no write operation for hours together, the registers lose the value over time.


      Hope this helps someone else as well.

        • 1. Re: Variables lose value over time



          Could you please keep a breakpoint on write on those variables and see if you could see the point at which it is getting updated ?


          Best Regards,

          • 2. Re: Variables lose value over time

            By "Breakpoint" do you mean an "if" code of some type or is it a feature in PSOC Creator?


            Sorry for my lack of knowledge.

            • 3. Re: Variables lose value over time

              A breakpoint uses the attached debugger/programmer to halt the executing code either on a specified line (Line Breakpoint) or when a variable is written or read (Data Breakpoint).  There are also address breakpoints and Function breakpoints (to break at specified addresses in code or upon entry to functions respectively).


              This can be very helpful for tracking down something in code that's misbehaving.


              For line breakpoints, simply right click the line you want to break on in your code and choose "Insert Breakpoint".  The line will be marked with a red circle.  When debugging the code will halt on that line and you can look at the state of your variables and registers at that point.


              For a data breakpoint, in creator, go to Debug>New Breakpoint>Variable Watchpoint.

              You can then type in which variable you want to break on, and if you want to break when it's read/written/accessed.

              1 of 1 people found this helpful