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.

MSP430F5172: GPIO pin configuration

Part Number: MSP430F5172

Hello, 

I am trying to control battery state control switches using GPIO pins. I used the same port but a different pin for setting PWM channels. However, my understanding is that these pins should not interfere with each other. However, even though my battery switch control output should be 1, it randomly goes to zero and turns back on. The pwm output also goes to low and high and sometimes this overlaps with the battery switch signal. Is there something wrong with the way I am configuring the pins? The code is supposed to sense the input voltage sensor value, trigger and ADC interrupt and enable or disable the battery switch. Thank you in advance. 

code is below

initial code

/*
P1SEL |= BIT7; // Set P1.7 to output direction - High BUCK
P1DIR |= BIT7;

P2SEL |= BIT0; // Set P2.0 to output direction - Low BUCK
P2DIR |= BIT0;

P2SEL |= BIT2; // Set P2.2 to output direction - High BOOST
P2DIR |= BIT2;

P2SEL |= BIT3; // Set P2.3 to output direction - Low BOOST
P2DIR |= BIT3;
*/

// configure ADC pins
PMAPPWD = 0x02D52; // Enable Write-access to modify port mapping registers
PMAPCTL = PMAPRECFG; // Allow reconfiguration during runtime
P1MAP0|= PM_ANALOG; // Modify all PxMAPy registers - A0 - Iin
P1MAP1|= PM_ANALOG; // Modify all PxMAPy registers - A1 - Vout_buck
P1MAP2|= PM_ANALOG; // Modify all PxMAPy registers - A2 - Vout
P1MAP3|= PM_ANALOG; // Modify all PxMAPy registers - A3
P1MAP4|= PM_ANALOG; // Modify all PxMAPy registers - A4 - Vbat
P1MAP5|= PM_ANALOG; // Modify all PxMAPy registers - A5 - Iout
P3MAP5|= PM_ANALOG; // Modify all PxMAPy registers - A8 - Ibat
P3MAP6|= PM_ANALOG; // Modify all PxMAPy registers - A7 - Vin
P2MAP2|= PM_TD1_1;
P2MAP3|= PM_TD1_2;
P2MAP0|= PM_TD0_2;
P1MAP7|= PM_TD0_1;

P1SEL |=BIT7+BIT5+BIT4+BIT3+BIT2+BIT1+BIT0; // setting the port mapping register PxMAPy to PM_ANALOG together with PxSEL.y=1 when applying analog signals
P3SEL |=BIT6+BIT5;

P2SEL |= BIT0+BIT2+BIT3;
P2DIR |= BIT0+BIT2+BIT3;
P1DIR |= BIT7;

P3SEL &= (~BIT0); // Set P3.0 to GPIO and to output direction - BAT_GD_EN
P3DIR |= BIT0;

P2SEL &= (~BIT6); // Set P2.6 as GPIO and to output direction - Vgate BAT
P2DIR |= BIT6;

PMAPPWD = 0; // Disable Write-Access to modify port mapping registers by writing incorrect key

// main code

while (1)
{
SetADC(7);
GetADC(7);
}

// ADC10 interrupt service routine
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR(void)

{
switch(__even_in_range(ADC10IV,12))
{
case 0: break; // No interrupt
case 2: break; // conversion result overflow
case 4: break; // conversion time overflow
case 6: break; // ADC10HI
case 8: break; // ADC10LO
case 10: break; // ADC10IN
case 12:
ADC10CTL0 &= ~ADC10ON; // ADC10 disabled completely
ADC_Result= ADC10MEM0;

Vin_temp=ADC_Result;

if (Vin_temp>=Vin_min){
OffBattery();
SetDuty_Buck (D_buckH, D_buckL);
__delay_cycles(10); // Delay between sequence convs

}

else if(Vin_temp<Vin_min & Vin_temp>=Vin_minABS){
// turn off buck stage
OffBuck(0,0);
__delay_cycles(100); // Delay between sequence convs
OnBattery();
__delay_cycles(50); // Delay between sequence convs
// turn on the boost stage
SetDuty_Boost(D_boostH, D_boostL);

}

else if (Vin_temp<Vin_minABS)
{
OffBattery();
OffBuck(0,0);
OffBoost(0,0);
}

__bic_SR_register_on_exit(CPUOFF);
break; // Clear CPUOFF bit from 0(SR)
default: break;
}
}

void OnBattery(){

P3OUT |= BIT0; //set 3.0 to high - enable battery GD
P2OUT |= BIT6; //set 2.6 to high
}

void OffBattery(){
P3OUT &= ~BIT0; //set 3.0 to low - disable battery GD
P2OUT &= ~BIT6; //set 2.6 to low - disable battery FETs
}

  •   

    Here is the image of the signals, the light blue is the battery switch control signal which should have stayed on throughout and the pink is the gate signal for one of the power stages. The dark blue is the input voltage and since it is within the desired threshold, it should the battery FET should have remained on. 

  • Hello Firehiwot,

    It looks like there is only one place in your code where the battery switch control is turned off:

    if (Vin_temp>=Vin_min){
    OffBattery();

    So this tells me some of your ADC readings satisfy this logic ( Vin_temp is >= Vin_min ) and turn off the battery.  If this is the case, you might want to double check your ADC values for potential random noise .

  • Hi Dennis, 

    thank you for the response. I actually have two cases setting the battery switches off and yes, commenting out those lines of code removes the random changes in the battery voltage.

    When checking the ADC values in debug mode, I see that they are within expected range so not sure how I can debug this. Do you have any recommendations? Also just commenting out the SetDuty_Boost(D_boostH, D_boostL) line of code in second condition (which is the condition I am testing) ensures steady output of the battery switch control signal. Is there any reason why you think this could be happening ( this is the reason why I thought I may have problem with the way I configured the GPIO pins). 

    Thank you, 

  • I guess I could use the LED to detect if it's going to those lines of code, but still not sure why commenting out the duty cycle function affects the battery control signal. Here is the code for setting duty cycle for your reference. 

    void SetDuty_Boost(unsigned int dboostH, unsigned int dboostL){
    //TD1CTL1 |= TDCLR; // reset timer for TD1
    TD1CCTL1 |= OUTMOD_2 + CLLD_2; // TD1CCR1,toggle reSet
    TD1CCR1 = dboostH; // TD1.1 boost high side
    TD1CCTL2 |= OUTMOD_6 + CLLD_2; // TD1CCR2, toggle set
    TD1CCR2 = dboostL; // TD1.2 boost low side
    TD1CTL0 |= MC_3 + TDCLR; //up/down mode, clear TDR
    }

  • Hi Firehiwot,

    Not sure why commenting out the duty cycle function would affect the battery control signals.

    Try to isolate the problem.  Reduce the code by removing the ADC portion.  Maybe setup a loop that calls your SetDuty_Boost() function and look to see if the P2.6 and P3.0 are affected in anyway.

**Attention** This is a public forum