Hello, I was trying to modify the ADC - ACLK source example from TI (msp430g2x33_adc10_11).
I have soldered the 32kHz crystal on my MSP-EXP430G2 launchpad.
#include <msp430.h>
void init(){
ADC10CTL1 = SHS_1 + CONSEQ_2 + INCH_3; // TA1 trigger sample start
ADC10CTL0 = SREF_0 + ADC10SHT_2 + ADC10ON + ADC10IE +MSC;
__enable_interrupt(); // Enable interrupts.
TACCR0 = 30; // Delay to allow Ref to settle
TACCTL0 |= CCIE; // Compare-mode interrupt.
TACTL = TASSEL_2 + MC_1; // TACLK = SMCLK, Up mode.
LPM0; // Wait for delay.
TACCTL0 &= ~CCIE; // Disable timer Interrupt
__disable_interrupt();
ADC10CTL0 |= ENC + ADC10SC; // ADC10 Enable
ADC10AE0 |= BIT3; // P1.3 ADC10 option select
P1DIR |= 0x01; // Set P1.0 output
TACCR0 = 5-1; // Sampling Period 6553.6 Hz
TACCTL1 = OUTMOD_3; // TACCR1 set/reset
TACCR1 = 4; // TACCR1 PWM Duty Cycle
TACTL = TASSEL_1 + MC_1; // ACLK, up mode
}
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; //Stop WDT
if(CALBC1_1MHZ==0xFF) {
while(1);
}
DCOCTL = 0;
BCSCTL1 = CALBC1_1MHZ; // Set DCO
DCOCTL = CALDCO_1MHZ;
init();
__bis_SR_register(LPM3_bits + GIE); // Enter LPM0, interrupts enabled
}
// ADC10 interrupt service routine
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(ADC10_VECTOR))) ADC10_ISR (void)
#else
#error Compiler not supported!
#endif
{
if (ADC10MEM < 0x155) // ADC10MEM = A1 > 0.5V?
P1OUT &= ~0x01; // Clear P1.0 LED off
else
P1OUT |= 0x01; // Set P1.0 LED on
}
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=TIMER0_A0_VECTOR
__interrupt void ta0_isr(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(TIMER0_A0_VECTOR))) ta0_isr (void)
#else
#error Compiler not supported!
#endif
{
TACTL = 0;
LPM0_EXIT; // Exit LPM0 on return
}
I hope I'm on the correct track;
I wanted to set the sampling frequency approximately 6553 Hz so I can send some data via UART which will use a 115200 baud rate.
Because I will be using UART which occupies P1.1, I wanted to use P1.3 (A3, INCH3) as my ADC input.
When trying the original example (using P1.1), it read the input signal correctly.
However, the P1.3 couldn't read the ADC input (a function generator's 2Hz min=0V, max=1.5V sine wave) and it shows a saturated (a digital value close to the reference voltage) value.
This happens whether P1.3 is connected or not connected to an input.
- Is my sampling frequency configured as 6553 Hz correctly?
- In this case, what seems to be a problem for P1.3? Is this related to ADC10CLK?
