Shop OBEX P1 Docs P2 Docs Learn Events
Spin Help — Parallax Forums

Spin Help

CenlasoftCenlasoft Posts: 265
edited 2012-04-25 06:31 in Propeller 1
Hello,
I am working on a homemade ping sensor just for fun and experimentation for my students. I am using two 40khz side-by-side ultrasonic transducers. To amplify the receiving signal, I am using an op amp breakout board from spark-fun. The hardware and software are below:
{{
***************************************
*        USTXRX.spin V1.1             *
* Author:  Curtis Desselles           *
***************************************

}}

CON
  _clkmode = xtal1 + pll16x
  _xinfreq = 5_000_000

  
VAR
  Long Exp_Val, Stack1[32]
   
OBJ
    pst       : "Parallax Serial Terminal"
PUB Main
    pst.start(115200)
    pst.Clear
    pst.Home
    repeat
      Exp_Val := US_out(0,1)
      pst.dec(Exp_Val / (clkfreq / 1_000_000))           
      pst.NewLine
   
PUb US_out(fpin,BT_Pin) : Time_Num | t, us, cnt1

'' US pulse generator
'' -- uses ctra to modulate pin at 40kHz
  
  us := clkfreq / 1_000_000
  dira[BT_Pin] := 0                                             
  ctra := (%00100 << 26) | fpin
  frqa := 2_147_483                                             ' 40kHz @ 80MHz system freq
  dira[fpin] := 1

  t := cnt                                                     ' Get the clk count
  outa[fpin] := 0                                              ' allow modulation
  waitcnt(t += (clkfreq / 1_000_000 * 125))                    ' on 125 us
  outa[fpin] := 1                                              ' kill modulation
  waitpeq(0, |< BT_Pin, 0)                                     ' Wait For Pin To Go LOW 
  waitpne(0, |< BT_Pin, 0)                                     ' Wait For Pin To Go HIGH
  cnt1 := t                                                    ' Store Current Counter Value
  waitpeq(0, |< BT_Pin, 0)                                     ' Wait For Pin To Go LOW 
  Time_Num := t - cnt1                                         ' Store Time_Num value

    

I am not getting anything to the serial terminal. When I test each section (tx and rx) I get a nice pulse from the tx and out of the amp I get a 2vpp signal or greater (3vpp max) (sinewave).
Thank you,
Cenlasoft
313 x 327 - 8K

Comments

  • Mike GMike G Posts: 2,702
    edited 2012-04-24 12:30
    Is your intention to setup a counter on each repeat loop invoked from Main? BTW, Setting APIN to zero stops the counter.

    Maybe if you explain intended function of the code.
  • lyassalyassa Posts: 52
    edited 2012-04-24 13:23
    I noticed this line in your code:

    waitcnt(t
    = (clkfreq / 1_000_000 * 125)) ' on 125 us

    I think the "=" sign is not correct. Did you mean to have it as:

    waitcnt(t
    + (clkfreq / 1_000_000 * 125)) ' on 125 us
  • Mike GMike G Posts: 2,702
    edited 2012-04-24 21:33
    lyassa += is an assignment operator.
      i := i + 2
    
    Can be written as 
      
      i += 2
    
  • CenlasoftCenlasoft Posts: 265
    edited 2012-04-25 06:31
    Hello,
    I will explain the purpose of my code. First, when I set up the hardware and use the scope to monitor the signal, I get a sine wave of about 360 mvpp with no obstruction to bounce back on. When there is an obstruction to bounce back, I get a 1- 3vpp signal depending on the distance of the obstruction. I was planning on sending a pulse (125usec at 40khz) and then wait for a low and then a high then low again to give me the time of flight. I could have ran the tx portion in a separate cog with an interval of about 1ms and use that time to wait for a signal. What is the best way to wait for the signal echo? Is my op amp breakout board slowing things down? Beau had suggestion on another post to use sigma-delta to measure the time of flight and stated that the procedure would amplify also.
    Thanks,
    Cenlasoft
Sign In or Register to comment.