Shop OBEX P1 Docs P2 Docs Learn Events
Square wave problem — Parallax Forums

Square wave problem

CenlasoftCenlasoft Posts: 265
edited 2012-02-28 06:48 in Propeller 1
Hello,
I am trying to use an ultrasonic TX and I have attached a schematic showing the circuit I built. I simply using pin 0 to send out a square wave that is .5ms in duration with an interval of 20 ms. It is a continuous wave. It works for about 45 sec to 1 min and then stops. I checked this with a scope with the ultrasonic sensor and without. The prop simply stops sending the square wave. If I press reset on the prop it starts again.
Thanks for any help.
Cenlasoft
1024 x 791 - 84K

Comments

  • CircuitsoftCircuitsoft Posts: 1,166
    edited 2012-02-21 10:33
    Can you post your code? The circuit looks fine.
  • MagIO2MagIO2 Posts: 2,243
    edited 2012-02-21 11:24
    Wait nother 50 sec and it propably starts again. Sounds like a waitcnt-problem. But to be sure you should post the code - if it's more than a short program, attach a zipped version.

    Another idea would be a recursion in your program which eats up the whole HUB-RAM.
  • groggorygroggory Posts: 205
    edited 2012-02-21 11:52
    Cenlasoft wrote: »
    Hello,
    I am trying to use an ultrasonic TX and I have attached a schematic showing the circuit I built. I simply using pin 0 to send out a square wave that is .5ms in duration with an interval of 20 ms. It is a continuous wave. It works for about 45 sec to 1 min and then stops. I checked this with a scope with the ultrasonic sensor and without. The prop simply stops sending the square wave. If I press reset on the prop it starts again.
    Thanks for any help.
    Cenlasoft

    Try disconnecting this circuit completely...

    Then running your prop program and puttnig your square wave pin on your scope and see if it'll keep working beyond the 45s-1min. If it is still working, then this circuit is the problem.

    If this is the case I'm betting it has something to do with an interaction with the speaker/ transducer and your hex inverter. If you're using a piezo speaker perhaps you're hitting a natural frequency of it and it's overdriving the hex inverter and it's heating up and then going into shutdown? ...not sure.

    What do you think?
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-02-21 12:48
    I'm voting for a software issue regarding use of waitcnt.

    -Phil
  • CenlasoftCenlasoft Posts: 265
    edited 2012-02-21 14:27
    Thanks for your suggestions. I tried sending a square wave using a signal generator set to 3.3 v and 40 khz. It did not fail. I have listed the code below:
    {{
    USTX.spin
    Curtis Desselles
    }}
    Con

    _clkmode = xtal1 + pll16x
    _xinfreq = 5_000_000

    freqPin = 0
    NewFreq = 40_000

    Var
    long stack1[32]

    Obj

    Pub Main

    cognew(US_out(freq_Pin),stack1)


    PUb US_out(fpin) | t

    '' US pulse generator
    '' -- uses ctra to modulate pin at 40kHz

    ctra := (%00100 << 26) | fpin
    frqa := 2_147_483 ' 40kHz @ 80MHz system freq
    dira[fpin] := 1

    t := cnt
    repeat
    outa[fpin] := 0 ' allow modulation
    waitcnt(t += (clkfreq / 1_000_000 * 500)) ' on 0.5ms
    outa[fpin] := 1 ' kill modulation
    waitcnt(t += (clkfreq / 1_000 * 18)) ' off 19.5ms
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-02-21 14:49
    attachment.php?attachmentid=78421&d=1297987572

    -Phil
  • CenlasoftCenlasoft Posts: 265
    edited 2012-02-21 15:51
    Here is code properly displayed, thanks Phil:
    {{
      USTX.spin
      Curtis Desselles
    }}
    Con
    
     _clkmode = xtal1 + pll16x
     _xinfreq = 5_000_000
    
     freqPin = 0
     NewFreq = 40_000 
      
    Var
     long stack1[32]
    
    Obj
    
    Pub Main
    
      cognew(US_out(freq_Pin),stack1)
    
    
    PUb US_out(fpin) | t
    
    '' US pulse generator
    '' -- uses ctra to modulate pin at 40kHz
    
      ctra := (%00100 << 26) | fpin
      frqa := 2_147_483                                             ' 40kHz @ 80MHz system freq
      dira[fpin] := 1
    
      t := cnt
      repeat
        outa[fpin] := 0                                              ' allow modulation
        waitcnt(t += (clkfreq / 1_000_000 * 500))                   ' on 0.5ms
        outa[fpin] := 1                                              ' kill modulation
        waitcnt(t += (clkfreq / 1_000 * 18))                        ' off 19.5ms
    
  • kuronekokuroneko Posts: 3,623
    edited 2012-02-21 16:21
    Pub Main
    
      cognew(US_out([COLOR="orange"]freqPin[/COLOR]),[COLOR="red"]@[/COLOR]stack1)
    
  • CenlasoftCenlasoft Posts: 265
    edited 2012-02-21 17:36
    Thanks kuroneko, I don't know how I missed that. It works now. I wonder how it worked for 1 min before?
    Cenlasoft
  • w8anw8an Posts: 176
    edited 2012-02-21 18:30
    Seems like it would be a good idea to put some kind of procedure after the cognew(...) so that cog 0 doesn't go into some unknown free running state...

    Pub Main
         cognew(US_out(freqPin),@stack1)
         repeat
    
    
  • kuronekokuroneko Posts: 3,623
    edited 2012-02-21 18:30
    Cenlasoft wrote: »
    I wonder how it worked for 1 min before?
    You basically placed your stack at address 0 in hub which definitely affects clkfreq (long[0]). If you'd waited slightly longer the pulse train would have restarted.

    @w8an: cog 0 just stops when it reaches the end of the main method (provided no-one messed with its stack).
  • w8anw8an Posts: 176
    edited 2012-02-21 18:41
    @w8an: cog 0 just stops when it reaches the end of the main method (provided no-one messed with its stack).

    Noted
  • CenlasoftCenlasoft Posts: 265
    edited 2012-02-28 06:48
    Thanks everyone for helping with this problem. In the circuit schematic (attached) that I posted, I want to tap in at one of the two traces going into the ultrasonic sensor. Basically I want to send a pulse (.5 ms, 20 ms interval) The amplitude is 10 vpp, At the tap point, I want to wait for a return pulse and measure the time of flight. I know how to do the spin code for that but, I don't want to burn my prop pin with the incoming signal pulse. The incoming signal pulse will be amplified using a 358 dual op amp which I have done already. It gives me a 2 vpp output. Any help with the circuit or code is appreciated.
    Thanks
    Cenlasoft
Sign In or Register to comment.