Jump to content


  • Content Count

  • Joined

  • Last visited

Reputation Activity

  1. Like
    sagarika36 reacted to username in HC - SR04 Ultrasound Module Driver Code   
    The trig pin on the module wants to see a 0-5V digital input. The msp430 only has a 3.6V input max. That mosfet works as a 3.6V to 5V converter. Since its a 5V module I did this to be safe though i'm not sure its required. It might tolerate lower voltage inputs. Use any basic mosfet that can handle a 3.6V gate voltage. A 2n7007 is a basic FET that should work.
    As for how a mosfet works, see wikipedia.
    If your asking as to how the trig pin works on the module, see the module datasheet.
  2. Like
    sagarika36 reacted to roadrunner84 in HC - SR04 Ultrasound Module Driver Code   
    SMCLK is set to 1MHz, TimerA is set to run at SMCLK/1, so also 1MHZ. 1MHZ means that each timer tick will be 1/1MHz = 1us.
    62500 us = 62.5ms, 4 * 62.5ms = 250ms.
    I'm not really sure why this multiple of 4 is mentioned, because I can't find it otherwise in the code.
    trigger_pulse is set to the timer rollover value (timer_period) minus 10, in mode 7. Mode 7 which means there will be a negative pulse from timer_period - 10 until timer_period, using the mentioned open drain configuration would invert this to become a positive pulse. This means the pulse is 10us long, I don't know why he mentions it to be 100us, I also don't see any capture/compare.
    Your description of us/58=centimeters seems odd, never have I seen an equation where one side only mentions the unit. I suppose your datasheet should mention us/centimeter=58
    time_to_trigger_us may be experimentally confirmed, it seems to be some correction for the delay through the system. So the timer would count while the ultrasonic pulse has not been sent yet, this levels that off, I think.
  3. Like
    sagarika36 reacted to username in HC - SR04 Ultrasound Module Driver Code   
    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.
  • Create New...