biza 0 Posted September 9, 2014 Share Posted September 9, 2014 hello friends, I have a big problem with small MSP430G2553, I would like to make a capture samples at P1.2 of the microcontroller, but my code does not work, what am I doing wrong, can someone help me. My code: unsigned int adcValue = 0; int i, BPM[10]; int maior = BPM[0]; int menor = BPM[0]; int contagem =0; /*****************************************************************/ /********* LOCAL FUNCTIONS *********/ /*****************************************************************/ void ADC_ConfigAnalogInput(void){ P1DIR2IN(BIT0); ADC10CTL0 &= ~(ENC); ADC10CTL1 = (INCH_0 + ADC10DIV_0); ADC10CTL0 = (SREF_0 + ADC10SHT_3 + ADC10ON + ADC10IE); ADC10AE0 |= BIT0; ADC10CTL0 |= ENC; } void ADC_ReadAnalogInput(void){ ADC_ConfigAnalogInput(); while (ADC10CTL1 & BUSY); // WAIT IF BUSY ADC10CTL0 |= ADC10SC; __bis_SR_register(CPUOFF + GIE); // LPM0, ADC10_ISR will force exit adcValue = ADC10MEM; } /* * */ unsigned int ADC_GetValue(void) { return adcValue; for (j=0;j<timer; j++){ BPM[j]=adcValue; if(maior < BPM[i]){ maior = BPM[j]; } if(menor > BPM[j]){ menor = BPM[j]; } } if(contagem>59) contagem =0; else contagem++; } /*****************************************************************/ /********* END *********/ /*****************************************************************/ Quote Link to post Share on other sites
abecedarian 330 Posted September 9, 2014 Share Posted September 9, 2014 @@biza First thing I see is no "main()" function. Second, this code isn't in a function anywhere: 62.if(contagem>59) 63.contagem =0; 64.else 65.contagem++;Is there more code than this? Also, maybe search the forums here for ADC examples. Quote Link to post Share on other sites
biza 0 Posted September 9, 2014 Author Share Posted September 9, 2014 yes there is more code, the main calls the two main functions ADC_GetValue(void),ADC_ReadAnalogInput(void), this lines if(contagem>timer) contagem =0;elsecontagem++; used to make a count, timer is equal a 59 Quote Link to post Share on other sites
cubeberg 540 Posted September 10, 2014 Share Posted September 10, 2014 The most obvious issue - you're using INCH_0 which is A0 (P1.0). You want INCH_2 since you're using P1.2 which is A2 (check the family guide and data sheet for the 2553). Could be something else - but that's a start. Quote Link to post Share on other sites
David Bender 28 Posted September 10, 2014 Share Posted September 10, 2014 You would also want to change BIT0 to BIT2 in this line: ADC10AE0 |= BIT0; 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.