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.

problem with TMS320F28234 adc

I try to get an board identification by reading the voltage of an resistor network with the internal ADC of the controller.

At some boards I get a wrong value for the voltage but I can measure the good voltage with my multimeter.

So I think there is an software problem.

I use this function :

// ---------------------------------------------------------------------------------------------------
// init of ADC's
// ---------------------------------------------------------------------------------------------------
void adcInit(void) {
    // Setup ADCTRL1     x000 0000  0011 xxxx b --> 0x0030
                                            // Bit 15        =    0 --> reserved
    AdcRegs.ADCTRL1.all = 0x0030;            // Bit 14        =    0 --> no reset adc
                                            // Bit 13 - 12    =   00 --> no stop in emulation mode

                                            // Bit 11 -  8    = 0000 --> acquisition window size
                                            //                           = (zzzz + 1) x ADCCLK
                                            // Bit  7        =     0 --> adcclk : 1
                                            // Bit  6        =     0 --> disable continuous run
                                            //                       --> d.h. start/stop Mode
                                            // Bit  5        =     1 --> enable Sequencer override feature
                                            // Bit  4        =     1 --> Cascaded mode

                                            // Bit  3 -  0    = 0000 --> reserved


    // Setup ADCTRL2    010x 00x0  0100 0000 b --> 0x4040
    AdcRegs.ADCTRL2.all = 0x4040;            // Bit 15        =    0 --> no SOCB for cascaded seq
                                            // Bit 14        =    1 --> reset sequencer-1
                                            // Bit 13        =    0 --> no SOC for sequencer-1
                                            // Bit 12        =    0 --> reserved

                                            // Bit 11        =    0 --> no INT_ENA_SEQ1
                                            // Bit 10        =    0 --> INT_MOD_SEQ1
                                            // Bit  9        =    0 --> reserved
                                            // Bit  8        =    0 --> no SOCA for sequencer-1

                                            // Bit  7        =    0 --> no EXT_SOC for sequencer-1
                                            // Bit  6        =    1 --> reset sequencer-2
                                            // Bit  5        =    0 --> no SOC for sequencer-2
                                            // Bit  4        =    0 --> reserved

                                            // Bit  3        =    0 --> no INT_ENA_SEQ2
                                            // Bit  2        =    0 --> INT_MOD_SEQ2
                                            // Bit  1        =    0 --> reserved
                                            // Bit  0        =    0 --> no SOCB for sequencer-2
                                            // stop conversion

    // Setup ADCTRL3    xxxx xxxx  1110 0110 b --> 0x00E6 --> 12.5   MHz
    // Setup ADCTRL3    xxxx xxxx  1110 1000 b --> 0x00E8 -->  6.75  MHz
    // Setup ADCTRL3    xxxx xxxx  1110 1010 b --> 0x00EA -->  3.125 MHz
    AdcRegs.ADCTRL3.all = 0x00E6;            // Power up bandgap/reference/ADC circuits
                                            // Bit 7-6 --> bandgap on
                                            // Bit   5 --> analog on
                                            // Bit 4-1 --> clk div = 6 --> 12.5 MHz
                                            // high-speed peripheri-clk ist bei diesem
                                            // Beispiel auf 75 MHz eingestellt
                                            // Bit 0   --> sequential sampling mode

    // Setup ADCMAXCONV        xxxx xxxx  x000 1111 b --> 0x000F
    AdcRegs.ADCMAXCONV.all = 0x000F;        // convert and store in 16 results registers

    // Setup ADCASEQSR    wird nicht ben"otigt, liefert nur den Status
    // AdcRegs.ADCASEQSR.all = 0x0000;

    // Setup ADCST    wird nicht ben"otigt, liefert nur den Status
    // bzw dient dem L"oschen von Interrupt-flags
    // AdcRegs.ADCST.all = 0x0000;

    // Setup ADCREFSEL
    AdcRegs.ADCREFSEL.bit.REF_SEL = 1;            // externe Vref mit 2.048 V

    // Setup ADCREFSEL    01yy yyyy  yyyy yyyy b --> 0x4000
    // AdcRegs.ADCREFSEL.all = 0x4000 ;            // externe Vref mit 2.048 V
    // zerst"ort ggf. Calibrierwerte

    // Setup ADCOFFTRIM    xxxx xxxx  yyyy yyyy b --> 0x????
    // AdcRegs.ADCOFFTRIM.all = 0x0000 ;        // wird durch adc_cal eingestellt

    // AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x0;    // Beispiel f"ur das einstellen der einzelnen Kan"ale

    AdcRegs.ADCCHSELSEQ1.all = 0x0000;            // Initialize all ADC channel selects to A0
    AdcRegs.ADCCHSELSEQ2.all = 0x0000;
    AdcRegs.ADCCHSELSEQ3.all = 0x0000;
    AdcRegs.ADCCHSELSEQ4.all = 0x0000;
}

Read function :

// ---------------------------------------------------------------------------------------------------
// mehrfaches lesen eines einzelnen ADC Kanals mit Mittelwertbildung
// ---------------------------------------------------------------------------------------------------
uint16_t adcReadMultiChannel(uint16_t kanal, uint16_t mittelwert) {
    WRITE_TRACE("adcReadMultiChannel", TRACE_MSG, 0, 0, 0);
    uint16_t adc_ergebnis = 0;
    uint16_t adc_schleife = 0;

    kanal         &= 0x000F;                        // stellenbegrenzung
    mittelwert     &= 0x000F;                        // begrenzt den wert

    adc_ergebnis   = kanal;                        // 3. Kanal
    adc_ergebnis <<= 4;
    adc_ergebnis  += kanal;                        // 2. Kanal
    adc_ergebnis <<= 4;
    adc_ergebnis  += kanal;                        // 1. Kanal
    adc_ergebnis <<= 4;
    adc_ergebnis  += kanal;                        // 0. Kanal

    AdcRegs.ADCCHSELSEQ1.all = adc_ergebnis;    // Initialize all ADC channel selects to kanal
    AdcRegs.ADCCHSELSEQ2.all = adc_ergebnis;
    AdcRegs.ADCCHSELSEQ3.all = adc_ergebnis;
    AdcRegs.ADCCHSELSEQ4.all = adc_ergebnis;

    AdcRegs.ADCMAXCONV.all = mittelwert;        // anzahl der messungen zur mittelwertbildung
                                                // 0x0 -->  1 Wandlung
                                                // 0xF --> 16 Wandlungen

    AdcRegs.ADCTRL2.bit.SOC_SEQ1 = 1;            // start of new conversion

    while (AdcRegs.ADCST.bit.INT_SEQ1 == 0)    {;}    // end of conversion

    adc_schleife  = mittelwert;
    adc_schleife += 1;                            // 0xF --> 16 Wandlungen

    adc_ergebnis = 0;                            // r"ucksetzen des Messwertes
    while (adc_schleife) {
        adc_ergebnis += (*((volatile int16_t far *) (0x00000AFF + adc_schleife)));
        adc_schleife--;
    }
    mittelwert += 1;                            // 0xF --> 16 Wandlungen
    adc_ergebnis /= mittelwert;
    adc_ergebnis &= 0x0FFF;                        // vorsichtsmassnahme eigentlich unn"otig
    return adc_ergebnis;
}

Is there any error at this fubctions ?

with best regards

 

Peter Schneider

Electronic Engineering

Stanley Engineered Fastening

Tucker GmbH

Max-Eyth-Str. 1, 35394 Giessen, Germany

office: +49.(0)641.405.428 | fax: +49.(0)641.405.724

www.emhart.eu

 

 

 

Amtsgericht Gießen, HRB 1775
Geschäftsführer: Mike A. Tyll, Manfred Müller, Martin Kreimer