Spin help
Hello,
I am trying to send a squarewave on two pins that are 180 degrees apart. I got that done I think. I am using an h-bridge to excite an ultrasonic transducer. from 5 V I will come out with a 10 vpp. It works. My spin code has something wrong. On the scope I see a squarewave (40KHZ). How do I time it to get .5 ms of the 40khz pulse then turnoff the h-bridge and listen for an echo.
Thanks, Cenlasoft
I am trying to send a squarewave on two pins that are 180 degrees apart. I got that done I think. I am using an h-bridge to excite an ultrasonic transducer. from 5 V I will come out with a 10 vpp. It works. My spin code has something wrong. On the scope I see a squarewave (40KHZ). How do I time it to get .5 ms of the 40khz pulse then turnoff the h-bridge and listen for an echo.
Thanks, Cenlasoft
{{
Template.spin
Curtis Desselles
}}
Con
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
Pin1 = 0
Pin2 = 1
Var
Obj
Pub Main
repeat
TX_Out 'TX a pulse x 5
dira[Pin1..Pin2]~~ 'Make pins output
outa[Pin1..Pin2] := %00 'Turn off h-bridge
Pub TX_Out | i
repeat i from 0 to 4
ctra := %00101 <<26 + Pin2<<9 +Pin1
frqa := 1<<31 / (clkfreq / 80_000)
dira |= |<Pin1 + |<Pin2
Return

Comments
2) If you still want pins 1 and 2 to be outputs with the h-bridge off, you could zero CTRA and do: OUTA[Pin1..Pin2]~ or OUTA[Pin1..Pin2] := $00
3) To get a particular pulse length, just wait that time, then set CTRA and the output pins to zero. Use: WAITCNT(CLKFREQ/2000 + CNT)
4) Remember that other statements will take a few microseconds. That may affect the 0.5ms pulse length. You may have to shorten the delay to compensate.
The code brackets use [] not <>
_clkmode = xtal1 + pll16x _xinfreq = 5_000_000 Pin1 = 0 Pin2 = 1 Pub Main ctra := %00101 <<26 + Pin2<<9 +Pin1 frqa := 1<<31 / (clkfreq / 80_000) dira[Pin1..Pin2] := %11 repeat outa[Pin1..Pin2] := %00 'on waitcnt(clkfreq/2000 + cnt) 'wait 0.5ms outa[Pin1..Pin2] := %11 'off ' wait for response here waitcnt(clkfreq/2 + cnt) 'pause 0.5s (optional)Andy
Cenlasoft.
dira[Pin0..Pin1] := %11 'ON
dira[Pin0..Pin1] := %00 'OFF
Andy
Regards,
Mickster