Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PLEASE HELP WITH BUGGY program

Status
Not open for further replies.

mcgriddless

New Member
hi guys, i doing my final year project and i am really stuck with the programming. i am using Mplab to write the program.
The buggy is a 2 wheel buggy which has 4 top sensors which are infra red and 4 btm sensors which are infra red as well.
The top sensors are to detect obstacles which then allow the motor to move. The btm sensors will read the colours which are black and white. The platform which the buggy is running on is a dart board like black and white spiral. So when all 4 btm sensors sense black in the middle of the spiral dart like platform it will stop. so far i am abit to run the Leds. However whenever i try to test my buggy forward or back using the lookup table it doesnt move. The proto type is prefectly fine.

I am really stump of what to do now. I keep trying to change the lookup table but i think that its fine. I am trying to fix the btm sensors of my program first. My btm sensors are able to detect and light up the leds but they are not able to move the motor. Please help guys please. Thanks. I have uploaded a picture of my circuit board. IF u guys need more information please tell me thanks so much
 

Attachments

  • fypcircuit.jpg
    fypcircuit.jpg
    39.9 KB · Views: 315
Last edited by a moderator:
So... it sounds like you can't get the motors to run?

Before attempting things like lookup tables, it's a smart idea to just send a byte to the port to see if you can get those H-bridges to run the motors. Do that, check the voltage on the port pins. Hard to tell from that fuzzy schematic, but it looks like you are using port A... on a... what, PIC18? Port A is multiplexed with the A/D converter, the problem may be in the port configuration bits.
 
yes i cant get the motor to run. i' have got a feeling that its my look up table that is the problem, but i have double checked it and its fine. Yes it is a PIC18. hmm i try and work on my program more. then i will get back to you. But this is what i have done so far.


; Program: [Stepper_Motor.asm]; Written by: Foo DF; Date: 29-Aug-2006
; This program configures PortC RC0-7 as OUTPUT to control the L293D Motor Control Board
;
; ************* HEADER **************************************************************
LIST p=16F876 ;PIC16F876 is the target processor
#include "P16F876.INC" ;Include header file
__config H'3F39' ;Osc=XT; WDT=Off;
;Power Up Timer=Off; Brown Out Detect=Off
;LVP=Disabled, Flash Program Write=Enabled,
;Data EE Read Protect=Off; Code Protect=Off
;
;************** File Register Variable use ******************************************
cblock H'20'
NUMBER
d1 ;use for Delay subroutine
d2
d3
d4
SENSOR
BOTTOM
TOP_motion
BTM_motion
sensor
time_on
TOP_SENSORCHECK
endc
;
; ************* Reset Vector ********************************************************
org H'00'
clrf STATUS
movlw 0x00
movwf PCLATH
goto Initial
;
; ************* Port B and C I/O Initialisation *************************************
Initial ;
bsf STATUS,RP0 ; Select BANK 1
; banksel TRISB
movlw B'00000000' ; Set PortB to O/Ps
movwf TRISB ; PortB setting is done!
movlw B'11111111' ; Set PortC to I/Ps
movwf TRISC ; PortC setting is done!
movlw B'00000000' ; Set PortA to O/Ps
movwf TRISA ; PortB setting is done!
movlw B'00000110'
movwf ADCON1

;
; ************* Main Program *******************************************************
banksel PORTA
;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
Start
clrf PORTA
clrf PORTB
clrf PORTC
goto SENSOR_CHK
;movlw b'00110000'
;movwf PORTA
;call SENSE
; call TOPP
;goto Start





SENSOR_CHK

movlw b'00110000'
movwf PORTA
call Delay_50us
movfw PORTC
movwf SENSOR
call SENSE
; call TOPP
return

Forward movlw b'00111010'
movwf PORTA
return

Reverse movlw b'00111111'
movwf PORTA
return

Right_turn movlw b'00111110'
movwf PORTA
return

Left_turn movlw b'00111011'
movwf PORTA
return


;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&



SENSE
clrf PORTA
clrf PORTB
movfw PORTC
movwf SENSOR
movwf PORTB
return

TOPP
movfw SENSOR
andlw b'11110000'
movwf TOP
swapf TOP,w
call TOP_SENSORCHECK
call Top_Table
movwf PORTA
return


BTM
movfw SENSOR
andlw b'00001111'
movwf BOTTOM
swapf BOTTOM,w
; call BTM_Table
movlw b'00111010'
movwf PORTA
return

;
TOP
movfw SENSOR
andlw b'00001111'
call Top_Table
movwf PORTA


Delay_50us movlw 0x0F
movwf d1

again3 decfsz d1,f
goto again3

return

;con_PWM

Top_Table

addwf PCL
retlw b'00110000' ;stop (Stop,stop)(0000)
retlw b'00111000' ;Left Turn (stop,forward)(0001)
retlw b'00110010' ;right turn (move,stop)(0010)
retlw b'00111111' ;reverse (reverse, reverse)(0011)
retlw b'00111000' ;turn left (stop,move)(0100)
retlw b'00111010' ;forward (move,move)(0101)
retlw b'00110010' ;turn right(move,stop)(0110)
retlw b'00111000' ;turn left(stop,move)(0111)
retlw b'00110010' ;turn right(move stop)(1000)
retlw b'00110010' ;turn right(move stop)!1001)
retlw b'00110010' ;turn right(move stop)(1010)
retlw b'00110010' ;turn right(move stop)(1011)
retlw b'00111010' ;forward (move move)(1100)
retlw b'00111000' ;turn left (stop move)(1101)
retlw b'00110010' ;turn right (move stop)(1110)
retlw b'00111010' ;move forward (move move)(1111)





BTM_Table
addwf PCL
retlw b'00111010' ;forward (0000)
retlw b'00110010' ;right (0001)
retlw b'00111000' ;left (0010)
retlw b'00111010' ;forward (0011)
retlw b'00111010' ;forward (0100)
retlw b'00110010' ;right (0101)
retlw b'00111000' ;left (0110)
retlw b'00111010' ;forward (0111)
retlw b'00111010' ;forward (1000)
retlw b'00110010' ;right (1001)
retlw b'00111000' ;left (1010)
retlw b'00111010' ;forward (1011)
retlw b'00111010' ;forward (1100)
retlw b'00111101' ;right (1101)
retlw b'00111000' ;left (1110)
retlw b'00110000' ;stop (1111)



; ************* End of the program ************************************************
END ;End of the program




i have not done the pulse width convertor but without it the buggy should still be able to move
 
I see a couple of problems -

You "goto" SENSOR_CHK, but SENSOR_CHK has a "return" statement in it. You only return from a routine you "call", not "goto".

Also, "movfw" isn't a pic instruction I know - do you mean "movwf" or "movff"?

Like I said earlier - before trying to debug the lookup table, just send one byte to the motor drive port to find out if the motors will turn at all. Try putting something like this at the very top of the "Main Program":
Code:
                movlw    b'00111010'
                movff    WREG, PORTA
Here            goto     Here
All it will do is send a byte out the motor drive port, but this will help you find out if the motor will run at all, and allow you to check the port pins with a meter.
 
My motor started moving already! As for movfw its move file to W its a code that my teachers taught me. Thanks! I happen to found out that my wires were not soldered in properly. it was a careless mistake on my part. I am really happy that my motor started moving now for the real programming :( Can i ask you if i have any more questions in the coming weeks?
 
And what about that "return" statement in SENSOR_CHK ?
 
No, it returns from a SUBROUTINE - the ones that you "call", not "goto". And it will cause problems if you use outside a subroutine, because it loads the program counter and stack registers.
 
With this you probably want to replace that "return" with a "goto Start". This makes a loop. Programmers call this loop the "main driver loop". From this loop you call your subroutines, like SENSE. SENSE returns to the loop, at the next instruction after the "call".
 
Last edited:
Oh ya so when i goto start it will loop through the whole program! thanks! now i better get started on writing the real part of the program. Connect the motor the the 4 top and 4 bottom sensors! :)
 
Last edited:
You got it, good luck and happy robotting.
 
Hey i met up with another problem with my program.





; Program: [Stepper_Motor.asm]; Written by: Foo DF; Date: 29-Aug-2006
; This program configures PortC RC0-7 as OUTPUT to control the L293D Motor Control Board
;
; ************* HEADER **************************************************************
LIST p=16F876 ;PIC16F876 is the target processor
#include "P16F876.INC" ;Include header file
__config H'3F3A' ;Osc=XT; WDT=Off;
;Power Up Timer=Off; Brown Out Detect=Off
;LVP=Disabled, Flash Program Write=Enabled,
;Data EE Read Protect=Off; Code Protect=Off
;
;************** File Register Variable use ******************************************
cblock H'20'
NUMBER
d1 ;use for Delay subroutine
d2
d3
d4
SENSOR
BOTTOM
sensor
time_on
endc
;
; ************* Reset Vector ********************************************************
org H'00'
clrf STATUS
movlw 0x00
movwf PCLATH
goto Initial
;



;******************* Port A initialisation*******************************

initial bcf STATUS , RP0
clrf PORTA
banksel ADCON1
movlw B'00000110'
movwf ADCON1
movlw B'00000000'
movwf TRISA
; ************* Port B and C I/O Initialisation *************************************
Initial ;
bsf STATUS,RP0 ; Select BANK 1
; banksel TRISB
movlw B'00000000' ; Set PortB to O/Ps
movwf TRISB ; PortB setting is done!
movlw B'11111111' ; Set PortC to I/Ps
movwf TRISC ; PortC setting is done!
movlw B'00000000' ; Set PortA to O/Ps
movwf TRISA ; PortB setting is done!
movlw B'00000110'
movwf ADCON1

;
; ************* Main Program *******************************************************
banksel PORTA
;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
Start

clrf PORTA
clrf PORTB
clrf PORTC
call SENSOR_CHK
;movlw b'00110000'
;movwf PORTAw
;call SENSE
; call TOPP
;goto Start
;test
;movfw PORTC
;movwf PORTB
;call SENSOR_CHK
;goto test




SENSOR_CHK

movlw b'00110000'
movwf PORTA
call Delay_50us
movfw PORTC
movwf SENSOR
call SENSE
call BTM
movwf PORTA
return

;Forward movlw b'00111101'
; movwf PORTA
; return

;Reverse movlw b'00110111'
; movwf PORTA
; return

;Right_turn movlw b'00111100'
; movwf PORTA
; return

;Left_turn movlw b'00110001'
; movwf PORTA
; return


;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&



SENSE
; clrf PORTA
clrf PORTB
movfw PORTC
movwf SENSOR
movwf PORTB
return

;TOPP
; movfw SENSOR
; andlw b'11110000'
; movwf TOP
; swapf TOP,w
; call Top_Table
; movwf PORTA
; return


BTM
movfw SENSOR
andlw b'00001111'
movwf BOTTOM
call BTM_Table
return

;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

Delay_50us movlw 0x0F
movwf d1

again3 decfsz d1,f
goto again3

return
;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

;Top_Table

; addwf PCL
; retlw b'00110000' ;stop (Stop,stop)(0000)
; retlw b'00111000' ;Left Turn (stop,forward)(0001)
; retlw b'00110010' ;right turn (move,stop)(0010)
; retlw b'00111111' ;reverse (reverse, reverse)(0011)
; retlw b'00111000' ;turn left (stop,move)(0100)
; retlw b'00111010' ;forward (move,move)(0101)
; retlw b'00110010' ;turn right(move,stop)(0110)
; retlw b'00111000' ;turn left(stop,move)(0111)
; retlw b'00110010' ;turn right(move stop)(1000)
; retlw b'00110010' ;turn right(move stop)!1001)
; retlw b'00110010' ;turn right(move stop)(1010)
; retlw b'00110010' ;turn right(move stop)(1011)
; retlw b'00111010' ;forward (move move)(1100)
; retlw b'00111000' ;turn left (stop move)(1101)
; retlw b'00110010' ;turn right (move stop)(1110)
; retlw b'00111010' ;move forward (move move)(1111)





BTM_Table
addwf PCL
retlw b'00111101' ;forward (0000)
retlw b'00111100' ;right (0001)
retlw b'00110001' ;left (0010)
retlw b'00111101' ;forward (0011)
retlw b'00111101' ;forward (0100)
retlw b'00111100' ;right (0101)
retlw b'00110001' ;left (0110)
retlw b'00111101' ;forward (0111)
retlw b'00111101' ;forward (1000)
retlw b'00111100' ;right (1001)
retlw b'00110001' ;left (1010)
retlw b'00111101' ;forward (1011)
retlw b'00111101' ;forward (1100)
retlw b'00111100' ;right (1101)
retlw b'00110001' ;left (1110)
retlw b'00110000' ;stop (1111)



; ************* End of the program ************************************************
END ;End of the program




this is what i have come out with so far. it is able to move forward , reverse, turn left and turn right. The sensors are all connected to the LEDs.
However when i try to piece the bottom sensors to move the motors, nothing happen.

The program should be running like this
Call sensor_check ( this will call the sensor to detect, lighting up the LEDs)-> goto sense( checking if its black or white at the bottom sensors. if all 4 sensors detect black it will stop the buggy-> BTM ( where this will call the btm lookup table)-> Btm lookup table.
This is what i thought should happen but the buggy moves but when all 4 of the bottom sensors detect black it still doesnt stop.

some help please :(
 
Great progress!

Have you got a red or green "indicator" led on it? If you don't have one, find a spare port pin and hook one up. You need a way for it to blink a light to tell you something happened.

You write a very simple program to check just one sensor, and light the indicator led if it is on. Something like:

Code:
check_loop       btfsc  sensor_1         ;sensor on?
                 goto   sensor_on        ;yes, go light the indicator led
                 bcf    indicator_led    ;no, unlight indicator led
                 goto   check_loop       ;return to test loop
sensor_on        bsf    indicator_led    ;switch indicator led on
                 goto   check_loop       ;return to test loop

When the first sensor is on, it lights the indicator, otherwise it is off. You then try this with each of the 4 sensors - it is not enough to check voltages, you must make sure the processor can read the sensors because sometimes a port is not initialized correctly. The indicator led will also help find other problems, it can help debugging the lookup table and a thousand other things.
 
hmm! Yes i got a red and yellow led, 4 red 4 yellow leds. . check_loop is for checking the sensor , which is similar to my sensor check right?
what about sensor_on? sorry i am really not very good with this programming. But i have check all my sensors, which are all working fine. I checked it by using this code

test
;movfw PORTC
;movwf PORTB
;call SENSOR_CHK
;goto test

i think i explained my buggy abit wrongly. its a buggy, 2 wheel. 2 motor. 4 infra red sensor which are the top, and 4 line sensor which are the bottom to sense black or white.

if it sense all black it will stop moving. Is my codes which i have done so far correct? As in i am quite sure there are some minor or maybe even major problems, but i just cant find them
 
A semicolon comments out the rest of the line. When the compiler hits a ";" it will stop compiling. They are only used for comments in this kind of assembly program.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top