Hello all. I am very confused about how to use the ADC for a new board that I am putting together.
Whenever I use an ADC on a new design, I always ensure that my code is reading it properly, so I just setup the internal channels VrefH and VrefL channels to be read to verify that the 0x000 and 0x3FF (or thereabouts) are being read back consistently, and then I would change my code to switch between the various channels as necessary and go full-speed for my oversampling algorithms.
The problem I am having is that even though my voltage is steady (using a 5V switching supply for this part), my ADC inputs are all over the map, as low as 0x357 and upwards of 0x3FD. I have done something similar before with little jitter of perhaps 3-4 counts in a noisy environment.
Please let me know if there are any thoughts on this, as it is driving me nuts!
I have attached my code below.
void main(void)
{
word wADC_Input;
APCTL1 = 0x04; //ADC2 is used as an ADC input.
ADCCFG = 0b00001000; //Clock Divide = Input Clock / 2, long sample time, 10-bit mode, input clock = bus-clock / 2.
ADCSC1 = 0x1D;
for(; //Infinite loop.
{
__RESET_WATCHDOG(); /* feeds the dog */
if(ADCSC1 & 0x80)
{ //Is conversion complete?
wADC_Input = ADCR;
//Setup a read for the next ADC Channel.
ADCSC1 = 0x1D;
}
}
}
已解决! 转到解答。
Thanks Mac, I have everything figured out. It was actually because the filter caps I was using were installed backwards. I was using tantalum caps and had installed them backwards at Vdd and Vss. This has never happened before, but once I misread a pin and referenced VrefH as Vss and VrefL as Vdd. I guess even the internal temperature bounces when there is a lot of noise.
Yes, I am using the POR default setup for the ICS module, and am using both the RM and the Datasheet. They are providing somewhat conflicting data at times, and I always appreciate an example to settle all disputes. I tried out the example for the JM16 and it appears to be working quite nicely now at 8MHz clock.
Thanks for all of your help. I just wish that I had thought about this earlier than today.
Hello,
I would suggest that your use of a high frequency switching regulator to directly power the MCU would be unsuitable where 10-bit ADC readings are of major importance for the application. This type of rregulator will generate high frequency noise at its output, and it is difficult to isolate sensitive analog circuits from this noise. Try a 5 volt linear regulator, and see whether the problem still exists.
Regards,
Mac
Thanks. I changed this now to a 12V switching power supply, and am using a 7805 linear regulator and am having all of the same problems. I don't have a 12V wall transformer anymore, otherwise I would be able to try this as well.
Once again though, the voltage is a rock-solid 4.91V now, and I am still having the same issue.
Would adding additional filter caps provide any sort of help? I have a 10uF tantalum and a 0.1uF ceramic as recommended. Should I double those up, or add a 1.0uF for an in-between noise shunt?
Hello,
Contrary to what you have said in your code comment, I notice that you are using short sample time and the clock source is the bus clock (rather than bus clock / 2). What is the bus frequency - does this exceed 8 MHz. I assume that the maximum allowable ADC clock is 8 MHz.
Are you actually saying that you are observing the fluctuations on the 0x1D channel (Vrefh), or on the 0x02 channel for the input that you are using? If it is the latter, how have you setup the test voltage level, and what is its value?
You should have a separate ground trace for the analog input, that would be joined to Vss at a single point only, very close to the Vss pin. Do you have any CR noise filter prior to the analog pin? The filter should use the analog ground.
See what short term fluctuation you get with the internal temperature sensor (channel 0x1A). This should not be subject to externally generated noise, but there may be a small fluctuation due to internal noise. One approach to reducing the internal noise is to enter wait mode immediately after commencing a conversion, and use the ADC conversion complete as a wakeup event. This would require use of the asynchronous clock source.
Regards,
Mac
Thanks BigMac. I noticed that you were correct in your comments, I had originally planned on using the code as listed in the original comment, but because things didn't work out, then I changed the bits, but not the comments. One of the problems with comments I guess.
I have changed the code to the following as you suggested (/ 2 still happeend, so I switched to / 4 and / 8), and it is still bouncing around, even with the 0x1A.
ADCCFG = 0b01111001; //Clock Divide = Input Clock / 8, long sample time, 10-bit mode, input clock = bus-clock / 2.
ADCSC1 = 0x1A;
After my reading, I changed the ADSC1 = 0x1D to the 0x1A, so that should not be a place of error in the code.
Honestly, I don't know what my clock speed is, as the datasheet leaves a lot to be desired with this manual. I set this up on a Friday night and I don't have a scope at home. I'll check this on Monday when I get to the office.
I suppose one of the next easy things to do would be to put a different processor on, as I ordered 5 samples and have them all ready to go.
I'll post back later after putting a new chip down to see if the problem follows the board, or is with the chip.
Thanks!
Hello,
I presume that you are using the POR default setup for the ISC module, with operation in FIE mode. The normally allowed internal reference frequency range is 31.25 to 39.0625 kHz. This gives ICSout frequency 32 to 40 MHz. If the reference is untrimmed, the frequency range may be somewhat wider. With POR default setting for BDIV, the normal bus frequency range will be 8.0 to 10.0 MHz. If the trim value held within upper flash has been calibrated for 32.768 kHz, and the trim value is transferred to the trim control register, the bus frequency should be close to 8.39 MHz
I trust that you are referring to both the datasheet and the reference manual for the device.
When measuring the internal temperature sensor voltage, if significant reading fluctuations occur, the cause will be either internal CPU noise, or that Vref is noisy. For this devoce VrefH is internally connected to Vdd, and VrefL to Vss, so that any noise fluctuations present of (Vdd - Vss) will directly affect the reading during the conversion process. By contrast, any noise at an analog input will affect the sampling process, but not the conversion process.
Regards,
Mac
Thanks Mac, I have everything figured out. It was actually because the filter caps I was using were installed backwards. I was using tantalum caps and had installed them backwards at Vdd and Vss. This has never happened before, but once I misread a pin and referenced VrefH as Vss and VrefL as Vdd. I guess even the internal temperature bounces when there is a lot of noise.
Yes, I am using the POR default setup for the ICS module, and am using both the RM and the Datasheet. They are providing somewhat conflicting data at times, and I always appreciate an example to settle all disputes. I tried out the example for the JM16 and it appears to be working quite nicely now at 8MHz clock.
Thanks for all of your help. I just wish that I had thought about this earlier than today.