BasicMicroUK - Forums

www.basicmicro.co.uk
It is currently Sat Jan 20, 2018 8:00 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: hpwm reliable stop command
PostPosted: Thu Jan 26, 2012 3:39 am 
Offline
Citizen

Joined: Fri Jun 24, 2011 2:29 am
Posts: 27
Hello: I need to ensure my motors are stopped properly, however I have not found any hpwm code that I am certain will stop them and keep them stopped.
On startup of the atom sometimes the motors will run for a few seconds. Not often but it has happend enough times to worry me.
The following code lines are various attempts I have used to stop the motors.
After program variables and constants I do the following.
HPWM LEFTWHEEL, LEFTMOTORPERIOD, 0
HPWM RIGHTWHEEL, RIGHTMOTORPERIOD, 0
LOW P10
LOW P9
-------------------------

in my working code I use the above as my stopmotor subroutine.
I than initialize my display, send a few messages, and send another stopmotor command. I then send a message to turn on the ps2 hand controller. I have yet another stopmotor command.
Finally I get to the MAIN body of the program.
Now than, if the controller syncs properly and I am in analog mode everything is fine. The problem is if the controller is not synced, or the controller is not in analog mode, sometimes the motors will start up. I dont know how, or where they are getting the code to start? I only kept adding all the gosub stopmotors all over the place in an attempt to prevent this odd behavior.
I am posting the pertinent code below and apologize if it appears long. I will post the whole program if requested.
-kerry
--------------------------------

'START OF PROGRAM---------------------

gosub stopmotors
LOW DOMEMOTOR
serout 1,i9600,[0,0,0] ' suppposedly initializes the serial lcd chip
pause 100

GOSUB CLEARDISPLAY

serout 1,i9600,[1,1,"PROGRAM START"]
PAUSE 6000

' ps2 setup routines.
GOSUB CLEARDISPLAY
gosub stopmotors
serout 1,i9600,[1,1,"TURN ON "]
serout 1,i9600,[2,1,"HAND CONTROLLER "]
PAUSE 2000
low SEL
shiftout CMD,CLK,FASTLSBPRE,[$1\8,$43\8,$0\8,$1\8,$0\8] ;Config Enable
high SEL

low SEL
shiftout CMD,CLK,FASTLSBPRE,[$01\8,$44\8,$00\8,$01\8,$03\8,$00\8,$00\8,$00\8,$00\8] ;Set Mode and Fix(Analog
high SEL

pause 100

low SEL
shiftout CMD,CLK,FASTLSBPRE,[$01\8,$4D\8,$00\8,$00\8,$01\8,$ff\8,$ff\8,$ff\8,$ff\8] ;Vibration Enable
high SEL

low SEL
shiftout CMD,CLK,FASTLSBPRE,[$01\8,$43\8,$00\8,$00\8,$00\8,$00\8,$00\8,$00\8,$00\8] ;Config Exit
high SEL

'end of Ps2 setup


'-----------PS2 Data----------

GOSUB STOPMOTORS

GOSUB CLEARDISPLAY
serout 1,i9600,[1,1,"READY "]
'PAUSE 1000
gosub stopmotors
HPWM LEFTWHEEL, LEFTMOTORPERIOD, 0
HPWM RIGHTWHEEL, RIGHTMOTORPERIOD, 0


MAIN
GOSUB HOLOEYE
'BORED = BORED + 1
'IF BORED >= 250 THEN '500 = 1 MINUTE
'GOSUB RANDOMSOUND
'ENDIF
IF OVERTEMPLEFT = 0 THEN GOSUB OVERTEMP
IF OVERTEMPRIGHT = 0 THEN GOSUB OVERTEMP

high CLK 'Turns CLK High
GOSUB PS2_IN 'Takes the input of the PS2 controller

while(temp(1).bit0 = 0) 'SELECT BUTTON
GOSUB SELECTBUTTON
GOSUB PS2_IN
wend

while(temp(1).bit3 = 0) 'sTART BUTTON
GOSUB STARTBUTTON
GOSUB PS2_IN
wend

while(temp(1).bit4 = 0) 'If up arrow is active then robot goes into forward subroutine
GOSUB forwardFULL
GOSUB PS2_IN
wend
while(temp(1).bit5 = 0) 'If right arrow is active then robot goes into right subroutine
GOSUB RIGHTTURN90
GOSUB PS2_IN
wend

while(temp(1).bit6 = 0) 'If down arrow is active then robot goes into backward subroutine
GOSUB backUP
GOSUB PS2_IN
wend

while(temp(1).bit7 = 0) 'If left arrow is active then robot goes into left subroutine
GOSUB leftTURN90
GOSUB PS2_IN
wend


WHILE(temp(2).bit4 = 0) 'TRIANGLE is active
GOSUB TRIANGLE
GOSUB PS2_IN
WEND

WHILE(temp(2).bit5 = 0) ' O BUTTON
GOSUB OOOO
GOSUB PS2_IN
WEND

WHILE(temp(2).bit6 = 0)
GOSUB XXXX ' X BUTTON ACTIVE
GOSUB PS2_IN
WEND

WHILE(temp(2).bit7 = 0) 'Square is active
GOSUB SQUARE
GOSUB PS2_IN
WEND

WHILE(temp(2).bit3 = 0) 'RIGHT TRIGGER BUTTON ACTIVE
GOSUB STOPMOTORS
GOSUB PS2_IN
WEND

WHILE(temp(2).bit2 = 0)
GOSUB STOPMOTORS
GOSUB PS2_IN
WEND

WHILE(temp(2).bit1 = 0)
GOSUB STOPMOTORS
GOSUB PS2_IN
WEND

WHILE(temp(2).bit0 = 0)
GOSUB STOPMOTORS
GOSUB PS2_IN
wend
'---------NOT SURE WHY THE JOYSTICK CODE IS WRITTEN DIFFERENTLY

' low P9
' low P10
' low p11
' low p12


LEFT_JOY_X=(TEMP(5)) 'LEFT JOYSTICK X
LEFT_JOY_Y=(TEMP(6)) ' LEFT JOYSTICK Y


if left_joy_y <=115 then gosub forward '128 being nuetral, allow a dead zone
if left_joy_y >=140 then gosub backup '128 nuetral allow a dead zone
if left_joy_y >=116 and left_joy_y <=139 then gosub stopmotors

'if left_joy_y <=120 and left_joy_x <=120 then gosub leftturn
'if left_joy_y >=135 and left_joy_y >=135 then gosub rightturn

' if temp(2).bit7 = 0 THEN 'If Square is active then goes into line following mode
' GOSUB start ' Subroutine for line following
' endif

goto MAIN

STOPMOTORS

HPWM LEFTWHEEL, LEFTMOTORPERIOD, 0
HPWM RIGHTWHEEL, RIGHTMOTORPERIOD, 0
LOW P10
LOW P9
' TMRW.BIT0=0

BORED = 0

RETURN


Top
 Profile  
 
 Post subject: Re: hpwm reliable stop command
PostPosted: Wed Dec 18, 2013 2:35 am 
Offline
Site Admin
User avatar

Joined: Fri Apr 12, 2013 8:38 pm
Posts: 87
Location: Nottingham, England, UK
HI

Can you give an idea of how the hardware is set up on this example and maybe post the whole code,

A tip when posting code is to place the code between "{code} YOUR CODE {/code} as that will make it more readable, click on the Code box at the start of the POST MESSAGE box and then paste you program between the CODE commands, then it will show like this :-
Code:
Your Program will be shown here.

As the Atom is based on the Nano-X there may be a minor bug in the code of the IDE causing your problems and I have come across problems with PWM outputs when using SEROUT before so that may be something simple you can check,

Comment out all SEROUT commands and try the program again and see if you still get the problem,

Also the Basic Micro IDE does include a great Debug system that can be used to step through your program and you can see if a certain command is causing the problem,

If that fails I can simulate your set up on our PIC emulator and Logic Analyser and see what's causing the problem in this case and see if there is a simple fix,

I hope this helps,

Many Thanks

Dave
BasicMicroUK
www.basicmicro.co.uk


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

phpBB SEO