Hi All.
This post continues the chapters of using the 12 bit ADC on JM16 series here and later here.
Mac, I have been reading again your tips, after using the voltage reference the measurements goes better, but still have fluctuations, small... but around +-8 values in the range of 4096 samples of the 12bit conversion.
Vref is totally stable near the micro. (+-1 mv)
Vsignal the same.
Vdd is tied to VddADC but Im not sure if those small fluctuations in the ADC Power are the responsible.
So before change my mind using an external ADC, I would ask you about how putting the ADC in sleep mode for reduce noise... Any ideas?
I´ve been reading that stop3 mode is the best option, but it seems it needs external ADCLK???
If you dont mind I will post some code I use for using the conversor.
void ADCInit(void) { APCTL1_ADPC0 = 1; // YOUT APCTL1_ADPC1 = 1; // ZOUT APCTL1_ADPC2 = 1; // POT APCTL2_ADPC8 = 1; // XOUT ADCSC2 = 0x00; // Disable HW trigger and autocompare ADCCFG_ADIV = 3; ADCCFG_MODE = 1; // 1=12 bit. ADCCFG_ADICLK = 3; ADCCFG_ADLSMP = 1; // 1 = long sample time /* ADCSC1: COCO=0,AIEN=0,ADCO=0,ADCH4=1,ADCH3=1,ADCH2=1,ADCH1=1,ADCH0=1 */ ADCSC1= 0x1F;}
The function that enables the conversion is:
byte AD1_Measure(byte WaitForResult){ if (ModeFlg != STOP) { /* Is the device in different mode than "stop"? */ return ERR_BUSY; /* If yes then error */ } ModeFlg = MEASURE; /* Set state of device to the measure mode */ AD1_HWEnDi(); /* Enable the device */ if (WaitForResult) { /* Is WaitForResult TRUE? */ while (ModeFlg == MEASURE) {} /* If yes then wait for end of measurement */ } return ERR_OK; /* OK */}
AD1_HWEnDi(); writes ADCSC1 register with ADCSC1= 0x42; -> irq enable and ch2 enable
When I want to get a conversion I Call:
AD1_Measure(1)
I take 50 values and divide, but there is some small strange fluctuation
Can you help me about using the stop3 mode with some code example or anything for reducing noise in the moment of the conversion? That is my last chance! :s
Regards.
Cristian.
Solved! Go to Solution.
Demo JM16 comes with 48 pin package (QFN).
The daughter card has 64 pins, DEMOJM16 documentation speaks about pin 45 is VrefH.
But, 48 pin package dont has VrefH in that pin, cause it´s tied to VDDAD... ¬¬
Could be nice to include in the documentation of the JMDemo some advice like, hey! VrefH is not there! is in the VDDAD pin.
I know that the DS is where to see all the information, but the schematics of the DEMOJM are so pretty that I have followed the pins through that schematic. It´s not a bug... but could be nice some advertisement for people like me who trust in the schematics of P&E
If someone has the DEMOJM16... watch out with the ADC converter and the pinout!!
So it´s clear now... I´m going to connect the voltage reference to the VDDAD, but not without being warned by you. I have looked into the electrical characteristics, and it seems that the ADC consumes MicroA, the voltage reference can give until 10mA... Is it usual to connect it there?
I´ve been advertised with the common mode in this case...
Regards.
Cristian.
Well about the clock source, it seems not need to be external, as the DS says:
"The asynchronous clock (ADACK). This clock is generated from a clock source within the ADC
module. When selected as the clock source, this clock remains active while the MCU is in wait or
stop3 mode and allows conversions in these modes for lower noise operation."
So! "for lower noise operation I need to use that clock! cause it keeps running in WAIT or STOP3 mode.
So! ¿How is the proper way to enter in that modes when using the ADC?
I will keep investigating on the DS, help in this point much appreciated.
Regards.
Cristian.
Hello Cristian,
Yes, the use of wait mode should be sufficient for this purpose. From within the main loop you would start the A/D conversion using the asynchronous clock, and then immediately enter wait mode with __asm wait;
The wakeup source would be the conversion complete interrupt, which might simply write the result of the conversion to a global variable, so as to clear the COCO flag. When the ISR exits, operation would then continue in the main loop, immediately following the wait instruction.
You would need to ensure that no other interrupt, such as a timer interrupt, could cause premature wakeup.
Regards,
Mac
After writing to the ADCSC1 register I use:
__asm wait;
Supposing that the micro stays in wait mode and the IRQ will wake up the cpu, that ´s what I do.
The noise is going better ( or maybe is a dream) but still not sufficient, it seems that the micro generates noise.
So, I´m investigating the stop3 mode, that it´s supposed to be more "sleepy" than the wait mode... The problem, is that I don´t understand how to wake up from that mode... well, it seems to wake up yes, but the code hangs up... My code:
ADCSC1= 0x42; //A write to the ADCSC1 starts the conversion.
SPMSC1_LVDE = 1;
SPMSC1_LVDSE = 1;
//SOPT1_STOPE = 1; //seems not to work
__asm stop;
Not working for me, it´s suppose to be stop3 mode, I get lost in the DS and trying to figure how the wake up procedure is.
¿Better to use an external ADC?
I only want to see if the noise with stop3 mode persists.
Please little help to a newbie.
Cheers.
Hello Cristian,
Betadine wrote:
So, I´m investigating the stop3 mode, that it´s supposed to be more "sleepy" than the wait mode... The problem, is that I don´t understand how to wake up from that mode... well, it seems to wake up yes, but the code hangs up... My code:
ADCSC1= 0x42; //A write to the ADCSC1 starts the conversion.
SPMSC1_LVDE = 1;
SPMSC1_LVDSE = 1;
//SOPT1_STOPE = 1; //seems not to work
__asm stop;
The ADC should be able to wakeup from stop3 mode. Many of the system registers are write once. This means that all bits must be simultaneously written, usually near the start of the program. For example, if the COPT bits of SOPT1 had already been written prior to the above code, then attempting to set the STOPE bit will not do so, and the stop instruction will not be enabled. I would also simultaneously initialise all bits of SPMSC1 near the start of the program.
With respect to the presence of noise, the power ground path and the analog ground path need to be kept separated, and joined only at a single point, in close proximity to the VssA and VrefL connections of the MCU. The external reference also needs to be returned directly to VrefL
How many 12-bit LSBs are the noise fluctuations? For precision measurements, it is not unusual to average the result of many readings, or to digitally filter the readings, to effectively reduce the noise fluctuations. But this will be determined by the transient response required by your application.
Regards,
Mac
Hi Mac,
Thank you for your comments
About the Wait mode, I use USB and UART so who knows if any interrupt there wakes up the micro. In theory, no transmission is done when making the conversion, RTC disabled, and seems not to exists any other timer.
I have tested to make an __asm wait , followed by a turning led off without using the conversion, and no interrupt wakes up the micro. I have then added the write to ADCSC1 just before the wait instruction, and then the led turns off. So it seems to works as expected.
The noise is a fluctuation around +/-6 samples -> 12 samples of variation. In 12 bit we have 4096 samples. So we are talking about 0.25% of error. I need 0.1% that means ZERO noise jeje. Texas Instruments sells data adquisition units that works good with this, but the cost is very very expensive.
What I´m starting to think is that 0.25% of error is something normal when this ADCs are integrated in the MCU.
GND of the analogic source goes directly to VrefL in which a Zero ohm resistor makes the union with GND (I tried also putting the GND to MCU GND and works the same)
Vrefh and signal Data are +/-0.5 mv variation more or less -> ZERO NOISE
GND of the voltage reference connects directly to VrefL of the MCU (connected at the same point where Analogic GND connects with VrefL of the MCU. There are only 1 point of connection between both GNDs.
I collect 50 samples and make the division for reducing noise... for a few! but not success
About the stop mode,
Yes it´s true, the register is written in the initialization, but then... if I have to take 50 samples how the demons I put the MCU in stop mode 50 times! cause that means 50 IRQs. If once the MCU is in stop mode at the beggining, after wake up, how is possible to reenter in stop mode?...
¿Do you think that an external ADC placed far from the MCU will be the solution?
Hello Cristian,
To ensure that neither the USB module nor the SCI module do not cause premature wakeup during data acquisition, their interrupts should be temporarily disabled. However, the test you conducted does seem to indicate that premature wakeup is not occurring.
Betadine wrote:
I collect 50 samples and make the division for reducing noise... for a few! but not success
Could you elaborate on why this did not reduce the fluctuations (assuming your input signal was constant over the period)? Over what period of time were the 50 samples collected. Depending on the frequency of noise components, there may be some advantage in reducing the sample rate, particularly if hum components might be present.
Betadine wrote:About the stop mode,
Yes it´s true, the register is written in the initialization, but then... if I have to take 50 samples how the demons I put the MCU in stop mode 50 times! cause that means 50 IRQs. If once the MCU is in stop mode at the beggining, after wake up, how is possible to reenter in stop mode?...
The SOPT1 register needs to be written to enable the STOP instruction, otherwise this instruction is treated as an illegal op code. This only needs to be done once, along with the setup of SPMSC1 register, and other system registers. After this, __asm stop will enter the required stop mode. You also need to ensure that all clocks are disabled during stop mode.
If you need to acquire 50 readings in quick succession, you would set up a loop that completed the 50 readings for the acquisition process. Stop mode would be entered 50 times, and of course, wakeup would happen 50 times when each ADC reading was completed.
Whether or not an external ADC would give improved results would depend on if the source of the noise was MCU clock related.
Betadine wrote:I almost forgot:
The noise fluctuation dissapear when the signal data is near GND
The noise is bigger when signal data is near VRefH -> the error there is around 0.25%
This would tend to indicate that the majority of the noise is not entering via a ground path. The primary contenders for the noise source would be either the reference signal or the input signal.
A resistance of less than 100 ohms, inconjunction with a 22uF capacitor, I do not consider to be an effective input filter for high frequency noise, especially if the capacitor type is electrolytic. A 100nF capacitor in close proximity to the ADC input pin is typically recommended, with a return path to analog ground. However, other buffering and filtering measures may also be necessary, depending on the nature of your input signal.
Regards,
Mac
Hi Mac
Putting a 100nF near the MCU between data signal and ground seems to be a little little better, I almost have it, I´m going to try now the stop3 mode instead the wait mode. I have understood much better the stop3 now with your post. Thank you.
But I have notice something quite strange... When Vref=4.096mV and Signal=4.096mV the ADC sample value is around 3400 +/- 10 (as always for these range of values)
If I raise the signal data voltage to meet sample number 4096, the multimeter says that Signal data is 5V.
So, it seems that VrefH of 4V is Ignored by the MCU and takes 5V instead of Vref.
Am I missing something? Have you ever see this issue?
VrefH = 4V!!
Hello,
I seem to recall that you are using a demo board. Assuming that the demo board is actually capable of accepting an external reference for tha ADC, it would seem that you may not have the correct jumpering. What voltage do you measure at the VrefH pin of the MCU?
Regards,
Mac
Yes, I´m Using DEMOJM with a JM16 daughter board
The problem is near to be resolve I feel, I´ve disconnected VrefH and you know what the MCU says? it doesn´t care!! O.o
The MCU continues to take VrefH from the "Unknown"
I believe that there we have the reason of the "noise"... cause it´s ignoring the voltage reference supplied!
I forgot to tell before where the signal data comes from, it cames from a 12V battery 3.5Ah (big battery) and through resistors I arrive to 4V (just for testing) the reality is that a geotecnic sonde take that power (12V) and returns as a Current font of 0-20 mA, with that current and 0.1% tolerance resistance I obtain 0-4V.
For testing I use a resistive Divisor, so the NOISE of the data signal barely exists, around +/- 1mV.
I tried stop mode succesfully as you described but... only for 1 sample, I take 1 sample... manually click and get another... and even worst! because not only the values seem to has the same noise... after taking 4 o 5 samples the ADC don´t answer, and the IRQs of the ADC doesn´t enter. I ve tried with a bucle taking 2 samples, it can do it once, but not more, if the bucle is (i<50) forget it, it doesnt work. The sample rate of the ADC is controlled by this bucle, and when the ADC finish then it can continue. To control the sample rate, I can use the RTC, but cause I´m using wait mode (works nice) I´m afraid by IRQs cause the awakening. As I thought that a quick way for slow the sample rate was to do a sub-bucle (from 0 to 50000) doing nothing. But the results was the same.
I believe that:
the MCU is not the problem.
GND is not the problem.
Data signal is not the problem
The problem is... VrefH which I have disconnected, and see with the multimeter pin45 in the daughter card for see if it´s really disconnected... and it marks 0.03V. Fantastic, now the MCU has not VRefH, jaja
But , when running the ADC doesn´t care, he still works with 5V as VrefH.
Im soldering directly to the daughter card instead of using the motherboard, so I can be sure that pin 45 has 0 volts...
Well, PE documentation say this, but when I look for the pdf to see if pin45 is VRefH I realize that the pdf of the JM16 doesnt include the 64 pin package, fantastic. Only 32-48 pin package, so how is possible I have a JM16 64 pin package...
The real problem is, where is VrefH, is it taking from VDDAD directly? The pdf, says that 48 pin package still mix AVDD & VREFH in the same pin, Is it good idea to insert a voltage reference to the AVDD directly?
Voltage reference can not give more than 10mA... but maybe the ADC it´s taking the reference from there...
Im going to see if my MCU exists in the datasheets ... ¬¬ and later post a solution, cause in this moment I don´t know where this MCU cames from, maybe from Jupiter or who knows! with a ghost pin called VrefH... lol
Hello Cristian,
Betadine wrote:I tried stop mode succesfully as you described but... only for 1 sample, I take 1 sample... manually click and get another... and even worst! because not only the values seem to has the same noise... after taking 4 o 5 samples the ADC don´t answer, and the IRQs of the ADC doesn´t enter. I ve tried with a bucle taking 2 samples, it can do it once, but not more, if the bucle is (i<50) forget it, it doesnt work. The sample rate of the ADC is controlled by this bucle, and when the ADC finish then it can continue. To control the sample rate, I can use the RTC, but cause I´m using wait mode (works nice) I´m afraid by IRQs cause the awakening. As I thought that a quick way for slow the sample rate was to do a sub-bucle (from 0 to 50000) doing nothing. But the results was the same.
I am having difficulty understanding what you mean, particularly with the word "bucle". Perhaps the firmware operation may become clearer if you post this portion of your code.
On the Vref issue -
When you select a lower pin count device where a number of different packages are available, you should always check out which facilities you will lose. This information should normally be apparent from the block diagram for the device. In this case it seems it is the external access to Vref. In these instances, VrefH will be internally bonded to VddA, and VrefL to VssA. Note that VddA must operate at the same potential as Vdd, and similarly with VssA and Vss. The reason that the VddA and VssA pins are externally available is so that additional filtering can be used for the analog supply.
If you require operation from a 4 volt external reference, when Vdd is 5 volts, you will need to choose a larger package version, where the reference pins are separately available.
Regards,
Mac
To avoid the Vdd=Vref issue described in this thread, I had to use a 48-pin S12 instead of a S08 in two projects (losing 2 bits of resolution), and I had to use an external ADC in yet another project.
The fault is Freescale's: the 48 QFP pinout for S08 is quite a fiasco. Who on earth wants 16 ADC channels x 12 bit resolution with the MCU supply voltage as Vref?! I really wonder what's the rationale behind that pinout.
Ups, "bucle" means "loop" in spanish
I don´t see much far for the stop mode.
In the initialization I write both stop3 mode init registers once, following all the pdf instructions.
The source code was deleted, cuase it was only the two lines initialization, and later put __asm stop; after starting the conversion... to be awaken by the ADC Interrupt end of conversion.
For 1 conversion, works good, but if I make 2 or three conversions (in a loop) it crash, while with the _asm wait; instruction works fine.
For the moment Im not going to use stop3 mode. I have changed the MCU for a 64 pin package and making the Board. I suppose that if I put the correct voltage reference in the correct pin all will work fine.
About why stop3 doesn´t work I don´t know. Maybe I need longer sample rates. But for now it´s good, I have take in account all the messages here in the forum and I read them many times (an more to be read) including all transient voltage protection and some filter and buffer posibilities.
For the moment, the ADC noise has been found, thanks a lot! Probably I will be back with some other staff. I have now a more clearly vision for making the design avoiding demo boards.
Cheers.
Cristian
Demo JM16 comes with 48 pin package (QFN).
The daughter card has 64 pins, DEMOJM16 documentation speaks about pin 45 is VrefH.
But, 48 pin package dont has VrefH in that pin, cause it´s tied to VDDAD... ¬¬
Could be nice to include in the documentation of the JMDemo some advice like, hey! VrefH is not there! is in the VDDAD pin.
I know that the DS is where to see all the information, but the schematics of the DEMOJM are so pretty that I have followed the pins through that schematic. It´s not a bug... but could be nice some advertisement for people like me who trust in the schematics of P&E
If someone has the DEMOJM16... watch out with the ADC converter and the pinout!!
So it´s clear now... I´m going to connect the voltage reference to the VDDAD, but not without being warned by you. I have looked into the electrical characteristics, and it seems that the ADC consumes MicroA, the voltage reference can give until 10mA... Is it usual to connect it there?
I´ve been advertised with the common mode in this case...
Regards.
Cristian.
I almost forgot:
The noise fluctuation dissapear when the signal data is near GND
The noise is bigger when signal data is near VRefH -> the error there is around 0.25%
Hello,
Are you sure you have a sufficiently low impedance voltage source connected to the input?
Have you tried replacing it with a very low impedance source to prove that the variation you are seeing is indeed created inside the MCU?
<100 ohms (resistive impedance) with decoupling C = 22microF (constand DC voltage is going to be measured)
I dont understand, 10 LSB samples of noise in high values (2-4V) and 1 or 2 smaples of noise in (0-1V)
Im going to try putting 100nF capacitors near the micro, move the union of GND with AGND... cause something happen there and I´m not sure what it is, but the ADC should work better I feel...I mean with less noise