- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi all cypress friends,
I got a trouble when I tried to use ADC to measure battery voltage. I divided the battery voltage with two resistors, and then connect two pins of resistor to ADC_SAR_Seq to measure the voltage. but when I simulate the code, I can't read out the ADC value of this resistor. and I captured the watch value for the ADC, unfortunately, it shows optimized out. I don't know what's the problem.
Can anyone help to figure out the reason?
many thanks!
Solved! Go to Solution.
- Labels:
-
PSoC 4 MCU
- Tags:
- CY8C4125LQI-S423
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @Kinrin ,
The snap indicates that the variable has been optimized out. Can you add the 'volatile' qualifier to the variable? This should prevent the optimization issue.
Regards,
Nikhil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @Kinrin ,
The snap indicates that the variable has been optimized out. Can you add the 'volatile' qualifier to the variable? This should prevent the optimization issue.
Regards,
Nikhil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi ncbs,
Thanks for your reply!
I tried the method that you suggested, and it works. now I can see the value of adc when debugging. but the value is always 0x0000. I feel no surprise, because I can't even go to adc readout sentence when debugging. but when I check the adc value in other functions, the programming works normally. I don't know why it happens, but it seems the problem has been solved.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @Kinrin,
You should be able to read the value of ADC output even in debug mode. After you start the conversion process and wait for the conversion to end, you should positively see the result when you invoke the <ADC>_GetResult16() API.
I would suggest you to go through CE95276. This would help you to understand the flow of code to read the ADC output.
Regards,
Nikhil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi ncbs,
thanks for your guiding, I will try with that.