Generate pulses

Discussions on how to get your MSP JTAG programmer up and running.

Moderator: phalanx

Post Reply
dushyant
Posts: 1
Joined: Mon Jul 18, 2016 12:35 am

Generate pulses

Post by dushyant » Mon Jul 18, 2016 12:46 am

Hello,
I am making the program in msp430g2553 launchpad. In this my input is from pin2.4. and my output will be three pulses from pin2.0, pin2.1, pin2.2. The code i am posting here in this the output i am getting is from pin2.0 high pulse, from pin2.1 low pulse and from pin2.2 high pulse.

I want all the three low pulses.
can anyone help me with this.

Code: Select all

#include <msp430g2553.h>
#define CPU_F ((double)16000000)
#define delay_us(x) __delay_cycles((long)(CPU_F*(double)x/1000000.0))
#define delay_ms(x) __delay_cycles((long)(CPU_F*(double)x/1000.0))

int i;
char C_1, C_2;
void System_Clock_Init( void )
{
    char i;
    _NOP();
    WDTCTL = WDTPW + WDTHOLD;                                         // Close Watching dog
    delay_ms(20);                                                     // 1MHz
    if( ( CALBC1_16MHZ == 0xff ) || ( CALDCO_16MHZ == 0xff ) )        // FLASH A was cleared!!!
        ((void (*)())RESET_VECTOR)();
    BCSCTL1 = CALBC1_16MHZ; //ACLK=32768Hz
    DCOCTL = CALDCO_16MHZ;  //MCLK=DCOCLK=16MHz
    BCSCTL2 = 0x06;//SMCLK=DCOCLK/8=2MHz
    BCSCTL3 = 0x00;//cap=1pF
    IE1 &= ~OFIE;//close crystal error interrupt

    TA0CCR0 =32-1; // PWM Period --> needs to be adjustable
    TA0CCTL1 = OUTMOD_2; // CCR1 reset/set
    TA0CCR1 = CCR0/2; // CCR1 PWM duty cycle 50% -->needs to be adjustable
    TACTL = TASSEL_1 + MC_1; // SMCLK, up mode

    do
    {
        IFG1 &= ~OFIFG;      
        for( i = 0; i < 100; i++ )
        {
            _NOP();
        }
    }
    while (IFG1 & OFIFG);     

    _NOP();
}

void IO_INIT(void)
{
	    P2SEL &= ~BIT4;
	    P2SEL2 &= ~BIT4;
	    P2REN &= ~BIT4;
	    P2DIR &= ~BIT4;
	    P2DIR |= BIT2;
	    P2IES |= BIT4;
	    P2IE  |= BIT4;
	    P2IFG  &= ~BIT4;

	    P2SEL &= ~(BIT0+BIT1);
	    P2SEL2 &= ~(BIT0+BIT1);
	    P2REN &= ~(BIT0+BIT1);
	    P2DIR &= ~(BIT0+BIT1);
	    P2DIR |= (BIT0+BIT1);
	    P2OUT &= ~(BIT0+BIT1);

	    P2SEL &= ~BIT2;
	    P2SEL2 &= ~BIT2;
	    P2REN &= ~BIT2;
	    P2DIR &= ~BIT1;
	    P2DIR |= BIT1;
	    P2OUT &= ~BIT2;
}

void main(void)//29uA
{
    System_Clock_Init();
    _NOP();
    //WDTCTL = WDT_ARST_1000;//feed watch dog  ?????下面的程序执行时间???
    _NOP();
    IO_INIT();
    _NOP();
    _EINT();//open all interrupt
    _NOP();
    LPM3;
    _NOP();
    while(1);
}
//------------------------------------------------------------------------------
//Function: Start Timer 0 A0 for Hour Timing 500ms
//------------------------------------------------------------------------------
#pragma vector = PORT2_VECTOR
#pragma vector = TIMER0_A1_VECTOR
__attribute__((__interrupt__(TIMER0_A0_VECTOR)))
void Timer0_A(void)
{
  _NOP();
  delay_us(20);

  if( C_1 == 0xff)
  {
    if(!( P2IN & BIT4 )) C_2 = 0xff;
  }
  else
  {
      if(!( P2IN & BIT4 )) C_1 = 0xff;
  }
  if(( C_1 == 0xff) && ( C_2 == 0xff))
  {
    //output A B D
    P2OUT |= BIT1;
    P2OUT |= BIT0;
    delay_ms(2);
    P2OUT |= BIT2;
    P2OUT &= ~BIT0;
    delay_ms(2);
    P2OUT |= BIT2;
    P2OUT &= ~BIT1;
    //delay_ms(2);
    P2OUT &= ~BIT2;
    P2OUT &= ~BIT1;
    delay_ms(2);

    C_1 =0x00;
    C_2 =0x00;
  }
  _NOP();
}

Post Reply