Hello All,
I've a strange problem with ADC10 module of MSP430G2553 when using LM35DZ. The code below works as it's supposed to but when i change ADC input channel other than INCH_0, i get a constant reading of 2.6 Volts.
ADC10CTL0 = SREF_1 + ADC10SHT_3 + REFON + ADC10ON; // Vref = 1,5V + SHT = x64 ADC10CTL1 = INCH_0 + ADC10DIV_3; ADC10AE0 = BIT0;
When using INCH_0 i get a reding of appr. 230 mVolts which is correct. But when i change the code as follows (x is between 1 and 7) i get a constant reading of 2.6 Volts.
ADC10CTL0 = SREF_1 + ADC10SHT_3 + REFON + ADC10ON; // Vref = 1,5V + SHT = x64 ADC10CTL1 = INCH_x + ADC10DIV_3; ADC10AE0 = BITx;
When INCH_0 pin is floating, raw readings change between 490 and 550. And when INCH_x (x is between 1 and 7 again) is floating, raw readings are always 1023.
When i connect another analog source (such as batteries between 1.0 V and 1.5 V) i always get correct readings no matter which ADC input channel i use.
Probably this is a ADC10 settings issue. Could anyone tell me what i'm missing?
Thanks in advance,
Emre.
Hi, Are you setting Direction to Input? Which voltage is measured when pin are floating? 1023 is the full scale reading so if the pin is set to output or REN enable a resistor as pullup may be this value happen. Batteries force input to the internal voltage sinking the pullup weak current.
From your chunk of code and writing no more than this can be extracted, please tell us if this confirm or more detailed description and full code initializing port are necessary to formulate some possible source of issue.
I think ADC has no issue at all.
Regards
Roberto.
Roberto
Please login & click Verify Answer if this post answered your question.
Thank you for your reply Roberto,
After i read your message, i checked the P1 registers in debug mode and found out that P1IN has a default value of 0x0E which means P1IN.1, P1IN.2 and P1IN.3 are 1 and other pins are 0.
When Vout of LM35DZ is connected to pins 0, 4, 5, 6 and 7 the readings are correct. But when it's connected to pins 1, 2 or 3 the reading are always 2.6 Volts (measured by a voltmeter since reference voltage of ADC10 is 1.5 Volts)
I understand that the problem will be solved when P1IN is set to 0x00. How can i do that?
The full code is as follows. Comments are not in English but since the code is short, i hope you don't mind.
#include "..\hd44780\hd44780.h"volatile float sicaklik = 0;int _system_pre_init(void){ WDTCTL = WDT_ADLY_250; //Watchdog timer zaman aralığı 250 milisaniye. BCSCTL1 = CALBC1_1MHZ; //BSC 1 MHz. DCOCTL = CALDCO_1MHZ; //DCO 1 MHz. //BCSCTL3 |= BIT2; //Kristal osilatör kondansatörü 6 pF. return(1);}void main (void){ __delay_cycles(1000000); //Kristal ve LCD Display'in başlamasını bekle. hd44780_Init(); //LCD Display'i başlat. ADC10CTL0 = SREF_1 + ADC10SHT_3 + REFON + ADC10ON; // Vref = 1,5V + SHT = x64 ADC10CTL1 = INCH_0 + ADC10DIV_3; ADC10AE0 = BIT0; IE1 |= WDTIE; //Watchdog timer için interrupt enable. IFG1 &= ~WDTIFG; //Hemen interrupt oluşmasını engellemek için flag'i temizle. LCD_Cursor(0,0); LCD_Print(" LM35DZ isi sensoru "); _BIS_SR(LPM3_bits + GIE); //Düşük güç moduna gir ve interrupt'ları enable. while(1) //Bu döngü hiç işletilmeyecek. { LCD_Cursor(0,0); LCD_Print("Never Executed"); }}#pragma vector=WDT_VECTOR__interrupt void WDT_ISR (void){ static unsigned int adc[11] = {0,0,0,0,0,0,0,0,0,0}; static int count = 0; LCD_Cursor(count, 3); LCD_Print(" o"); ADC10CTL0 |= ENC + ADC10SC; // ADC dönüşümünü başlat while(ADC10CTL1 & ADC10BUSY); adc[count++] = ADC10MEM; if (count == 10) { count = 0; adc[10] = (adc[0] + adc[1] + adc[2] + adc[3] + adc[4] + adc[5] + adc[6] + adc[7] + adc[8] + adc[9]) / 10; sicaklik = (adc[10] / 1024.0f) * 1500.0f; LCD_Cursor(0,1); LCD_PrintInt((int)sicaklik, 4); LCD_Print(" - "); LCD_PrintInt(sicaklik / 10,0); LCD_Print(","); LCD_PrintInt((int)sicaklik % 10,0); LCD_Print("ßC"); LCD_Cursor(0,2); LCD_PrintInt(adc[10], 0); LCD_Print(" "); } //IFG1 &= ~WDTIFG;}//WDT ISR
M. Emre TureI understand that the problem will be solved when P1IN is set to 0x00. How can i do that?
_____________________________________Before posting bug reports or ask for help, do at least quick scan over this article. It applies to any kind of problem reporting. On any forum. And/or look here.If you cannot discuss your problem in the public, feel free to start a private conversation: click on my name and then 'start conversation'. But please do so only if you really cannot do it in a public thread, as I usually read all threads. And I prefer to answer where others can profit from it (or contribute to it) too.
One of the instructors from www.mcu-turkey.com has told me the source of the problem and its solution. You are absolutely right; there's voltage on pins P1.1, P1.2 and P1.3 and their source is launchpad itself!
Unlike other pins, P1.1, P1.2 and P1.3 are special. P1.1 and P1.2 are connected to TXD and RXD. P1.3 is connected to S2 with a pull-up resistor. Low analog sources such as LM35DZ produces cannot suppress the voltage on P1.1, P1.2 and P1.3
The solution is simply to disconnect the RXD and TXD jumpers in order to use P1.1 and P1.2. The pull-up resistor should be removed to use P1.3 but this doesn't seem to be a good idea since it doesn't have a jumper. As far as I know launchpad rev 1.5 doesn't include a pull-up resistor connected to S2. I'm using rev 1.4.
Best regards,
M. Emre TureThe pull-up resistor should be removed to use P1.3 but this doesn't seem to be a good idea since it doesn't have a jumper.