4-bit switch
Earl Foster
Posts: 185
I am using a 4-bit switch·to adjust timing.· The below procedure is called with each loop of the program and it works without any problems but I wonder if there was a better way of programming it.· A more efficient way.· It is pretty straightforward with only 4 bits but if I need a 5-bit or 6-bit switch the code starts to get pretty long and would be easy to mess up the binary count.
Trying to get better at coding so I was just wondering.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
WWW.HAPB.NET
"Don't ask yourself what the world needs - ask yourself what makes you come alive, and then go do it." - H.T.Whitman
Trying to get better at coding so I was just wondering.
Pub Get_Timing case ina[noparse][[/noparse]21..24] %0000: maxtime:= 30 %0001: maxtime := interval * 1 %0010: maxtime := interval * 2 %0011: maxtime := interval * 3 %0100: maxtime := interval * 4 %0101: maxtime := interval * 5 %0110: maxtime := interval * 6 %0111: maxtime := interval * 7 %1000: maxtime := interval * 8 %1001: maxtime := interval * 9 %1010: maxtime := interval * 10 %1011: maxtime := interval * 11 %1100: maxtime := interval * 12 %1101: maxtime := interval * 13 %1110: maxtime := interval * 14 %1111: maxtime := interval * 15
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
WWW.HAPB.NET
"Don't ask yourself what the world needs - ask yourself what makes you come alive, and then go do it." - H.T.Whitman
Comments
How about something like this?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
WWW.HAPB.NET
"Don't ask yourself what the world needs - ask yourself what makes you come alive, and then go do it." - H.T.Whitman
-Phil
Post Edited (Phil Pilgrim (PhiPi)) : 3/27/2009 7:16:46 PM GMT
I'll happily admit to still learning SPIN but something like this may well be faster...
-Phil
See attached timing code.
Original code - 38.2us
Beau's Code· - 35.6us
Phil's Code··· -·25.4us
Brian's Code· -·78.0us
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
WWW.HAPB.NET
"Don't ask yourself what the world needs - ask yourself what makes you come alive, and then go do it." - H.T.Whitman
Post Edited (Earl Foster) : 3/27/2009 8:00:29 PM GMT