ADC_SAR_seq

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Kinrin
Level 2
Level 2
10 replies posted 25 sign-ins 5 replies posted

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?simulation.jpg

many thanks!

0 Likes
1 Solution
ncbs
Moderator
Moderator
Moderator
500 replies posted 50 likes received 250 sign-ins

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

View solution in original post

0 Likes
4 Replies
ncbs
Moderator
Moderator
Moderator
500 replies posted 50 likes received 250 sign-ins

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

0 Likes
Kinrin
Level 2
Level 2
10 replies posted 25 sign-ins 5 replies posted

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. 

0 Likes
ncbs
Moderator
Moderator
Moderator
500 replies posted 50 likes received 250 sign-ins

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

0 Likes
Kinrin
Level 2
Level 2
10 replies posted 25 sign-ins 5 replies posted

Hi ncbs,

thanks for your guiding, I will try with that.

0 Likes