8 years, 9 months ago.

Question regarding HBridge current feedback

Hi Eli,

I am trying to modify ADC code to also read HBridge IFB and IFA signals, but so far without luck.

I am using ADC channel 7 mux A for H bridge A, and channel 3 mux A for H bridge B. I believe this is internally connected to pins PTE23 and PTE22 by default.

I then modified the IRQ handler function state machine to add two new states :

extern "C" void ADC0_IRQHandler()
{
    uint8_t Junk;

    switch(CurrentADC_State) {
        default:
            Junk =  ADC0->R[0];
            break;

        case ADC_STATE_CAPTURE_POT_0:

            PotADC_Value[0] = ADC0->R[0];
            ADC0->CFG2  &= ~ADC_CFG2_MUXSEL_MASK; //Select the A side of the mux
            ADC0->SC1[0]  =  TFC_POT_1_ADC_CHANNEL | ADC_SC1_AIEN_MASK;
            CurrentADC_State = ADC_STATE_CAPTURE_POT_1;

            break;

        case ADC_STATE_CAPTURE_POT_1:

            PotADC_Value[1] = ADC0->R[0];
            
       /* Changed instructions here to prepare for HBridge capture */
            CurrentADC_State = ADC_STATE_CAPTURE_I_HBRIDGE_A; 
            ADC0->SC1[0]  =  TFC_I_HBRIDGE_0_SENSE_ADC_CHANNEL | ADC_SC1_AIEN_MASK; // HBRIDGE channel
            ADC0->CFG2  &= ~ADC_CFG2_MUXSEL_MASK; //Select the A side of the mux
            break;
            
            
        /*     NEW STATES  */
        case ADC_STATE_CAPTURE_I_HBRIDGE_A:
            HBridge_0_current_value = ADC0->R[0];
            ADC0->SC1[0]  =  TFC_I_HBRIDGE_1_SENSE_ADC_CHANNEL | ADC_SC1_AIEN_MASK;
            CurrentADC_State = ADC_STATE_CAPTURE_I_HBRIDGE_B;
            break;
            
        case ADC_STATE_CAPTURE_I_HBRIDGE_B:
            HBridge_1_current_value = ADC0->R[0];            
            ADC0->CFG2  |= ADC_CFG2_MUXSEL_MASK; //Select the B side of the mux
            ADC0->SC1[0]  =  TFC_BAT_SENSE_CHANNEL| ADC_SC1_AIEN_MASK;
            CurrentADC_State = ADC_STATE_CAPTURE_BATTERY_LEVEL;
            break;

/* Back to the classic code */
        case ADC_STATE_CAPTURE_BATTERY_LEVEL:

            BatSenseADC_Value = ADC0->R[0];

            //Now we will start the sequence for the Linescan camera

            TAOS_CLK_HIGH;

            for(Junk = 0; Junk<50; Junk++) {
            }

            TAOS_SI_LOW;


            CurrentLineScanPixel = 0;
            CurrentLineScanChannel = 0;
            CurrentADC_State = ADC_STATE_CAPTURE_LINE_SCAN;
            ADC0->CFG2  |= ADC_CFG2_MUXSEL_MASK; //Select the B side of the mux
            ADC0->SC1[0] =  TFC_LINESCAN0_ADC_CHANNEL | ADC_SC1_AIEN_MASK;

            break;

        case ADC_STATE_CAPTURE_LINE_SCAN:

            if(CurrentLineScanPixel<128) {
                if(CurrentLineScanChannel == 0) {
                    LineScanImage0WorkingBuffer[CurrentLineScanPixel] = ADC0->R[0];
                    ADC0->SC1[0]  =  TFC_LINESCAN1_ADC_CHANNEL | ADC_SC1_AIEN_MASK;
                    CurrentLineScanChannel = 1;

                } else {
                    LineScanImage1WorkingBuffer[CurrentLineScanPixel] = ADC0->R[0];
                    ADC0->SC1[0]  =  TFC_LINESCAN0_ADC_CHANNEL | ADC_SC1_AIEN_MASK;
                    CurrentLineScanChannel = 0;
                    CurrentLineScanPixel++;

                    TAOS_CLK_LOW;
                    for(Junk = 0; Junk<50; Junk++) {
                    }
                    TAOS_CLK_HIGH;

                }

            } else {
                // done with the capture sequence.  we can wait for the PIT0 IRQ to restart

                TAOS_CLK_HIGH;

                for(Junk = 0; Junk<50; Junk++) {
                }

                TAOS_CLK_LOW;
                CurrentADC_State = ADC_STATE_INIT;
                
                //swap the buffer

                if(LineScanWorkingBuffer == 0) {
                    LineScanWorkingBuffer = 1;

                    LineScanImage0WorkingBuffer = &LineScanImage0Buffer[1][0];
                    LineScanImage1WorkingBuffer = &LineScanImage1Buffer[1][0];

                    TFC_LineScanImage0 = &LineScanImage0Buffer[0][0];
                    TFC_LineScanImage1 = &LineScanImage1Buffer[0][0];
                } else {
                    LineScanWorkingBuffer = 0;
                    LineScanImage0WorkingBuffer = &LineScanImage0Buffer[0][0];
                    LineScanImage1WorkingBuffer = &LineScanImage1Buffer[0][0];

                    TFC_LineScanImage0  = &LineScanImage0Buffer[1][0];
                    TFC_LineScanImage1  = &LineScanImage1Buffer[1][0];
                }

                TFC_LineScanImageReady++;
            }

            break;
    }

}

I have checked the code several times, but now it seems I have broken the battery measurement as well.

I was only able to check HBridge measure for bridge B, because motor A wasn't spinning. I just saw that this is a firmware 2.0 issue, so at least I'll be able to fix that tommorow.

At first sight do you see something wrong with my code ? The only doubt I have is whether I should activate something on the GPIO. I am rather confused at the GPIO code and product documentation that I find rather hard to grasp on this specific point.

Thanks for your help

Question relating to:

Official library for the FRDM-TFC shield Cup, Freescale

Ok, I found the issue, I needed to switch line 13 and 14, otherwise it seems the measurement was triggered while I switched the mux. Problem solved

posted by Remi Beges 22 Feb 2016
Be the first to answer this question.