Shop OBEX P1 Docs P2 Docs Learn Events
HB-25 SPIN Question — Parallax Forums

HB-25 SPIN Question

NWCCTVNWCCTV Posts: 3,629
edited 2013-07-09 17:04 in Propeller 1
I am anxiously awaiting the arrival of my Wild Thumper robot which will be here tomorrow. While I am waiting I am working on getting my SPIN code for the IR Remote to work with it. It comes with 2 Ea. HB-25's. Several months ago I wrote the code for 2 HB-25's to work using Parallax IR receiver and a standard remote control for another project using PBasic. In PBasic, you must issue a pause 1 command immediately after the first PULSEOUT command to start the second HB-25. Do I do the same thing in SPIN? PBasic code example below.
IF (IN3 = 1)  THEN        ' Checks if Pushbutton on IN3 is pressed,
                          ' If Yes then send pulseout command to Pin
    PULSOUT HB25, 500     ' 15  to rotate motor 1 forward.
    PAUSE 1               ' 1 mS Delay For Motor 2 Pulse
    PULSOUT HB25, 1000    ' send pulsout command to pin 15
                          ' to rotate motor 2 reverse.
    PAUSE 10                ' wait 10 ms

Comments

  • JonnyMacJonnyMac Posts: 9,107
    edited 2013-07-09 15:56
    You can use one of the counters to create a high precision pulse output. It's not quite the same as the BS2 PULSOUT (which inverts the pin state), but for your purposes this will work (I use it for servo pulses all the time). As PAUSE is not part of the Spin language I've included my method for that, too.
    pub pulse_out(pin, us)
    
    '' Creates active-high pulse output on pin (timing in microseconds)
    '' -- leaves pin a output low
    
      us *= (clkfreq / 1_000_000)                                   ' convert to ticks
    
      phsa := 0  
      frqa := 1                                                     
      ctra := (%00100 << 26) | pin                                  ' NCE/SE mode
      dira[pin] := 1                                                ' make pin an output
    
      phsa := -us                                                   ' start the pulse
      waitpne(1 << pin, 1 << pin, 0)                                ' let it finish
    
    
    pub pause(ms) | t
    
    '' Delay program in milliseconds
    
      if (ms < 1)                                                   ' delay must be > 0
        return
      else
        t := cnt - 1776                                             ' sync with system counter
        repeat ms                                                   ' run delay
          waitcnt(t += (clkfreq / 1000))
    


    Converting your PBASIC fragment:
    if (ina[3] == 1)
        pulse_out(HB25, 1000)
        pause(1)
        pulse_out(HB25, 2000)
        pause(10)
    


    Remember that BS2 PULSOUT units are 2us each; the pulse_out() method uses 1us units, hence the change in the values.
  • NWCCTVNWCCTV Posts: 3,629
    edited 2013-07-09 17:04
    Thanks Jon. I was aware of this, I just posted my code as an example.
Sign In or Register to comment.