Shop OBEX P1 Docs P2 Docs Learn Events
Which stamp to use as pulse generator / emulator? — Parallax Forums

Which stamp to use as pulse generator / emulator?

Garced WinderGarced Winder Posts: 4
edited 2010-09-04 11:05 in BASIC Stamp
I am considering using a basic stamp to emulate/generate a automotive crankshaft position sensor signal to allow test-benching and development work of a car ECM, but am unsure which stamp would be most appropriate.

The signal to be generated emulates a magnetic sensor that reads a wheel with 7 notches; 6 evenly spaced and 1 extra notch (sync) which allows the ECM to determine crankshaft position.

Max output would be ~42khz.

Initial plan was to count pulses from external source, turn on/off stamp output pin appropriately.

TIA

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-10-17 04:40
    You've got a little more than 23us for the pulse period with a extra pulse thrown in for an occasional period of under 12us. You don't say what the actual pulse width is.

    The fastest Stamp (BS2px) is not fast enough to handle this. It executes about 20K instructions (not statements necessarily) per second.

    A Propeller or an SX would be more than adequate for the task. The Propeller has the advantage of being able to directly handle a PS/2 keyboard and can provide either VGA or NTSC video for a display. It uses a crystal timebase and would not need an external timing source. Have a look at the Propeller Protoboard with the Accessory Kit.
  • Garced WinderGarced Winder Posts: 4
    edited 2007-10-17 14:49
    Each pulse is 10 degrees of crank rotation.

    Thanks for the recommendation on the SX or Propeller - will check them out.
  • Mike GreenMike Green Posts: 23,101
    edited 2007-10-17 16:07
    Here's an untested example of what would be necessary for a Propeller to produce the pulse train needed. This would be incorporated into some kind of main program that would set the parameters you want.
    
    '' This object emulates/generates a automotive crankshaft position
    '' sensor signal to allow test-benching and development work of a car
    '' ECM.  The signal to be generated emulates a magnetic sensor that
    '' reads a wheel with 7 notches; 6 evenly spaced and 1 extra notch
    '' (sync) which allows the ECM to determine crankshaft position.
    
    '' To start the emulator (if the object is called OBJ):
    
    '' OBJ.start( pin, cyclesPerSec, pulseWidthUS, pulsesPerCycle)
    
    '' This returns a non-zero value if successful, zero on failure
    '' if unable to start a new cog or the timing values are zero.
    
    ''            pin : The I/O pin number to be used for the output
    ''   cyclesPerSec : The number of "revolutions" per second
    ''   pulseWidthUS : The output pulse width in microseconds
    '' pulsesPerCycle : The number of "spokes" on the timing wheel
    ''                  Note that this does not include the sync pulse
    ''                  which is produced once per cycle midway between
    ''                  the first two "spokes" of a cycle.
    
    '' To stop the emulator and free the cog used:
    
    '' OBJ.stop
    
    '' This can be called even if the emulator has never been started.
    
    VAR long cog                           ' Holds cog number + 1
    
    PUB start(pin, cyclesPerSec, pulseWidthUS, pulsesPerCycle) | usTicks
       stop                                ' Stop cog if already started
       if cyclesPerSec == 0 or pulseWidthUS == 0 or pulsesPerCycle == 0
          return 0
       usTicks := clkfreq / 1_000_000      ' Clock ticks per microsecond
       pinMask := |< pin                   ' I/O pin bitmask
       between := clkfreq / cyclesPerSec   ' Clock ticks per cycle
       width := usTicks * pulseWidthUS     ' Clock ticks per output pulse
       between := between / 2 - width      ' 1/2 cycle less pulse width
       pulses := pulsesPerCycle            ' Number of pulses per cycle
       cog := cognew(@entry,@cyclesPerSec) + 1
       waitcnt(clkfreq/1000 + cnt)         ' Wait for cog to start
       return cog                          '  and grab its parameters
    
    PUB stop
       if cog                              ' If cog was started,
          cogstop(cog~ - 1)                '  stop it
    
    DAT
                org     0
    entry       andn    outa,pinMask       ' Set up output pin to output low
                or      dira,pinMask
                mov     time,between       ' Initialize timer to some time
                add     time,cnt           '  a little bit in the future
    cycle       mov     count,pulses       ' Overall loop
    pulse       waitcnt time,width         ' Start of pulse
                or      outa,pinMask
                waitcnt time,between       ' End of pulse
                andn    outa,pinMask
                cmp     count,pulses   wz  ' See if first cycle
                waitcnt time,width
         if_eq  or      outa,pinMask       ' Do sync pulse on first cycle
                waitcnt time,between
         if_eq  andn    outa,pinMask
                djnz    count,#pulse
                jmp     #cycle
    
    pinMask     long    0                  ' I/O pin mask
    between     long    0                  ' Clock ticks between pulses
                                           '  in the case of a sync pulse
    width       long    0                  ' Width of pulse in clock ticks
    pulses      long    0                  ' Number of pulses per cycle
    count       long    0                  ' Counter for pulse number
    time        long    0                  ' Next system time to wait for
    
    
  • ftj405ftj405 Posts: 8
    edited 2010-09-04 10:49
    I found a circuit that uses two inverters from a 4049 IC (Hex Inverters), to create a pulse generator.

    It has a single output.

    Using a BS2, I sent the output to PIN0 and if HIGH set PIN1 to high to blink the led.

    I'm am trying to get a pulse to use with a clock project, but i can't get the pulses to be consistant or the timing to be slow enough.

    Any suggestions... I'll apologize now for the poor schematic.

    Here is the BS2 app code.

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}



    Blink PIN 1
    Pulse PIN 0
    TSeconds VAR Nib 'tenths of a second.
    Seconds VAR Byte 'seconds count
    Minutes VAR Byte

    TSeconds = 0
    Seconds = 0
    Minutes = 0


    DO WHILE Minutes < 1
    IF (Pulse=0) THEN
    LOW Blink
    ELSE
    HIGH Blink

    IF(TSeconds<9)THEN
    TSeconds = TSeconds + 1
    ELSE
    GOSUB ADDSecond
    TSeconds = 0
    ENDIF
    'GOSUB DisplayTime
    ENDIF
    LOOP
    END

    ADDSecond:

    IF(Seconds < 59) THEN
    Seconds = Seconds + 1
    ELSE
    Seconds = 0
    GOSUB ADDMinute
    'GOSUB DisplayTime
    ENDIF
    RETURN


    ADDMinute:
    Minutes=Minutes + 1
    GOSUB DisplayTime
    RETURN

    DisplayTime:
    DEBUG "Time is: ", DEC Minutes, ":", DEC Seconds, ":", DEC TSeconds, CR
    RETURN
    800 x 600 - 25K
  • Mike GreenMike Green Posts: 23,101
    edited 2010-09-04 11:05
    The circuit you showed doesn't work well at all with slow pulses. You can use a CMOS timer like the LMC555. You'll need to use a tantalum capacitor for timing if you need a large value, but you'd be better off using a smaller value that is available with a mylar or other plastic dielectric.

    If you want an accurate clock, you will need to use a 32768Hz crystal oscillator and a divider to get 1Hz pulses. Here's one example. You can leave out the CD4027 if you're willing to use a 2Hz clock pulse.
Sign In or Register to comment.