Jump to content

dushyant

Members
  • Content Count

    5
  • Joined

  • Last visited

  1. dushyant

    generate pulse with the help of timer

    main thing is i want to generate the pulse after 200 input pulses. but i am not getting it. help me please. the warning i fixed it but then also i am not getting the desired result. help me!!
  2. dushyant

    generate pulse with the help of timer

    yup i am getting the warnings So, basically i have to generate the output pulse on the pin2.0, pin2.1 and pin 2.2 of the msp430g2553 launchpad. pin1.0 is the input So, at first when i touch the input pin1.0 with the oscilloscope probe; my output won't generate. but after 200 input pulses my output will generate on the pins 2.0/2.1/2.2 it means after passing of 200 input pulses, the output will generate. the above code i pasted here is giving me the input and output both. but the pulses i am getting is the train of pulses and i want just only oune pulse.
  3. dushyant

    generate pulse with the help of timer

    I tried but couldn't find the solution. i am not getting the output as i want. After 200 counts the output will be one pulse not the train of pulse. i checked everything how to get one pulse output, but no success. can you help me how to have the output one not train?
  4. Hello, I have made the program in which i used timer to generate the pulse. but now i don't want to use timer instead i want to use counter. I have to generate the output pulse when my input counter is more than 200. if it is less than 200, don't want to generate the pulse. I am pasting here my code, help me to generate the output pulse when input pulse is more than 200 input is in pin1.0 and output is from pin 2.0, pin 2.1, pin 2.2. I am using msp430g2553 launchpad #include "msp430G2553.h" #include "stdint.h" volatile uint16_t down_counter; // Variable for counting down volatile uint8_t output_control = 0; // Variable controls output activity volatile uint8_t input_state = 0; // Variable holds actual input state volatile uint8_t counter = 0; void main( void ) { WDTCTL = (WDTPW | WDTHOLD); // Stop watchdog timer #if defined(CALBC1_16MHZ_) && F_CPU >= 16000000L BCSCTL1 = CALBC1_16MHZ; // Set range DCOCTL = CALDCO_16MHZ; // Set DCO step and modulation #endif P2REN |= BIT4; // Enable resistor for P2.4 P2OUT |= (BIT0 | BIT1 | BIT2 | BIT4); // P2.0/1/2 high, pull-up resistor for P2.4 P2DIR |= (BIT0 | BIT1 | BIT2); // P2.0/1/2 to output direction P2IES |= BIT4; // Interrupt on high->low transition P2IFG &= ~BIT4; // Clear P2.4 IFG P2IE |= BIT4; // Enable interrupts for P2.4 TA0CCR0 = 2000; // Timer value for 2ms interrupt TA0CCTL0 = CCIE; // Enable compare interrupt TA0CTL = (TASSEL_2 | ID_0 | MC_2 | TACLR); // SMCLK, divider 1, continuous mode, clear // Input emulation P1OUT |= BIT0; // P1.0 high P1DIR |= BIT0; // P1.0 output - emulates output of sensor TA1CCR0 = 62500; // Timer value for 500ms interrupt 62500 TA1CCTL0 = CCIE; // Enable compare interrupt TA1CTL = (TASSEL_2 | ID_3 | MC_2 | TACLR); // SMCLK, divider 8, continuous mode, clear // Input emulation __bis_SR_register( GIE ); // Enable global interrupts while( 1 ) // Main program { } } // Input emulation // Timer 1 A0 interrupt service routine #pragma vector = TIMER1_A0_VECTOR __interrupt void Timer1_A0_ISR( void ) { static uint8_t timer_state = 0; // Variable holds actual timer state static uint8_t multiplier = 0; // Variable to extend timer interval TA1CCR0 += 2000; // Timer value for next interrupt in 2ms switch( timer_state ) // Determine actual timer state { case 0: // Delay between pulses { if( ++multiplier < 2 ) // Not 1s elapsed yet { TA1CCR0 += 62500; // Add 500ms 62500 } else // 1s elapsed { TA1CCR0 += 12500; // Add 100ms 12500 P1OUT &= ~BIT0; // P1.0 low multiplier = 0; // Reset multiplier timer_state++; // Increment timer state } break; } case 1: // Signal was low for 100ms { TA1CCR0 += 50000; // Add 400ms 50000 P1OUT |= BIT0; // P1.0 high timer_state++; // Increment timer state break; } case 2: // Signal was high for 400ms { TA1CCR0 += 12500; // Add 100ms 12500 P1OUT &= ~BIT0; // P1.0 low timer_state++; // Increment timer state break; } case 3: // Signal was low for 100ms { TA1CCR0 += 62500; // Add 500ms 62500 P1OUT |= BIT0; // P1.0 high timer_state = 0; // Reset timer state break; } } } // Input emulation // Timer 0 A0 interrupt service routine #pragma vector = TIMER0_A0_VECTOR __interrupt void Timer0_A0_ISR( void ) { static uint8_t state = 0; // Variable holds actual output state // TA0CCR0 += 2000; // Timer value for next interrupt in 2ms if(counter>200) { output_control = 1; } else { output_control = 0; } if( output_control = 1 ) // Test if down counter became 0 now { input_state = 0; // Reset input state P2IE &= ~BIT4; // Disable interrupts for P2.4 P2IES |= BIT4; // Interrupt on high->low transition P2IFG &= ~BIT4; // Clear P2.4 IFG P2IE |= BIT4; // Enable interrupts for P2.4 } if( output_control == 1 ) // Test if output is active { switch( state ) { case 0: // State 0 { P2OUT |= BIT2; // Set P2.2 high P2OUT &= ~BIT0; break; } case 1: // State 1 { P2OUT |= BIT0; // Set P2.0 high P2OUT &= ~BIT1; // Set P2.1 low break; } case 2: // State 2 { P2OUT |= BIT1; // Set P2.1 high P2OUT &= ~BIT2; // Set P2.2 low break; } } if( ++state >= 3 ) // Increment state and test if >= 3 { state = 0; // Reset state to 0 } else (output_control == 0); { } } } // Port 2 interrupt service routine #pragma vector = PORT2_VECTOR __interrupt void Port2_ISR( void ) { switch( input_state ) // Determine actual input state { case 0: // State 0: High->low transition of first pulse { down_counter = 60; // Timeout of 120ms 60 input_state++; // Increment input state P2IES &= ~BIT4; // Interrupt on low->high transition break; } case 1: // State 1: Low->high transition of first pulse { down_counter = 225; // Timeout of 450ms 225 input_state++; // Increment input state P2IES |= BIT4; // Interrupt on high->low transition break; } case 2: // State 2: High->low transition of second pulse { down_counter = 60; // Timeout of 120ms 60 input_state++; // Increment input state P2IES &= ~BIT4; // Interrupt on low->high transition break; } case 3: // State 3: Low->high transition of second pulse { P2IES |= BIT4; // Interrupt on high->low transition output_control = 1; // Activate output P2IE &= ~BIT4; // Disable interrupts for P2.4 input_state = 0; // Reset input state break; } } P2IFG &= ~BIT4; // Clear P2.4 IFG }
  5. dushyant

    msp430g2553 launchpad programming

    Hello, I am making my program using msp430g2553 launch pad. In this i have taken input from P2.4 and i want my output from P2.0, P2.1 and P2.2. In this program i have to generate the pulse of 500ms from input. and my output will be three low pulses from the three pins. Meaning whenever i connect my oscilloscope probe to 2.4 i can see the pulse. But the program i made it didn't work. when i connect to the oscilloscope it is showing nothing. when my input pulse is high i will get the three low pulses output. here is my code, please check it and tell me what is wrong in the code? since it doesn't contains any error. code: #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)) char C_1, C_2; void System_Clock_Init( void ) { char i; _NOP(); WDTCTL = WDTPW + WDTHOLD; // Close Watching dog delay_ms(50); / / 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 do { IFG1 &= ~OFIFG; for( i = 0; i < 100; i++ ) { _NOP(); } } while (IFG1 & OFIFG); _NOP(); } void IO_INIT(void) { NOP(); P2SEL &= ~BIT4; P2SEL2 &= ~BIT4; P2REN &= ~BIT4; /*P2DIR |= BIT2;*/ P2IES |= BIT4; P2IE |= BIT4; P2IFG &= ~BIT4; P2SEL &= ~(BIT0+BIT1); P2SEL2 &= ~(BIT0+BIT1); P2REN &= ~(BIT0+BIT1); //P2DIR &= ~(BIT0+BIT1); P2OUT &= ~(BIT0+BIT1); P2SEL &= ~BIT2; P2SEL2 &= ~BIT2; P2REN &= ~BIT2; //P3DIR &= ~BIT1; P2OUT &= ~BIT2; } void main(void) { System_Clock_Init(); _NOP(); //WDTCTL = WDT_ARST_1000; _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 __interrupt void PORT_C_Interrupt(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 |= BIT0; delay_ms(2); P2OUT |= BIT1; P2OUT &= ~BIT0; delay_ms(2); P2OUT |= BIT2; P2OUT &= ~BIT1; delay_ms(2); P2OUT &= ~BIT2; delay_ms(2); P2OUT ^= BIT1; //P2 toggle P2IFG &= ~BIT1; //IFG cleared? C_1 =0x00; C_2 =0x00; } _NOP(); }
×