Lights, ASM, Beethoven
I added three LED's to my Stingray to indicate ping sensor action. I also read about using the counters, and I added a piezo speaker, so I figured I'd apply the knowledge with a taste of Beethoven. I also rolled the ping code. This is turning out to be a good learning experience for me.
DAT org sensor_loop :sound mov items,#24 ' # items in notes array or ctra,_nco ' set nco mode mov index,#notes ' address first item or ctra,#6 ' set output pin :load movs :get_freq,index ' move index address to :get_freq label or dira,s_pin ' set pin to output :get_freq mov frqa,0-0 ' move notes[noparse][[/noparse]index] into frqa mov s_delay,#10 ' plays slower if pings don't detect obstacle :delay_note call #three_pings ' play note while checking pings ' <- add more sensors here djnz s_delay,#:delay_note ' lower s_delay if adding more sensors andn dira,s_pin ' set pin to input add index,#1 ' increment index to next item djnz items,#:load ' decrement items, jump if not zero jmp #sensor_loop ' end sensor_loop ============================= three_pings mov pin,#1 ' first ping pin mov addr,par ' get distance variable address :get_ping or dira,pin ' set pin to output or outa,pin ' set high mov time,cnt ' need 2-5 us delay add time,delay waitcnt time,delay andn outa,pin ' clear pin andn dira,pin ' set pin to input waitpne null,pin ' wait for pin to go high mov cnt1,cnt ' store count waitpeq null,pin ' wait for pin to go low mov cnt2,cnt ' store count2 sub cnt2,cnt1 ' calculate ping time shr cnt2,#7 wrlong cnt2,addr ' write ping time shl pin,#1 ' next ping sensor pin add addr,#4 ' move to next long cmp pin,#5 wc ' inner loop if carry if_c jmp #:get_ping ' if carry, pin < 5 three_pings_ret ret ' all pings returned distance ' Notes to frequencies ' C6 C#6 D6 Eb6 E6 F6 F#6 G6 Ab6 A6 Bb6 B6 '56_184, 59_524, 63_066, 66_814, 70_786, 74_995, 79_456, 84_181, 89_186, 94_489, 100_108, 105_629 ' C7 C#7 D7 Eb7 E7 '112_528, 119_049, 126_128, 133_628, 141_574 notes long 141_574, 133_628, 141_574, 133_628, 141_574, 105_629, 63_066, 56_184, 94_489 long 70_786, 94_489, 112_528, 141_574, 94_489, 105_629, 70_786, 89_186, 70_786 long 89_186, 105_629, 112_528, 70_786, 94_489, 141_574 s_pin long 1 << 6 ' sound pin _nco long %00100 << 26 ' nco counter index long 0 ' index for notes array null long 0 delay long 160 ' ping trigger delay s_delay res 1 ' sound delay items res 1 ' number of items in notes array pin res 1 ' ping pin cnt1 res 1 ' timing counters cnt2 res 1 addr res 1 time res 1 fit
Comments
Needless to say, they still aren't happy with my choices.