RobG 1,892 Posted February 8, 2013 Share Posted February 8, 2013 Can you try adcHigh = adc + 3; // or even 4 adcLow = adc - 3; Quote Link to post Share on other sites
PowerX 2 Posted February 8, 2013 Share Posted February 8, 2013 (edited) Can you try adcHigh = adc + 3; // or even 4 adcLow = adc - 3; Still floating +/- 3 and 4. Maybe if reading multiple values and comparing them to take the logical decision? PS : i`m trying now to put 2 resistors instead of pot (maybe it`s not so accurate making noise). Feedback: still same result with the 2 resistors instead of pot. Maybe adding a filter will do the trick. Edited February 8, 2013 by PowerX Quote Link to post Share on other sites
DanAndDusty 62 Posted February 9, 2013 Share Posted February 9, 2013 You could try running the test code I wrote a while back. It runs the ADC and DCO at a variety of speeds and ADC settings. It then uses the UART to tell you how many samples it managed and tells you what the highest and lowest readings were. Anyway the link is http://forum.43oh.com/topic/892-adc10-speed-tests-using-hardware-uart/ You can see my test readings. You could see if yours are of a similar stability. Hope this helps. Dan Quote Link to post Share on other sites
oliveiracarlos 2 Posted February 12, 2013 Author Share Posted February 12, 2013 PowerX, thanks for testing. DanAndDusty, I am too noob to use your code. Could you try to help me plz ? A friend of mine wrote this code. This code is "almost there", a very little instable output: unsigned int pot = 0; unsigned int adc = 0;unsigned int i = 0; long sum = 0; void setup() { Serial.begin(9600); } void loop() { while (i<100){ adc = analogRead(A7); sum = sum + (long)adc; i++; } sum = sum/100; pot = sum >> 3; Serial.print("Average = "); Serial.println(pot); delay(10); i=0; sum=0; } Thanks all, again. Quote Link to post Share on other sites
RobG 1,892 Posted February 12, 2013 Share Posted February 12, 2013 The code above is pretty much the same as my code in post #4, but uses 100 samples instead of 8. You will still get that 1 digit error, because even if you repeat it 1000 times, the chance of 1 digit error is close to 50/50. Averaging works well when samples are far apart. Quote Link to post Share on other sites
PowerX 2 Posted February 12, 2013 Share Posted February 12, 2013 The code above is pretty much the same as my code in post #4, but uses 100 samples instead of 8. You will still get that 1 digit error, because even if you repeat it 1000 times, the chance of 1 digit error is close to 50/50. Averaging works well when samples are far apart. Rob is right. It get`s as stable as it can be even with a filtered lab power supply and low tolerance resistors. As Rob said Welcome to the real world. You will have to go with another mcu or go digital for your application, my opinion. Quote Link to post Share on other sites
oliveiracarlos 2 Posted February 12, 2013 Author Share Posted February 12, 2013 PowerX, i am thinking about to choose another one. Another MSP430 example, like i Quote Link to post Share on other sites
RobG 1,892 Posted February 12, 2013 Share Posted February 12, 2013 1. What value is your pot? 2. What are the default ADC settings for analogRead? (I am not familiar with Energia.) Few things you can try: lower pot's value, extend sample time, and use Vref from MSP430 to power your pot. In the example below, I am using 50k pot (el cheapo,) Vcc to power my pot, and S&H time = 16x ADC10CLKs. Very stable, no changes whatsoever. #include <msp430g2553.h> unsigned char txData[6] = {0,0,0,0,'\r','\n'}; void binaryToASCII(unsigned int n, unsigned char * digits); void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WDT BCSCTL1 = CALBC1_1MHZ; DCOCTL = CALDCO_1MHZ; P1SEL = BIT2; // P1.2 is TXD P1SEL2 = BIT2; UCA0CTL1 |= UCSSEL_2; UCA0BR0 = 104; UCA0BR1 = 0; UCA0MCTL = UCBRS_1; UCA0CTL1 &= ~UCSWRST; ADC10CTL0 = ADC10SHT_2 + ADC10ON + ADC10IE; ADC10CTL1 = INCH_0; // P1.0 analog input ADC10AE0 |= BIT0; CCTL0 = CCIE; // CCR0 interrupt enabled CCR0 = 6400; // sample every 50ms TACTL = TASSEL_2 + MC_1 + ID_3; // SMCLK/8, upmode _bis_SR_register(LPM0_bits + GIE); // Enter LPM0 w/ interrupt } #pragma vector=ADC10_VECTOR __interrupt void ADC10_ISR(void) { binaryToASCII(ADC10MEM >> 3, txData); char c = 0; while(c < 6) { while (!(IFG2 & UCA0TXIFG)) ; UCA0TXBUF = txData[c]; c++; } } // Timer A0 interrupt service routine #pragma vector = TIMER0_A0_VECTOR __interrupt void Timer_A (void) { ADC10CTL0 |= ENC + ADC10SC; } void binaryToASCII(unsigned int n, unsigned char * digits) { __asm(" clr R14"); __asm(" rla R12"); __asm(" rla R12"); __asm(" rla R12"); __asm(" rla R12"); __asm(" rla R12"); __asm(" dadd R14, R14"); __asm(" rla R12"); __asm(" dadd R14, R14"); __asm(" rla R12"); __asm(" dadd R14, R14"); __asm(" rla R12"); __asm(" dadd R14, R14"); __asm(" rla R12"); __asm(" dadd R14, R14"); __asm(" rla R12"); __asm(" dadd R14, R14"); __asm(" rla R12"); __asm(" dadd R14, R14"); __asm(" rla R12"); __asm(" dadd R14, R14"); __asm(" rla R12"); __asm(" dadd R14, R14"); __asm(" rla R12"); __asm(" dadd R14, R14"); __asm(" rla R12"); __asm(" dadd R14, R14"); __asm(" rla R12"); __asm(" dadd R14, R14"); __asm(" mov.b R14, 3(R13)"); __asm(" swpb R14"); __asm(" mov.b R14, 1(R13)"); __asm(" rra R14"); __asm(" rra R14"); __asm(" rra R14"); __asm(" rra R14"); __asm(" mov.b R14, 0(R13)"); __asm(" swpb R14"); __asm(" mov.b R14, 2(R13)"); __asm(" and #0x0F0F, 0(R13)"); __asm(" and #0x0F0F, 2(R13)"); __asm(" add.b #0x30, 3(R13)"); __asm(" tst.b 0(R13)"); __asm(" jnz l1"); __asm(" mov.b #0x20, 0(R13)"); __asm(" tst.b 1(R13)"); __asm(" jnz l2"); __asm(" mov.b #0x20, 1(R13)"); __asm(" tst.b 2(R13)"); __asm(" jnz l3"); __asm(" mov.b #0x20, 2(R13)"); __asm(" jmp l4"); __asm("l1:"); __asm(" add.b #0x30, 0(R13)"); __asm("l2:"); __asm(" add.b #0x30, 1(R13)"); __asm("l3:"); __asm(" add.b #0x30, 2(R13)"); __asm("l4:"); return; } oliveiracarlos 1 Quote Link to post Share on other sites
oliveiracarlos 2 Posted February 13, 2013 Author Share Posted February 13, 2013 10k pot (B10k) thanks Rob for your help, but I give up. I gonna try with arduino because i see lots of pot examples working. Quote Link to post Share on other sites
RobG 1,892 Posted February 13, 2013 Share Posted February 13, 2013 That's odd. Did you try different pot? 10k is perfect, so I am wondering about it's condition. Switching to another MCU will not solve your problem, it must be something else. Quote Link to post Share on other sites
calinp 24 Posted February 13, 2013 Share Posted February 13, 2013 In Energia the ADC and its reference are turned on and off for each conversion. Maybe the settling time (for the reference) is not enough. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.