This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

ADC12_sampe_time???

Other Parts Discussed in Thread: MSP-TS430PN80USB, MSP430F5529

Hi to everyone,

I use MSP-TS430PN80USB with MSP430F5529 microcontrollers at the first time. I need adc input and to know the sampling time. I start to read the example from ti.com.

Use this code:

"

#include <msp430.h>

/*
* main.c
*/
int main(void) {

WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
ADC12CTL0 = ADC12SHT02 + ADC12ON; // Sampling time je 16 ADC12CLK cycles, ADC12 on je 4bit 16bitnog registra ADC12CTL0
ADC12CTL1 = ADC12SHP; // ADC12SHP This bit selects the source of the sampling signal, znaci da je 1 i to je pulse sample mode
ADC12IE = 0x01; // Enable interrupt, ukljucuje prekid
ADC12CTL0 |= ADC12ENC; //vazan bit koji mora biti 1 pre konverzije
P6SEL |= 0x01; // P6.0 ADC option select
P1DIR |= 0x03; // P1.0 and P1.1 output

while (1)
{
ADC12CTL0 |= ADC12SC; // Start sampling/conversion

__bis_SR_register(LPM0_bits + GIE); // LPM0, ADC12_ISR will force exit

}
}

#pragma vector = ADC12_VECTOR
__interrupt void ADC12_ISR(void)
{
if (ADC12MEM0 >= 0x947) // ADC12MEM = A0; 947 odabiraka odgovara naponu od 1.8V
P1OUT &= 0xfe; // P1.0 = 0
else
P1OUT |= 0x01; // P1.0 = 1

__bic_SR_register_on_exit(LPM0_bits); // Exit active CPU
}

"

...it give me the increments, and that is great.

But I have a problem to understand how much is sampling time???

---With this line of code 

ADC12CTL0 = ADC12SHT02 + ADC12ON;        

,I turn on this adc and define number of ADC12CLK cycles, on this case 16cycles, but how much is my ADC12CLK??????????? Which line of code select value of ADC12CLK?

 I use 4 Mhz crystal on board. Is this a work frequency of microcontroler?

---With this line of code

ADC12CTL1 = ADC12SHP;

I select the source of the sampling signal. Do I select the pulse sample mode??? In this mode period od SAMPCON depends of how I chose the ADC12SHT0x?

My sampe time is???


thanks,

Srdjan

  • All answers are found in the users guide and the device datasheet.

    Srdjan Stankovic said:
    ---With this line of code
    ADC12CTL1 = ADC12SHP;
    I select the source of the sampling signal. Do I select the pulse sample mode???

    With this line you set all bits in ADC12CTL1 to 0 except the SHP bit.


    From users guide:

    ADC12SHP
    RW default: 0h
    ADC12_A sample-and-hold pulse-mode select. This bit selects the source of the sampling signal (SAMPCON) to be either the output of the sampling timer or the sample-input signal directly.
    0b = SAMPCON signal is sourced from the sample-input signal.
    1b = SAMPCON signal is sourced from the sampling timer.

    So yes, you select the sampling soucre by setting BIT 10+11 to 0 (Whcih means samplign source is ADC12SC bit). YOu also set the start point of the conversion to the ADC12MEMCTL0 register. You set the clock divider to 1, select ADC12OSC (MODOSC) as clock (see the device datasheet for its frequency - that's why datasheets exist) and set single channel single conversion mode.

    Note that, e.g. ADC12SSEL_0 resolves to 0 and is as good as omitting it from the assignment. (Including it is a nice thing anyway, as it documents the intention)

    So
    ADC12CTL1 = ADC12SHP;
    is the same as
    ADC12CTL1 = ADC12SHP | ADC12CONSEQ_0 | ADC12SSEL_0 | ADC12DIV_0 | ADC12SHS_0 | ADC12CSTARTADD_0;

  • Hi Srdjan,

    Since you did not specify a ADC10CLK, it assumes the default option which you can find from the datasheet. On the register part you'll see something like "rw - (0)" under the boxes illustrated. That means read-write-default: 0. So you can find which clock option is selected, and its value from the datasheet again.

    Regards,

    Gunay

    Edit: Good timing (:

**Attention** This is a public forum