EmbeddedRelated.com
Forums

ADC Noise coming from Timer?

Started by GB April 22, 2009
Hello,










I am using an MSP430F1611 to sample a sine wave at 8kHz with the signal fed to ADC input A0.However, when I check using an oscilloscope the A0 port I discover a sort of sawtooth wave (more like a sudden peak and then decaying over ad over again) oscillating at about 8kHz and other times at other rates, which is my timer's rate. Does anyone know of this? I've never had this happen and the fact that this noise has 825mV peak to peak is of course worrying. It can't be just plain noise picked up from the air since the voltage is too much.Is there something I'm missing that's causing the timer connected to the ADC (and triggering it) and results in this noise?I get ADC results whether I have the sine wave connected or disconnected.
Thank you very much
My code is:
#define SamplePrd 500
void main(void)
{

WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer

BCSCTL1 |= DIVA_3; // ACLK= LFXT1CLK/8
TI_SetDCO(TI_DCO_4MHZ);

BCSCTL2 &= ~SELS; // SMCLK = DCO

// Setup IO
P6SEL |= 0x01; // P6.0 ADC option select
// Setup ADC12 module
ADC12CTL0 = ADC12ON; // Turn on ADC12, S&H in sample
// ADC12 Clock=ADC12OSC
ADC12CTL1 = SHS_3 + CONSEQ_2; // S&H src select: Timer_B.OUT1,
// rep. single channel
ADC12IFG = 0x00; // Clear ADC12 interrupt flag reg
ADC12IE |= 0x0001;
ADC12CTL0 |= ENC; // Enable conversion
// Timer_B.OUT1 triggers ADC12 conversion
// Setup Timer_B for recording
TBCTL = TBSSEL_2; // Use SMCLK as Timer_B source
TBR = 0;
TBCCR0 = SamplePrd; // Initialize TBCCR0
TBCCR1 = SamplePrd - 20; // Trigger for ADC12 SC
TBCCTL1 = OUTMOD_7; // Reset OUT1 on EQU1, set on EQU0

TBCTL |= MC0; // Start Timer_B in UP mode
// (counts up to TBCL0)

__bis_SR_register(LPM0_bits + GIE); // Enable interrupts, enter LPM0


}

//-----
// ADC ISR: record mode only, encode and store conversion result
#pragma vector=ADC_VECTOR
__interrupt void ISR_ADC(void)
{
result = ADC12MEM0; // Move results, IFG is cleared
}




Beginning Microcontrollers with the MSP430

The noise may be caused by the ADC sampling process itself. Do you know the impedance, Rs, of the signal that you are trying to digitize?

A0 input pin is equivalent to a 2 k-ohm and a 40 pF in series. Is the the decay time of the noise consistent with (Rs + 2k)*40pf ? Is the peak-to-peak voltage of the noise consistent with this equivalent circuit?

--- In m..., GB wrote:
>
> Hello,
>
> I am using an MSP430F1611 to sample a sine wave at 8kHz with the signal fed to ADC input A0.However, when I check using an oscilloscope the A0 port I discover a sort of sawtooth wave (more like a sudden peak and then decaying over ad over again) oscillating at about 8kHz and other times at other rates, which is my timer's rate. Does anyone know of this? I've never had this happen and the fact that this noise has 825mV peak to peak is of course worrying. It can't be just plain noise picked up from the air since the voltage is too much.Is there something I'm missing that's causing the timer connected to the ADC (and triggering it) and results in this noise?I get ADC results whether I have the sine wave connected or disconnected.
> Thank you very much
> My code is:
> #define SamplePrd 500
>
>
> void main(void)
> {
>
>
>
>
> WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
>
> BCSCTL1 |= DIVA_3; // ACLK= LFXT1CLK/8
> TI_SetDCO(TI_DCO_4MHZ);
>
> BCSCTL2 &= ~SELS; // SMCLK = DCO
>
> // Setup IO
> P6SEL |= 0x01; // P6.0 ADC option select
>
>
> // Setup ADC12 module
> ADC12CTL0 = ADC12ON; // Turn on ADC12, S&H in sample
> // ADC12 Clock=ADC12OSC
> ADC12CTL1 = SHS_3 + CONSEQ_2; // S&H src select: Timer_B.OUT1,
> // rep. single channel
> ADC12IFG = 0x00; // Clear ADC12 interrupt flag reg
> ADC12IE |= 0x0001;
> ADC12CTL0 |= ENC; // Enable conversion
>
>
> // Timer_B.OUT1 triggers ADC12 conversion
>
>
> // Setup Timer_B for recording
> TBCTL = TBSSEL_2; // Use SMCLK as Timer_B source
> TBR = 0;
> TBCCR0 = SamplePrd; // Initialize TBCCR0
> TBCCR1 = SamplePrd - 20; // Trigger for ADC12 SC
> TBCCTL1 = OUTMOD_7; // Reset OUT1 on EQU1, set on EQU0
>
>
>
> TBCTL |= MC0; // Start Timer_B in UP mode
> // (counts up to TBCL0)
>
>
>
> __bis_SR_register(LPM0_bits + GIE); // Enable interrupts, enter LPM0
>
>
> }
>
>
>
>
> //-----------------------------------------
> // ADC ISR: record mode only, encode and store conversion result
> #pragma vector=ADC_VECTOR
> __interrupt void ISR_ADC(void)
> {
> result = ADC12MEM0; // Move results, IFG is cleared
>
>
> }
>
>
>
>
>
>

?what do you have linked to that pin
?what is the freq of the filter you have there
avram

--- On Wed, 4/22/09, GB wrote:
From: GB
Subject: [msp430] ADC Noise coming from Timer?
To: m...
Date: Wednesday, April 22, 2009, 6:42 PM





Hello,





















I am using an MSP430F1611 to sample a sine wave at 8kHz with the signal fed to ADC input A0.However, when I check using an oscilloscope the A0 port I discover a sort of sawtooth wave (more like a sudden peak and then decaying over ad over again) oscillating at about 8kHz and other times at other rates, which is my timer's rate. Does anyone know of this? I've never had this happen and the fact that this noise has 825mV peak to peak is of course worrying. It can't be just plain noise picked up from the air since the voltage is too much.Is there something I'm missing that's causing the timer connected to the ADC (and triggering it) and results in this noise?I get ADC results whether I have the sine wave connected or disconnected.

Thank you very much

My code is:

#define SamplePrd 500

void main(void)

{

WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer



BCSCTL1 |= DIVA_3; // ACLK= LFXT1CLK/8

TI_SetDCO(TI_ DCO_4MHZ) ;



BCSCTL2 &= ~SELS; // SMCLK = DCO



// Setup IO

P6SEL |= 0x01; // P6.0 ADC option select

// Setup ADC12 module

ADC12CTL0 = ADC12ON; // Turn on ADC12, S&H in sample

// ADC12 Clock=ADC12OSC

ADC12CTL1 = SHS_3 + CONSEQ_2; // S&H src select: Timer_B.OUT1,

// rep. single channel

ADC12IFG = 0x00; // Clear ADC12 interrupt flag reg

ADC12IE |= 0x0001;

ADC12CTL0 |= ENC; // Enable conversion

// Timer_B.OUT1 triggers ADC12 conversion

// Setup Timer_B for recording

TBCTL = TBSSEL_2; // Use SMCLK as Timer_B source

TBR = 0;

TBCCR0 = SamplePrd; // Initialize TBCCR0

TBCCR1 = SamplePrd - 20; // Trigger for ADC12 SC

TBCCTL1 = OUTMOD_7; // Reset OUT1 on EQU1, set on EQU0



TBCTL |= MC0; // Start Timer_B in UP mode

// (counts up to TBCL0)



__bis_SR_register( LPM0_bits + GIE); // Enable interrupts, enter LPM0





}

//---------- --------- --------- --------- --------- --------- ---

// ADC ISR: record mode only, encode and store conversion result

#pragma vector=ADC_VECTOR

__interrupt void ISR_ADC(void)

{

result = ADC12MEM0; // Move results, IFG is cleared

}





















avram and old cow,
There is nothing connected to the pin when I get this. I check for shorts on the circuit and it doesn't seem so (no short with any pins that are near).

--- On Wed, 4/22/09, avram ionut wrote:

From: avram ionut
Subject: Re: [msp430] ADC Noise coming from Timer?
To: m...
Date: Wednesday, April 22, 2009, 1:33 PM









?what do you have linked to that pin

?what is the freq of the filter you have there

avram

--- On Wed, 4/22/09, GB wrote:

From: GB

Subject: [msp430] ADC Noise coming from Timer?

To: msp430@yahoogroups. com

Date: Wednesday, April 22, 2009, 6:42 PM

Hello,





















I am using an MSP430F1611 to sample a sine wave at 8kHz with the signal fed to ADC input A0.However, when I check using an oscilloscope the A0 port I discover a sort of sawtooth wave (more like a sudden peak and then decaying over ad over again) oscillating at about 8kHz and other times at other rates, which is my timer's rate. Does anyone know of this? I've never had this happen and the fact that this noise has 825mV peak to peak is of course worrying. It can't be just plain noise picked up from the air since the voltage is too much.Is there something I'm missing that's causing the timer connected to the ADC (and triggering it) and results in this noise?I get ADC results whether I have the sine wave connected or disconnected.

Thank you very much

My code is:

#define SamplePrd 500

void main(void)

{

WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer



BCSCTL1 |= DIVA_3; // ACLK= LFXT1CLK/8

TI_SetDCO(TI_ DCO_4MHZ) ;



BCSCTL2 &= ~SELS; // SMCLK = DCO



// Setup IO

P6SEL |= 0x01; // P6.0 ADC option select

// Setup ADC12 module

ADC12CTL0 = ADC12ON; // Turn on ADC12, S&H in sample

// ADC12 Clock=ADC12OSC

ADC12CTL1 = SHS_3 + CONSEQ_2; // S&H src select: Timer_B.OUT1,

// rep. single channel

ADC12IFG = 0x00; // Clear ADC12 interrupt flag reg

ADC12IE |= 0x0001;

ADC12CTL0 |= ENC; // Enable conversion

// Timer_B.OUT1 triggers ADC12 conversion

// Setup Timer_B for recording

TBCTL = TBSSEL_2; // Use SMCLK as Timer_B source

TBR = 0;

TBCCR0 = SamplePrd; // Initialize TBCCR0

TBCCR1 = SamplePrd - 20; // Trigger for ADC12 SC

TBCCTL1 = OUTMOD_7; // Reset OUT1 on EQU1, set on EQU0



TBCTL |= MC0; // Start Timer_B in UP mode

// (counts up to TBCL0)



__bis_SR_register( LPM0_bits + GIE); // Enable interrupts, enter LPM0





}

//---------- --------- --------- --------- --------- --------- ---

// ADC ISR: record mode only, encode and store conversion result

#pragma vector=ADC_VECTOR

__interrupt void ISR_ADC(void)

{

result = ADC12MEM0; // Move results, IFG is cleared

}








































It seems like your MSP is reseting on every timer interrupt, then the P6 changes from ADC input to something else before you have it configured again.
Check stack overflow or other reasons to loose control.

-Augusto
On Qua 22/04/09 15:06 , GB g...@yahoo.com sent:
> avram and old cow,
> There is nothing connected to the pin when I get this. I check for
> shorts on the circuit and it doesn't seem so (no short with any pins
> that are near).
> --- On Wed, 4/22/09, avram ionut wrote:
> From: avram ionut
> Subject: Re: [msp430] ADC Noise coming from Timer?
> To: m...
> Date: Wednesday, April 22, 2009, 1:33 PM
> ?what do you have linked to that pin 
> ?what is the freq of the filter you have there
> avram
> --- On Wed, 4/22/09, GB wrote:
> From: GB
> Subject: [msp430] ADC Noise coming from Timer?
> To: msp430@yahoogroups. com
> Date: Wednesday, April 22, 2009, 6:42 PM
> Hello,
> I am using an MSP430F1611 to sample a sine wave at 8kHz with the
> signal fed to ADC input A0.However, when I check using an
> oscilloscope the A0 port I discover a sort of sawtooth wave (more
> like a sudden peak and then decaying over ad over again) oscillating
> at about 8kHz and other times at other rates, which is my timer's
> rate. Does anyone know of this? I've never had this happen and the
> fact that this noise has 825mV peak to peak is of course worrying. It
> can't be just plain noise picked up from the air since the voltage is
> too much.Is there something I'm missing that's causing the timer
> connected to the ADC (and triggering it) and results in this noise?I
> get ADC results whether I have the sine wave connected or
> disconnected.
> Thank you very much
> My code is:
> #define SamplePrd            500
> void main(void)
> {
>  WDTCTL = WDTPW + WDTHOLD;                 // Stop watchdog
> timer
>   
>   BCSCTL1 |= DIVA_3;                        // ACLK=
> LFXT1CLK/8
>   TI_SetDCO(TI_ DCO_4MHZ) ;
>   
>    BCSCTL2 &= ~SELS;                          //
> SMCLK = DCO
>    
>  // Setup IO
>   P6SEL |= 0x01;                            // P6.0
> ADC option select
>    // Setup ADC12 module
>   ADC12CTL0 = ADC12ON;                      // Turn on
> ADC12, S&H in sample
>                                             //
> ADC12 Clock=ADC12OSC
>   ADC12CTL1 = SHS_3 + CONSEQ_2;             // S&H src
> select: Timer_B.OUT1,
>                                             //
> rep. single channel
>   ADC12IFG = 0x00;                          // Clear
> ADC12 interrupt flag reg 
>   ADC12IE |= 0x0001;
>   ADC12CTL0 |= ENC;                         // Enable
> conversion
>   // Timer_B.OUT1 triggers ADC12 conversion
>   // Setup Timer_B for recording
>   TBCTL = TBSSEL_2;                         // Use
> SMCLK as Timer_B source
>   TBR = 0;
>   TBCCR0 = SamplePrd;                       //
> Initialize TBCCR0
>   TBCCR1 = SamplePrd - 20;                  // Trigger for
> ADC12 SC
>   TBCCTL1 = OUTMOD_7;                       // Reset
> OUT1 on EQU1, set on EQU0
>   
>   TBCTL |= MC0;                             // Start
> Timer_B in UP mode
>                                             //
> (counts up to TBCL0)
>   
>   __bis_SR_register( LPM0_bits + GIE);       // Enable
> interrupts, enter LPM0
>  
>  
> }
> //---------- --------- --------- --------- --------- --------- ---
> // ADC ISR: record mode only, encode and store conversion result
> #pragma vector=ADC_VECTOR
> __interrupt void ISR_ADC(void)
> {
>   result = ADC12MEM0;                      // Move
> results, IFG is cleared
> }
>
>
>
>
>

That really sounds like it could be it. I was starting to suspect restart and your explanation makes sense.Hopefully I can find out why is it doing that.
--- On Wed, 4/22/09, Augusto Einsfeldt wrote:

From: Augusto Einsfeldt
Subject: Re: [msp430] ADC Noise coming from Timer?
To: m...
Date: Wednesday, April 22, 2009, 2:21 PM









It seems like your MSP is reseting on every timer interrupt, then the P6 changes from ADC input to something else before you have it configured again.

Check stack overflow or other reasons to loose control.

-Augusto

On Qua 22/04/09 15:06 , GB gusgl2001@yahoo. com sent:

> avram and old cow,

> There is nothing connected to the pin when I get this. I check for

> shorts on the circuit and it doesn't seem so (no short with any pins

> that are near).

> --- On Wed, 4/22/09, avram ionut wrote:

> From: avram ionut

> Subject: Re: [msp430] ADC Noise coming from Timer?

> To: msp430@yahoogroups. com

> Date: Wednesday, April 22, 2009, 1:33 PM

> ?what do you have linked to that pin

> ?what is the freq of the filter you have there

> avram

> --- On Wed, 4/22/09, GB wrote:

> From: GB

> Subject: [msp430] ADC Noise coming from Timer?

> To: msp430@yahoogroups. com

> Date: Wednesday, April 22, 2009, 6:42 PM

> Hello,

> I am using an MSP430F1611 to sample a sine wave at 8kHz with the

> signal fed to ADC input A0.However, when I check using an

> oscilloscope the A0 port I discover a sort of sawtooth wave (more

> like a sudden peak and then decaying over ad over again) oscillating

> at about 8kHz and other times at other rates, which is my timer's

> rate. Does anyone know of this? I've never had this happen and the

> fact that this noise has 825mV peak to peak is of course worrying. It

> can't be just plain noise picked up from the air since the voltage is

> too much.Is there something I'm missing that's causing the timer

> connected to the ADC (and triggering it) and results in this noise?I

> get ADC results whether I have the sine wave connected or

> disconnected.

> Thank you very much

> My code is:

> #define SamplePrd 500

> void main(void)

> {

> WDTCTL = WDTPW + WDTHOLD; // Stop watchdog

> timer

>

> BCSCTL1 |= DIVA_3; // ACLK=

> LFXT1CLK/8

> TI_SetDCO(TI_ DCO_4MHZ) ;

>

> BCSCTL2 &= ~SELS; //

> SMCLK = DCO

>

> // Setup IO

> P6SEL |= 0x01; // P6.0

> ADC option select

> // Setup ADC12 module

> ADC12CTL0 = ADC12ON; // Turn on

> ADC12, S&H in sample

> //

> ADC12 Clock=ADC12OSC

> ADC12CTL1 = SHS_3 + CONSEQ_2; // S&H src

> select: Timer_B.OUT1,

> //

> rep. single channel

> ADC12IFG = 0x00; // Clear

> ADC12 interrupt flag reg

> ADC12IE |= 0x0001;

> ADC12CTL0 |= ENC; // Enable

> conversion

> // Timer_B.OUT1 triggers ADC12 conversion

> // Setup Timer_B for recording

> TBCTL = TBSSEL_2; // Use

> SMCLK as Timer_B source

> TBR = 0;

> TBCCR0 = SamplePrd; //

> Initialize TBCCR0

> TBCCR1 = SamplePrd - 20; // Trigger for

> ADC12 SC

> TBCCTL1 = OUTMOD_7; // Reset

> OUT1 on EQU1, set on EQU0

>

> TBCTL |= MC0; // Start

> Timer_B in UP mode

> //

> (counts up to TBCL0)

>

> __bis_SR_register( LPM0_bits + GIE); // Enable

> interrupts, enter LPM0

>

>

> }

> //---------- --------- --------- --------- --------- --------- ---

> // ADC ISR: record mode only, encode and store conversion result

> #pragma vector=ADC_VECTOR

> __interrupt void ISR_ADC(void)

> {

> result = ADC12MEM0; // Move

> results, IFG is cleared

> }

>

>

>

>

>






















so, that is your problem.
you should feed some energy into that pin.
first condition: the amount of energy should be greater than the estimated energy of captured noise, at least twice - if you have a constant voltage variable frequency signal that you want to measure then the amplitude should be greater than the noise you see on the scope.
second: nyquist-shanon
third: the energy stoled in the measuring process should not affect the measures process
avram

--- On Wed, 4/22/09, GB wrote:
From: GB
Subject: Re: [msp430] ADC Noise coming from Timer?
To: m...
Date: Wednesday, April 22, 2009, 9:06 PM





avram and old cow,

There is nothing connected to the pin when I get this. I check for shorts on the circuit and it doesn't seem so (no short with any pins that are near).

--- On Wed, 4/22/09, avram ionut wrote:

From: avram ionut

Subject: Re: [msp430] ADC Noise coming from Timer?

To: msp430@yahoogroups. com

Date: Wednesday, April 22, 2009, 1:33 PM

?what do you have linked to that pin

?what is the freq of the filter you have there

avram

--- On Wed, 4/22/09, GB wrote:

From: GB

Subject: [msp430] ADC Noise coming from Timer?

To: msp430@yahoogroups. com

Date: Wednesday, April 22, 2009, 6:42 PM

Hello,





















I am using an MSP430F1611 to sample a sine wave at 8kHz with the signal fed to ADC input A0.However, when I check using an oscilloscope the A0 port I discover a sort of sawtooth wave (more like a sudden peak and then decaying over ad over again) oscillating at about 8kHz and other times at other rates, which is my timer's rate. Does anyone know of this? I've never had this happen and the fact that this noise has 825mV peak to peak is of course worrying. It can't be just plain noise picked up from the air since the voltage is too much.Is there something I'm missing that's causing the timer connected to the ADC (and triggering it) and results in this noise?I get ADC results whether I have the sine wave connected or disconnected.

Thank you very much

My code is:

#define SamplePrd 500

void main(void)

{

WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer



BCSCTL1 |= DIVA_3; // ACLK= LFXT1CLK/8

TI_SetDCO(TI_ DCO_4MHZ) ;



BCSCTL2 &= ~SELS; // SMCLK = DCO



// Setup IO

P6SEL |= 0x01; // P6.0 ADC option select

// Setup ADC12 module

ADC12CTL0 = ADC12ON; // Turn on ADC12, S&H in sample

// ADC12 Clock=ADC12OSC

ADC12CTL1 = SHS_3 + CONSEQ_2; // S&H src select: Timer_B.OUT1,

// rep. single channel

ADC12IFG = 0x00; // Clear ADC12 interrupt flag reg

ADC12IE |= 0x0001;

ADC12CTL0 |= ENC; // Enable conversion

// Timer_B.OUT1 triggers ADC12 conversion

// Setup Timer_B for recording

TBCTL = TBSSEL_2; // Use SMCLK as Timer_B source

TBR = 0;

TBCCR0 = SamplePrd; // Initialize TBCCR0

TBCCR1 = SamplePrd - 20; // Trigger for ADC12 SC

TBCCTL1 = OUTMOD_7; // Reset OUT1 on EQU1, set on EQU0



TBCTL |= MC0; // Start Timer_B in UP mode

// (counts up to TBCL0)



__bis_SR_register( LPM0_bits + GIE); // Enable interrupts, enter LPM0





}

//---------- --------- --------- --------- --------- --------- ---

// ADC ISR: record mode only, encode and store conversion result

#pragma vector=ADC_VECTOR

__interrupt void ISR_ADC(void)

{

result = ADC12MEM0; // Move results, IFG is cleared

}



























































that is simple to see: add a breakpoint to the first line of main (void) and see if it gets there that often.
or if you want something smart add a global noinit char guc_i that is incremented in the first line of main and watch his value from time to time. if it is not a constant then you have main running multiple times or a memory management problem but this is not the case now
avram

--- On Wed, 4/22/09, Augusto Einsfeldt wrote:
From: Augusto Einsfeldt
Subject: Re: [msp430] ADC Noise coming from Timer?
To: m...
Date: Wednesday, April 22, 2009, 9:21 PM







It seems like your MSP is reseting on every timer interrupt, then the P6 changes from ADC input to something else before you have it configured again.

Check stack overflow or other reasons to loose control.

-Augusto

On Qua 22/04/09 15:06 , GB gusgl2001@yahoo. com sent:

> avram and old cow,

> There is nothing connected to the pin when I get this. I check for

> shorts on the circuit and it doesn't seem so (no short with any pins

> that are near).

> --- On Wed, 4/22/09, avram ionut wrote:

> From: avram ionut

> Subject: Re: [msp430] ADC Noise coming from Timer?

> To: msp430@yahoogroups. com

> Date: Wednesday, April 22, 2009, 1:33 PM

> ?what do you have linked to that pin

> ?what is the freq of the filter you have there

> avram

> --- On Wed, 4/22/09, GB wrote:

> From: GB

> Subject: [msp430] ADC Noise coming from Timer?

> To: msp430@yahoogroups. com

> Date: Wednesday, April 22, 2009, 6:42 PM

> Hello,

> I am using an MSP430F1611 to sample a sine wave at 8kHz with the

> signal fed to ADC input A0.However, when I check using an

> oscilloscope the A0 port I discover a sort of sawtooth wave (more

> like a sudden peak and then decaying over ad over again) oscillating

> at about 8kHz and other times at other rates, which is my timer's

> rate. Does anyone know of this? I've never had this happen and the

> fact that this noise has 825mV peak to peak is of course worrying. It

> can't be just plain noise picked up from the air since the voltage is

> too much.Is there something I'm missing that's causing the timer

> connected to the ADC (and triggering it) and results in this noise?I

> get ADC results whether I have the sine wave connected or

> disconnected.

> Thank you very much

> My code is:

> #define SamplePrd 500

> void main(void)

> {

> WDTCTL = WDTPW + WDTHOLD; // Stop watchdog

> timer

>

> BCSCTL1 |= DIVA_3; // ACLK=

> LFXT1CLK/8

> TI_SetDCO(TI_ DCO_4MHZ) ;

>

> BCSCTL2 &= ~SELS; //

> SMCLK = DCO

>

> // Setup IO

> P6SEL |= 0x01; // P6.0

> ADC option select

> // Setup ADC12 module

> ADC12CTL0 = ADC12ON; // Turn on

> ADC12, S&H in sample

> //

> ADC12 Clock=ADC12OSC

> ADC12CTL1 = SHS_3 + CONSEQ_2; // S&H src

> select: Timer_B.OUT1,

> //

> rep. single channel

> ADC12IFG = 0x00; // Clear

> ADC12 interrupt flag reg

> ADC12IE |= 0x0001;

> ADC12CTL0 |= ENC; // Enable

> conversion

> // Timer_B.OUT1 triggers ADC12 conversion

> // Setup Timer_B for recording

> TBCTL = TBSSEL_2; // Use

> SMCLK as Timer_B source

> TBR = 0;

> TBCCR0 = SamplePrd; //

> Initialize TBCCR0

> TBCCR1 = SamplePrd - 20; // Trigger for

> ADC12 SC

> TBCCTL1 = OUTMOD_7; // Reset

> OUT1 on EQU1, set on EQU0

>

> TBCTL |= MC0; // Start

> Timer_B in UP mode

> //

> (counts up to TBCL0)

>

> __bis_SR_register( LPM0_bits + GIE); // Enable

> interrupts, enter LPM0

>

>

> }

> //---------- --------- --------- --------- --------- --------- ---

> // ADC ISR: record mode only, encode and store conversion result

> #pragma vector=ADC_VECTOR

> __interrupt void ISR_ADC(void)

> {

> result = ADC12MEM0; // Move

> results, IFG is cleared

> }

>

>

>

>

>