username 198 Posted November 3, 2014 Author Share Posted November 3, 2014 1MHz clock makes math easy, no other reason. Yes the mosfet can generate a 5V pulse with the circuit shown. Yes, you should be able to port this to other MCUs though if their core clocks are different you may have to tweak the math to get the proper distance. sagarika36 1 Quote Link to post Share on other sites
sagarika36 0 Posted November 17, 2014 Share Posted November 17, 2014 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? Quote Link to post Share on other sites
sagarika36 0 Posted November 17, 2014 Share Posted November 17, 2014 port 1 interrupt pins r not available in msp430F5438a board? wat should i do? Quote Link to post Share on other sites
sagarika36 0 Posted November 17, 2014 Share Posted November 17, 2014 how to set time period for 8Mhz frequency for Msp430F5438A? Quote Link to post Share on other sites
sagarika36 0 Posted January 14, 2015 Share Posted January 14, 2015 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 Quote Link to post Share on other sites
marcosh72 0 Posted June 28, 2015 Share Posted June 28, 2015 Wouldn't it be better to use a timer register in capture mode to get the value of the timer when the echo pulse goes up/down? It seems faster than using GPIO interrupts. I tried it here with the HC-SR04 and it works wonderfully, even when the object is at about 1cm from the sensor. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.