Hello. I’m a novice in BASIC. but somehow, I get by with the simple codes. however, i don’t know how to run the gears of the tri-track chassis for a period of time. example, i want it to run forward for 2 secs then turn left. could anyone suggest how i will do it? through codes, of course thanks.
It of course depends on what processor and motor controller you are using… Also depends on how accurate and fancy you wish the code to be.
On an Atom Pro It could be something as simple as:
NUMLOOPS con 500 ; first guess...
i var long
; Go forward for about 2 seconds
for i = 0 to NUMLOOPS
pulsout RightChannelPin, 4000
pulsout LeftChannelPin, 4000
next
Assuming this works at all and it goes foreword. Simply time how long it took and if not accurate enough modify NUMLOOPS until you are satisfied.
Or you could make it more complicated and use one of the system timers. For example you can use TimerA, which is an 8 bit timer. i.e it can count from 0 to 255 before it overflows. You can configure it to increment this value by different counts of system clocks. I often use the configuration for 8192 system clocks for 1 timer tick. So the maximum time you can measure before it overflows is:
8192*256/16000000 = ~.131 seconds. One way around this is to have the timer overflow raise an interrupt (call code outside of the main loop) and have this interrupt handler simply increment a counter, that you then test against.
To do this the code could look something like:
[code]
; initialize the timer
ONINTERRUPT TIMERAINT,IntHandler
TMA = (TMA & 0xF0) | 0x0 ;Sets TimerA to increment once every 8192 clock cycles.
timer var long
ENABLE TIMERAINT
ENABLE
; loop going foreword for about 2 seconds 2/.131 time between interrupts…
TCA = 0 ; reset the system timer count
timer = 0
while timer < 15
pulsout RightChannelPin, 4000
pulsout LeftChannelPin, 4000
wend
end
; Our interrupt handler - simply increment
IntHandler
timer = timer + 1
resume[/code]
Note, this was all entered on the fly, not compiled, so obviously not tested… Can easily be improved on to improve accuracy. For example TCA contains the system timer counter, so can use this. Could have the timer interupt add 256 each time instead of 1 and then use:
TIMER+TCA as the number of system clocks/8192, which is easy to convert to milliseconds.
So hopefully this will give you some ideas on possible solutions. There is lots of information about the system clocks on the H8/3694 Hardware manual that you can display from the help menu of the Basic Micro Studio.
Good Luck
Kurt
Thank you Sir Kurt. You’re reply is greatly appreciated. I’ll try to code it right away and see if I can modify and run it. Thanks again
[code]temp var byte
throttle var byte
steering var byte
i var long
throt var long
turn var long
throttle = 150
steering = 150
i = 0
low p0
low p1
main:
throt = (throttle-20)20
turn = (steering20)
if in13 = 0 then
for i = 0 to 500
pulsout 0, (throt)
pulsout 1, (turn)
next
endif
goto main[/code]
sir, this is the code i made. this code makes the gears go forward but don’t stop at certain time. i know it is because of GOTO MAIN. but if I erase GOTO MAIN, the code will not run. How can I modify this code for the track to stop at a certain time.
Sir, I already made a code that will forward and turn
[code]i var long
numloop con 5
low p0
low p1
'for i = 0 to numloop
pulsout p0, 2500
pulsout p1, 3000
pause 2000
high p0
high p1
pulsout p0, 3500
pulsout p1, 3000
pause 500
low p0
low p1
pulsout p0, 2500
pulsout p1, 3000
pause 2000
high p0
high p1
pulsout p0, 2500
pulsout p1, 3000
pause 500
low p0
low p1
pulsout p0, 2500
pulsout p1, 3000
pause 2000
'next
[/code]
here is my code. thanks again!