This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hello Together,
i´m trying to measure the degital value of a PT100 output voltage circuit. The Voltage @ 25°C is 1,092V. I use the 2.5 Vref+. i used the P1.0 as input.
The Problem is that i get not stable values. so the digital values vary with +-20 per second. so i get values from 420 until 460. Normally the value should be 446 and stable for some secondes.
can someone help me? it may be that i don´t understand the sampling time or the sampling and converting initialization.
//*********************************************************** // Temperature measurement with PT100 //Aymen Ben Hafsa // Juni/2012 //*********************************************************** #include <msp430g2553.h> //#ifndef TIMER0_A1_VECTOR //#define TIMER0_A1_VECTOR TIMERA1_VECTOR //#define TIMER0_A0_VECTOR TIMERA0_VECTOR //#endif volatile long tempRaw; void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer if (CALBC1_1MHZ ==0xFF || CALDCO_1MHZ == 0xFF) // If calibration data is erased BCSCTL1 = CALBC1_1MHZ; // Set range DCOCTL = CALDCO_1MHZ; // Set DCO step + modulation BCSCTL3 |= LFXT1S_2; // LFXT1 = VLO IFG1 &= ~OFIFG; // Clear OSCFault flag BCSCTL2 |= SELM_0 + DIVM_3 + DIVS_3; // MCLK = DCO/8 while(1) { ADC10CTL1 = INCH_1 + CONSEQ_0 ; // Temp Sensor ADC10CLK and P1.0 as ADC input ADC10CTL0 = SREF_1 + ADC10SHT_3 + REFON + ADC10ON + REF2_5V ; ADC10AE0 |= 0x002; // Analog enable for the P1.0 _delay_cycles(5); // Wait for ADC Ref to settle ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start _delay_cycles(100); ADC10CTL0 &= ~ENC; ADC10CTL0 &= ~(REFON + ADC10ON); tempRaw = ADC10MEM; P1OUT |= BIT0; } }
Best regards
Aymen
Dear Aymen,
I think since you switch on and off ADC and reconfigure continuously in the loop, this might lead to some fluctuations in the voltage samples. Do not configure the ADC inside the while loop. Configure ADC once outside out of the loop. Inside the loop you only start the conversion, read the value. Try out this way and let me know.
Regards,
Vidya.
switching the ADC on and off just for the conversion isn't really a problem. Swithcing the reference on and off, however, is, as it requires a long settling time before it is stable. Also, jsut putting a _delay_cycles() to wait for a conversion result isn't a stable approach - better wait for the IFG bit coming up, indiocating that the conversion is done. Or ADC10SC getting cleared.
_delay_cycles is a busy-waiting loop anyway, so why not waiting for the correct 'converison complete' indicator?
Figure 1: The First Measurement with short delay.
Figure 2: The last measurement with longer delay.
so i send you the results from the code composer . I tried with other delay´s time (Figure 2) and with the intialization out of the while function. It´s better now but with +-10 fluctuation . But i measured the output of the circuit with a Osci. and i found that the voltages varies in the microsecond range. So i think i have to choose the best sampling and converting time :-( I think i need a good tutorial to understand the sampling system...
ADC10CTL1 = INCH_1 /*+ ADC10DIV_0 + CONSEQ_0*/; // Temp Sensor ADC10CLK ADC10CTL0 = SREF_1 + ADC10SHT_3 + REFON + ADC10ON + REF2_5V ; //ADC10AE0 |= BIT1; _delay_cycles(500); // Wait for ADC Ref to settle ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start _delay_cycles(100); ADC10CTL0 &= ~ENC; ADC10CTL0 &= ~(REFON + ADC10ON); _delay_cycles(10000); tempRaw = ADC10MEM; _delay_cycles(10000); P1OUT |= BIT0; } }
I would like to mention that i use for the VDD the USB from the Laptop. So i think it can be the source of the Problem. I will try tomorrow to use another voltage source. OK ;-)
Best Regards
Aymen
i used a batterie. So the results are more better. fluctuation of +-5 now ;-)... i think i have a problem in the code now. I have to chose long time of sampling. how can i make it? please
sorry not yet. because i don´t have any idea how i will make the interrupt. because i´m a beginner. So i understand what s he means so instead of waiting i can use the flag check. if it is busy ;-) so i will try to implement the this lines but i need to read the datasheet how can i make it ;-)
i would suggest that you take a look into code samples available for ADC10. It is to easy to write in the answer but you know, you wouldnt learn much.
please check the following link: http://www.ti.com/lsds/ti/microcontroller/16-bit_msp430/code.page?DCMP=MSP430&HQS=Other+OT+msp430codeexamples
i would like to remind you again: configure your ADC outside of while loop, this is very trivial. it might work right away!!
That's independent of the interrupt. just move teh first four lines from inside the while to before the wile. And delete the line in which you reset REFON and ADC10ON.Aymen Ben said:sorry not yet. because i don´t have any idea how i will make the interrupt
Also, teh delay after switchign the reference on (now the last instruciton before the while) should be significantly increased. The reference settling time is definitely much, much longer than 5 MCLK cycles (5µS@1MHz)
About the delay during conversion, well, just do a busy-waiting while loop, waiting for the ADC10IFG bit becoming set. Plain pollinm, no ISR. Don't forget to clear the bit after reading the result, so you can wait for it again during the next conversion.
**Attention** This is a public forum