Jump to content

sagarika36

Members
  • Content Count

    9
  • Joined

  • Last visited

  1. can u plz send me the code for two ultrasonic sensors....... i tried the same for one hcsr04 its working... but with two hcsr04 its not working properly.... plz help
  2. hi... this code is working perfectly wid 1 sensor.... but when m trying to use more den one sensors... it is considering all the conditions ... how to use it... please help#include "msp430.h" #include "stdint.h" //GPIO Pins #define trigger_pin1 BIT1 #define echo_input_pin1 BIT3 #define led1 BIT0 #define trigger_pin2 BIT3 #define echo_input_pin2 BIT4 #define led2 BIT1 //Ultrasound parameters #define timer_period1 62500 // 4 * 62500 = 250ms #define trigger_pulse1 (timer_period1 - 10) #define us_per_cm1 14.5 // Depends on module #define time_to_trigger_us1 450 #define distance_check1 70 #define timer_period2 62500 // 4 * 62500 = 250ms #define trigger_pulse2 (timer_period2 - 10) #define us_per_cm2 14.5 // Depends on module #define time_to_trigger_us2 450 #define distance_check2 70 //Statics static uint16_t echo_pulse_counts1 = 0; static uint16_t echo_pulse_counts2 = 0; //Functions void clk_setup_8mhz(); void setup_trigger_pulse1(); void setup_gpio_echo_interrupt1(); uint16_t get_distance_cm1(); void setup_trigger_pulse2(); void setup_gpio_echo_interrupt2(); uint16_t get_distance_cm2(); //Main void main(void) { clk_setup_8mhz(); setup_trigger_pulse1(); setup_gpio_echo_interrupt1(); setup_trigger_pulse2(); setup_gpio_echo_interrupt2(); P1DIR |= led1; P1OUT &= ~led1; P1DIR |= led2; P1OUT &= ~led2; clk_setup_8mhz(); while(1) { if((get_distance_cm1() < distance_check1)&&(get_distance_cm2() > distance_check2)) { P1OUT |= led1; P1OUT &=~ led2; } else if ((get_distance_cm2() < distance_check2)&&(get_distance_cm1() > distance_check1)) { P1OUT |= led2; P1OUT &= ~led1; } else if (((get_distance_cm1() < distance_check1)&&(get_distance_cm2() < distance_check2))==1) { P1OUT |= led1; P1OUT |= led2; } else{ P1OUT &= ~led1; P1OUT &=~ led2; } } } // End of main void clk_setup_8mhz() { UCA0CTL1 |= UCSWRST; // **Put state machine in reset** UCA0CTL1 |= UCSSEL_2; // SMCLK UCA0BR0 = 109; // 1MHz 115200 (see User's Guide) UCA0BR1 = 0; // 1MHz 115200 UCA0MCTL |= UCBRS_1 + UCBRF_0; // Modulation UCBRSx=1, UCBRFx=0 UCA0CTL1 &= ~UCSWRST; UCA0IV=0x02; // **Initialize USCI state machine** UCA0IE |= UCTXIE + UCRXIE; } void setup_trigger_pulse1() { P4DIR |= trigger_pin1; P4OUT &= ~trigger_pin1; P4SEL |= trigger_pin1; TB0CCR0 = timer_period1;//up mode it will count upto time period value..set// TB0CCTL1 = OUTMOD_7;//reset /set// TB0CCR1 = trigger_pulse1;//reset whn it counts to ccrx value TB0CTL = TBSSEL_2 + MC_1+ ID_2;//smclk,up mode,div by 4,// __enable_interrupt(); } void setup_trigger_pulse2() { P4DIR |= trigger_pin2; P4OUT &= ~trigger_pin2; P4SEL |= trigger_pin2; TB0CCR0 = timer_period2;//up mode it will count upto time period value..set// TB0CCTL3 = OUTMOD_7;//reset /set// TB0CCR3 = trigger_pulse2;//reset whn it counts to ccrx value TB0CTL = TBSSEL_2 + MC_1+ ID_2;//smclk,up mode,div by 4,// __enable_interrupt(); } void setup_gpio_echo_interrupt1() { P1DIR &= ~echo_input_pin1; P1OUT &= ~echo_input_pin1; P1IE |= echo_input_pin1; P1IES |= echo_input_pin1; P1IFG &= ~echo_input_pin1; } void setup_gpio_echo_interrupt2() { P1DIR &= ~echo_input_pin2; P1OUT &= ~echo_input_pin2; P1IE |= echo_input_pin2; P1IES |= echo_input_pin2; P1IFG &= ~echo_input_pin2; } uint16_t get_distance_cm1() { return (echo_pulse_counts1 - time_to_trigger_us1)/ us_per_cm1; } uint16_t get_distance_cm2() { return (echo_pulse_counts2 - time_to_trigger_us2)/ us_per_cm2; } #pragma vector=PORT1_VECTOR __interrupt void PORT_1(void) { echo_pulse_counts1 = TB0R; P1IFG &= ~echo_input_pin1; echo_pulse_counts2 = TB0R; P1IFG &= ~echo_input_pin2; this is my code for msp430f5438... plz help
  3. how to set time period for 8Mhz frequency for Msp430F5438A?
  4. port 1 interrupt pins r not available in msp430F5438a board? wat should i do?
  5. intrtupt port is not available in msp430F5438A board....so how to provide echo interrupt? whether it is timer interrupt? plz explain about the interrupt? while calculating time period where u have got the value 62500? plz explain?
  6. why did u choose the clock frequency as 1MHz?? will it very for other boards msp430F5438.... ? plz reply
  7. but the trigger pin requires 5v TTL pulse..... will the mosfet provide TTL pulse? m using the code for MSP430F5438A,can u help?
  8. which mosfet should we use for triggering ? how to use it please explain how it works...?
  9. #define timer_period 62500 // 4 * 62500 = 250ms ---how did you assign 62500? plz reply
×
×
  • Create New...