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.

MSP430G2332: Source Code of PMP9776 reference design (Power Bank).

Part Number: MSP430G2332
Other Parts Discussed in Thread: PMP9776

Hi,

 

 

Could I have a source code of PMP9776 reference design?

 

http://www.ti.com/tool/pmp9776

e2e.ti.com/.../your-complete-power_2d00_bank-solution


Thanks.

  • I have alerted the design engineer.  He is out of office, so it may be a while before he responds.

  • TPS61236_V3.c
    //Add CC function at high Temp compared to V2, the CC current to 1A with temperature higher than 30degree
    // the current limit is reset at MCU reset or phone diconnection
    
    #define ADC_3V 0x199                          // 3*(511/2511)/1.5*1023=0x1A0
    #define ADC_3_5V 0x1DD                          // 3.5*(511/2511)/1.5*1023=0x1E5
    #define ADC_3_7V 0x1F9                          // 3.7*(511/2511)/1.5*1023=0x201
    #define ADC_3_9V 0x214                          // 3.9*(511/2511)/1.5*1023=0x21D
    #define ADC_45_Deg 0x13B                             //  (0.38*0.47)/(0.47+1)*3*1023/1.5= 0xF8
    #define ADC_60_Deg 0x5B
    #define ADC_1_6A 0x1A6                                  // (38.7*1.6)/150*1023=0x1A6
    #define ADC_1_3A 0x157                                  // (38.7*1.3)/150*1023=0x157
    
    void ADC_Routin(void);
    void Delay(unsigned int);
    void LED_ON(void);
    
    unsigned int ADCValues[4];
    
    #include <msp430.h> 
    
    /*
     * main.c
     */
    int main(void) {
    
    	unsigned int STATE=0;
    
    	WDTCTL = WDTPW | WDTHOLD;	// Stop watchdog timer
    	
        /*operating frequency of MCU */
    
         DCOCTL = 0;                               // Select lowest DCOx and MODx settings
         BCSCTL1 = CALBC1_1MHZ;               // Set DCO
         DCOCTL = CALDCO_1MHZ;
         BCSCTL3 |= LFXT1S_2;                //12KHz Clock for TimerA
    
        /*P1.0~P1.3 as ADC function*/
        ADC10CTL1 = (INCH_3 + CONSEQ_1);            // A3/A2/A1/A0, single sequence
        ADC10AE0 |= 0x0F;                         // P1.3,2,1.0 ADC10 option select
        ADC10CTL0 = (SREF_1 + ADC10SHT_2 + MSC + ADC10ON); //1.5V Reference
        ADC10DTC1 = 0x04;                         // 4 conversions
    
    
    
        /*P1.7 as Input I/O for INACT*/
     //   P1IE |= BIT7;                             // P1.7 interrupt enabled
        P1IES |= BIT7;                            // P1.7 Hi/lo edge
        P1IFG &= ~BIT7;                           // P1.7 IFG cleared
    
        /*P1.5, P2.0~P2.2, P2.4~2.7 as digital output*/
    
        P1OUT &= ~BIT5;                       // P1.5 output Low
        P1DIR |= BIT5;        // Config  P1.5 as output pin
    
    
        P2SEL =0x00;
        P2OUT = 0x00;                       // P2.x low
        P2DIR |= 0xFF;        // Config  P2.x Output function
    	Delay(10);            //1s delay the ADC input need to stable
    
        while(1)
    
        {
        	switch (STATE)
        	{
        	case 0:
        		P2OUT = 0x00;                       // Turn off the boost converter
    		    P1OUT &= ~BIT5;	                  // All LED OFF
    			Delay(40);            //4s delay to reduce power consumption
    
        		ADC_Routin();
    
        	    if(ADCValues[3] >= ADC_3_5V && ADCValues[0] > ADC_60_Deg)          // the battery voltage higher than 3.5V, the power bank on. Temp lower than 45degree
        	    	{
    	    		STATE = 1;
        	    	LED_ON();
        	    	}
             break;
    
        	case 1:
        	   P2OUT |= BIT4|BIT7;                 //VCUR high, TPS2514 ON
    		   Delay(1);            //100ms Delay
        	   P2OUT |= BIT5;                 // boost converter on
        	   Delay(1);                                //100ms delay
       	       ADC_Routin();
    
        	   if (ADCValues[3] >= ADC_3V && ADCValues[2] > ADCValues[3] && ADCValues[0] > ADC_60_Deg) // VBAT higher than 3V and VOUT higher than VBAT
        	    	STATE = 2;
        	    else
        	    {
        	        STATE = 0;
        	    	P2OUT = 0x00;                       // Turn off the boost converter
        		    P1OUT &= ~BIT5;	                  // All LED OFF
        	    }
        	break;
    
        	case 2:
        		if ((P1IN & 0x80) ==0x80)                  //INACT is high logic, no mobile connection or small output current
        		{
        			Delay(20);                          //two second delay
        		    P1IFG &= ~BIT7;                           // P1.7 IFG cleared
        			Delay(10);                          //one second delay
        			if ((P1IN & 0x80) ==0x80)     //double check INACT in high logic
        			{
            			P2OUT &= 0xF8;
            			P2OUT |= BIT4;                     //VCUR=High
            		    P1OUT &= ~BIT5;	                  // All LED OFF
            		    P2OUT &= ~BIT7;                  // TPS2514 OFF
            		    Delay(1);
    
        			P1IE |= BIT7;                             // P1.7 interrupt enabled
        		    __bis_SR_register(LPM3_bits + GIE);       // Enter LPM3 w/interrupt
    
         		    P2OUT &= ~BIT5;                          // disable boost converter
        		    P2OUT |= BIT7;                           //TPS2514 ON,
    
        			Delay(4);                            //400ms delay to discharge the VOUT
    
        		    P2OUT |= BIT5;                                  // boost converter on
        			Delay(10);                          //one second delay for the device to normal operation
        			}
        		}
        		else
        		{
    
        			ADC_Routin();
    
        			if (ADCValues[3] >= ADC_3V && ADCValues[2] > ADCValues[3] && ADCValues[0] > ADC_60_Deg)
        			{
                        LED_ON();
    
                        if ((P2OUT&BIT4) != 0x00)           //if 	VCUR==L, the voltage compensation is disabled
                       {
                	      if (ADCValues[1] > ADC_1_6A)
        	    			 P2OUT |= BIT6;                                        //VCOM is high
    					  if (ADCValues[1] < ADC_1_3A)
        	    			 P2OUT &= ~BIT6;                                        //VCOM is Low
                       }
                        else
                        	 P2OUT &= ~BIT6;                                        //VCOM is Low
    
                      if (ADCValues[0] < ADC_45_Deg)
                      {
                    	  P2OUT &= ~BIT4;                           //VCUR =0, low current limit
                      }
        			}
        			else
        			{
            	        STATE = 0;
            	    	P2OUT = 0x00;                       // Turn off the boost converter
            		    P1OUT &= ~BIT5;	                  // All LED OFF
        			}
        		}
        	break;
        	  }                                                //end switch
        }                                                     //end while
    }                                                         //end main(void)
    
    // Port 1 interrupt service routine
    #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
    #pragma vector=PORT1_VECTOR
    __interrupt void Port_1(void)
    #elif defined(__GNUC__)
    void __attribute__ ((interrupt(PORT1_VECTOR))) Port_1 (void)
    #else
    #error Compiler not supported!
    #endif
    {
    	LPM3_EXIT;
    	P1IFG &= ~0x80;                           // P1.7 IFG cleared
        P1IE &= ~BIT7;                             // P1.7 interrupt disable
    	__bic_SR_register_on_exit(GIE);                               //disable GIE
    }
    
    #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
    #pragma vector=TIMER0_A0_VECTOR
    __interrupt void Timer_A (void)
    #elif defined(__GNUC__)
    void __attribute__ ((interrupt(TIMER0_A0_VECTOR))) Timer_A (void)
    #else
    #error Compiler not supported!
    #endif
    {
    	LPM3_EXIT;
    	CCTL0 &= ~BIT4; //Interrupt disable
    	__bic_SR_register_on_exit(GIE);                               //disable GIE
    	TACTL = 0x00;              //strop timer
    }
    
    void ADC_Routin(void)
    {
    	ADC10CTL0 |= BIT5;                      //ADC Reference ON
    	Delay(1);            //100m delay the ADC input need to stable
    
        ADC10SA = (unsigned int)ADCValues;                        // ADC Data buffer start Address
    
        ADC10CTL0 |= ENC + ADC10SC;             // Sampling and conversion start
    
       while ((ADC10CTL0 & BIT2) == 0);
    //  	Delay_100ms();                  // wait until ADC finish
    
        ADC10CTL0 &= ~BIT2;                     // Clear ADC finished flag
        ADC10CTL0 &= ~ENC;
        while (ADC10CTL1 & BUSY);               // Wait if ADC10 core is active
        ADC10CTL0 &= ~BIT5;                     //ADC Reference ON to reduce power loss
    }
    
    void LED_ON(void)
    {
    	if (ADCValues[3] >= ADC_3V && ADCValues[3] < ADC_3_5V)
    	{
    		P1OUT |= BIT5;            //D4 ON
    	    P2OUT &= ~BIT0;	          //D1 OFF
    	    P2OUT &= ~BIT1;	          //D2 OFF
    	    P2OUT &= ~BIT2;	          //D3 OFF
    
    	}
    
    
    	else if (ADCValues[3] >= ADC_3_5V && ADCValues[3] < ADC_3_7V)
        	  {
    		P1OUT |= BIT5;            //D4 ON
    	    P2OUT |= BIT0;	          //D1 ON
    	    P2OUT &= ~BIT1;	          //D2 OFF
    	    P2OUT &= ~BIT2;	          //D3 OFF
        	  }
    
    	else if (ADCValues[3] >= ADC_3_7V && ADCValues[3] < ADC_3_9V)
    	{
    		P1OUT |= BIT5;            //D4 ON
    	    P2OUT |= BIT0;	          //D1 ON
    	    P2OUT |= BIT1;	          //D2 ON
    	    P2OUT &= ~BIT2;	          //D3 OFF
    	    }
    
    	else if (ADCValues[3] >= ADC_3_9V)
         {
        	 P2OUT |= BIT0|BIT1|BIT2;                              // All LED ON
        	 P1OUT |= BIT5;
         }
    
    	else
    	{
    		P1OUT &= ~BIT5;            //D4 OFF
    	    P2OUT &= ~BIT0;	          //D1 OFF
    	    P2OUT &= ~BIT1;	          //D2 OFF
    	    P2OUT &= ~BIT2;	          //D3 OFF
    
    	}
    }
    
    
    void Delay(unsigned int i)
    {
    	unsigned int Number_Cout;
    
    	while(i>0)
    	 {
    		Number_Cout +=1200;
    		i--;
    	 }
    
    	CCTL0 = CCIE;                             // CCR0 interrupt enabled
    	  CCR0 = Number_Cout;                             //
    	  TACTL = TASSEL_1 + MC_1;                  // ACLK, upmode
    	  __bis_SR_register(LPM3_bits + GIE);       // Enter LPM3 w/ interrupt
    
    }
    
    
    
    refer to the attachment for code

  • I appreciate your help.

    Thanks.