2014-07-17 12:41 PM
Hi,
I have programmed stm3220G-sk to read two ADC values from two different adcs ADC 1 & 2.When I connect DC power supply to check the readings, it can read values from 1 v to 3.3 v but cannot read values below 1 v, keeps reading nonsense for zero for example. when I reset the board it will read everything perfectly from 0 to 3.3v but only for once, for example if I reduce voltage from 3 to 0.5 it again cannot read 0.5 volt.Does anybody have an idea what is going on?Thank you #adc #stm322014-07-18 06:51 AM
Try to break your problem into smaller sub-problems, and then test each one separately to see where the problem lies.
You have code that, as you say, reads the ADC.But you must have other code as well. Code that processes the result into a voltage, and code that outputs it in such a way that you can understand it - for example on an LCD screen or to a serial port.To test the reading-the-ADC code, you could (for example) compare the raw ADC reading with a preset threshold value, and light an LED if the ADC value is above that threshold.Run the code, find out what voltage is just when the LED lights; try again with a different threshold. See if the relationship between actual voltage and programmed threshold makes sense.To test the subsequent code, you could replace the ADC-reading code with successive values e.g. counting down from full-scale. Add a delay so you can see the progress, then see if things make sense all the way down to zero or if the output goes funny at some level.My suspicion is that you might be converting a floating-point value to a string using e.g. printf(''%g'', voltage) without realising that %g changes from decimal to scientific notation as the numbers get smaller. And the scientific notation results in a much longer string that you might not have allowed for, either in the memory that you allocate to it, or how you analyse the string for display.Hope this helps,Danish