Hello all,
I've been trying to do an analog to digital conversion using MSP430 Launchpad. First I tried to reach every single bit in the ADC10MEM register but I gave up on that. Now, the thing I've been trying is to segmentize the ADC10MEM register, i.e, I will divide the value to 10 levels, and display the output on a seven segment display. The code is the following:
#include "msp430g2231.h"
void ConfigureAdc(void)
{
/* Configure ADC Channel */
ADC10CTL1 = INCH_5 + ADC10DIV_3 ; // Channel 5, ADC10CLK/4
ADC10CTL0 = SREF_0 + ADC10SHT_3 + ADC10ON + ADC10IE; //Vcc & Vss as reference
ADC10AE0 |= BIT5; //P1.5 ADC option
}
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
BCSCTL1 = CALBC1_1MHZ; // Set range
DCOCTL = CALDCO_1MHZ;
BCSCTL2 &= ~(DIVS_3); // SMCLK = DCO = 1MHz
P1DIR |= 0xdf; //All ports except P1.5 to output
P1SEL |= BIT5; //ADC Input pin P1.5
P1OUT &= ~(0xdf); // 0 initialization
ConfigureAdc();
__enable_interrupt(); // Enable interrupts.
while(1)
{
__delay_cycles(1000); // Wait for ADC Ref to settle
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
__bis_SR_register(CPUOFF + GIE); // LPM0 with interrupts enabled
/* the part I divided ADC10MEM to 10 */
if(ADC10MEM > 922)
P1OUT = 0x4; //these hex numbers are to display numbers from 9 to 0 in the seven segment
else if(ADC10MEM > 820)
P1OUT = 0x0;
else if(ADC10MEM > 718)
P1OUT = 0xF;
else if(ADC10MEM > 616)
P1OUT = 0x20;
else if(ADC10MEM > 514)
P1OUT = 0x24;
else if(ADC10MEM > 412)
P1OUT = 0x4C;
else if(ADC10MEM > 310)
P1OUT = 0x6;
else if(ADC10MEM > 207)
P1OUT = 0x12;
else if(ADC10MEM > 105)
P1OUT = 0x4F;
else
P1OUT = 0x1;
}
}
// ADC10 interrupt service routine
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR (void)
{
__bic_SR_register_on_exit(CPUOFF); // Return to active mode
}
As I tried this with voltages in a range from 0 to 3.3 I got High from P1.2 and L from all others everytime and this is none of the outputs I gave to the seven segment in the if statements.
I looked at all the example codes that TI published, I also read the User's manuals many times but could not find a way out.
Any help is appreciated,
Best regards
Günay Turan