- How to read the inputs effectively, especially as we were reading in ADC inputs and how to convert them again into a binary form , so case statements could be used. We managed to do this through reading each of the inputs into a memory location . Then using If statements these could be analysed and if over a certain value a 1 , 2 ,or 4, which in binary is 001 , 010, 100 could be added to a separate memory location , in my case b3. E.G if my left sensor sensed the line and went past a certain value then in b3 would be 100, if my right 001 and middle 010 or any combination of theses , like if all sensed the line 111. With this case statements could be used. It is important however after selecting the case to erase all the values in b3 so when the programs loops the values do not keep adding up.
- How to change between modes, symbol mode and line follower. As we used a toggle switch which was connected to input pin 7 , we just read in all the pins to a memory location and if over a certain value (because pin7 if on would effectively have a value of 128, and thus make any values being read into the input pins over 128) then it would be in symbol mode and if under the value it would be in line follower mode.
- Lack of program memory, it was soon realised after creating my program that the computer would not allow it to download onto the chip because the program took up to much memory, essentially my programming for the motors which I put into each case was making the file way to big. The way I combated this was to use subroutines. I made one for forward , turn right and turn left. These could be called by using GOSUB...turnright and the program would return to its original location by use of the command RETURN. This saved duplicating lots of code, and made my file size much smaller.
The finished program was as follows;
main:
b7=pins ;read in all pins to memory
readadc 0,b0 ;reading all adc inputs to memory
readadc 1,b1
readadc 2,b2
if b7 <10>
goto symmode ;else go to symbol mode
normal:
if b2>100 then let B3=B3+1 ;right sensor, p
endif
if b1>100 then let B3=B3+2 ; middle sensor
end if
if b0>100 then let B3=B3+4 ; left sensor
endif
select B3 ; case statements for the different scenarios
case %00000000; both motors off and return to select
case %00000001 ; right motor off
gosub turnright
case %00000010 ; both motors on and return to select
gosub forward
case %00000011 ; Right motor off
gosub turnright
case %00000100 ; Left hand motor off
gosub turnleft
case %00000101 ; Error, carry on
case %00000110 ; Left hand motor off
gosub turnleft
case %00000111 ; both motors on and return to select
gosub goforward
end select
debug
let b3=%00000000
goto main
symmode:
if b2>100 then let B3=B3+1 ;right sensor
endif
if b1>100 then let B3=B3+2 ; middle sensor
end if
if b0>100 then let B3=B3+4 ; left sensor
endif
select b3
case %00000000 ; straight
gosub goforward
case %00000001 ; forward 90 right
gosub turnright
pause 1000
case %00000010 ; straight
gosub goforward
case %00000011 ; forward 90 right
gosub turnright
pause 1000
case %00000100 ; forward 90 left
gosub turnleft
pause 1000
case %00000101 ; Forward pause reverse
case %00000110 ; Forward 90 left
gosub turnleft
pause 1000
case %00000111 ; Forward pause reverse
end select
debug
let b3=%00000000
goto main
turnright: ; subroutines for driving motors
`To Turn Right
High 5 `Left Motor Fowards
Low 4 `Left Motor Forwards
low 6 `Turn Right Motor Off
return
turnleft:
` To Turn Left
High 6 `Right Motor Forwards
low 7 `Right Motor Forwards
low 5 `Tur Left Motor off
return
goforward:
`To Drive Motor Forwards
High 5 `Left Motor Fowards
Low 4 `Left Motor Forwards
High 6 `Right Motor Forwards
low 7 `Right Motor Forwards
return
No comments:
Post a Comment