This is working great! Phil, no problems to report..:blank:
I will let it heat up for a while, and see whats to see. it's only been running ten minutes or so...
The problem is that the pulse that has to be detected is so short and so runty, that nothing short of waitpeq in Spin will catch it. And, if waitpeq misses it, well, you know what happens then.
Can't tell you how much this short explanation cleared some things up for me. Thanks very much.:thumb:
I'm much happier with the new code, since the Ping))) pin isn't being driven all the time during the detect interval, but just pulsed low then tri-stated again. I've created an object from the new code and replaced the previous version in the first post with it.
There's no hope in that department, I'm afraid, since there's no way I could test such a thing. Lack of eye-hand coordination renders me useless as an RC pilot.
Comments
CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 PING_PIN = 0 OBJ pst : "parallax serial terminal" VAR long echo PUB start pst.start(38400) cognew(@ping, @echo) repeat pst.char(1) pst.dec(dist_mm) pst.char(11) PUB dist_mm return (((echo / 80) >> 1) * 10_000 / 29034 - 87) #> 0 DAT ping mov dira,pin_mask test cnt_mask,cnt wc if_c jmp #ping :wait_hi test cnt_mask,cnt wc if_nc jmp #:wait_hi mov outa,pin_mask mov dira,pin_mask :wait_pulse test pulse_mask,cnt wc if_nc jmp #:wait_pulse mov outa,#0 :wait_wait test wait_mask,cnt wc if_nc jmp #:wait_wait mov dira,#0 neg time,cnt :echo_loop mov dira,pin_mask mov dira,#0 nop nop nop test pin_mask,ina wc if_c jmp #:echo_loop add time,cnt wrlong time,par jmp #ping cnt_mask long $0040_0000 pulse_mask long $0002_0000 wait_mask long $0001_0000 pin_mask long 1 << PING_PIN time res 1-Phil
I will let it heat up for a while, and see whats to see. it's only been running ten minutes or so...
Can't tell you how much this short explanation cleared some things up for me. Thanks very much.:thumb:
-Tommy
-Phil
Here is my version of "Roaming with a Ping((("
CON _CLKMODE = XTAL1 + PLL16X _CLKFREQ = 5_000_000 PING_PIN = 0 OBJ S2 : "S2" S2_ping : "S2_ping" PUB Main | distance S2.start ' Start S2 object S2.set_led(s2#POWER, s2#BLUE) ' Turn on the power LED. S2.start_motors ' Start motor controller S2_ping.start(PING_PIN) ' Start Ping((( controller repeat S2.move_now(100, 100, 0, 10, 1) ' Forward until preempted. distance := (S2_ping.dist_mm) ' Get distance reading from ping((( if distance < 170 ' if distance less then 170 then... S2.stop_now ' Stop moving S2.set_speed(15) ' Set turning speed S2.begin_path ' Begin path S2.turn_deg(-90) ' Turn right. S2.end_path ' End movements S2.wait_stop ' Wait for turn to completeNot the fanciest code, but she works...-Tommy
I loaded the new code, put my PING))) in my new holder and went measuring distances. It worked like a champ for about 30 minutes of playing.
Well done!!!
Now, I'll have to go roaming with Tommy's code. My S2 hasn't had this much attention in a long time!!
Hmmm.....wonder how the S2 would like running under Forth? Hmmm......
-Phil
I love the smell of magic smoke in the morning...
... it smells like.....testing!