Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Tools
Old 3rd October 2009, 02:50 PM   #1
Default Help with MikroBasic program misbehaving please

Hi again guys,

due to all the previous help I now have a somewhat working program but it is doing something I can't figure out and am only a beginner with Pics.

When I turn on I expected the program to wait until a button (up or down) was sent high ( I have internal pullups off and the pins pulled low on my dev board - EasyPic5) but the prog just runs through past the button command to the pulses and never stops.

What am I doing wrong?

I am using a 12F629 Pic btw, here is the code.

program stepper992

main:

DIM t as byte
WPU = %00000000 'turn off weak pullups
TRISIO =%00101000 'set GPIO 0,1,2,4 as out and 3,5 as inputs
GPIO = %00000000 'turn off all outputs
CMCON =0x07 'set comparator to off
IF BUTTON(GPIO,5,1,0)then GOTO up 'check for button press for up
END IF
IF BUTTON(GPIO,3,1,0)then GOTO down 'check for button press for down
END IF
GOTO main 'if no presses then restart

up:
FOR t = 1 to 5
GPIO = %00010001 'Set on bits for this pulse
delay_ms (110)
GPIO = %00000011 'Set on bits for this pulse
DELAY_MS (110)
GPIO = %00000110 'Set on bits for this pulse
delay_ms (110)
GPIO = %00010100 'Set on bits for this pulse
DELAY_MS (110)
NEXT t

GOTO main 'After completing pulses return to start

down:
FOR t = 1 to 5
GPIO = %00010100 'Set on bits for this pulse
delay_ms (110)
GPIO = %00000110 'Set on bits for this pulse
DELAY_MS (110)
GPIO = %00000011 'Set on bits for this pulse
delay_ms (110)
GPIO = %00010001 'Set on bits for this pulse
DELAY_MS (110)
NEXT t

GOTO main 'After completing pulses return to start
end.

Thanks for looking........Al
__________________
Founder member of the Campaign to do Something about the nonexistent word "Somethink"
bigal_scorpio is offline  
Old 3rd October 2009, 03:02 PM   #2
Default

I don't know what the button function does and so can't comment. However, you could try something like if(GPIO&%00100000) instead of IF BUTTON(GPIO,5,1,0). I'm assuming that IF BUTTON(GPIO,5,1,0) reads a button on GPIO 5. As both your functions have delays there is no need for any debounce.

Mike.
Pommie is online now  
Old 3rd October 2009, 04:20 PM   #3
Default

Quote:
Originally Posted by Pommie View Post
I don't know what the button function does and so can't comment. However, you could try something like if(GPIO&%00100000) instead of IF BUTTON(GPIO,5,1,0). I'm assuming that IF BUTTON(GPIO,5,1,0) reads a button on GPIO 5. As both your functions have delays there is no need for any debounce.

Mike.
Mike the IF BUTTON(GPIO,5,1,0). is checking for low on transition from 1 to 0 (release of button), GPIO,5 is inverted:
I think the OP would want
Code:
main:

DIM t as byte
WPU = %00000000 'turn off weak pullups
TRISIO =%00101000 'set GPIO 0,1,2,4 as out and 3,5 as inputs
GPIO = %00000000 'turn off all outputs
CMCON =0x07 'set comparator to off
IF BUTTON(GPIO,5,0,1)then GOTO up 'check for button press for up
END IF
IF BUTTON(GPIO,3,0,1)then GOTO down 'check for button press for down
END IF
GOTO main 'if no presses then restart

up:
FOR t = 1 to 5
GPIO = %00010001 'Set on bits for this pulse
delay_ms (110)
GPIO = %00000011 'Set on bits for this pulse
DELAY_MS (110)
GPIO = %00000110 'Set on bits for this pulse
delay_ms (110)
GPIO = %00010100 'Set on bits for this pulse
DELAY_MS (110)
NEXT t

GOTO main 'After completing pulses return to start

down:
FOR t = 1 to 5
GPIO = %00010100 'Set on bits for this pulse
delay_ms (110)
GPIO = %00000110 'Set on bits for this pulse
DELAY_MS (110)
GPIO = %00000011 'Set on bits for this pulse
delay_ms (110)
GPIO = %00010001 'Set on bits for this pulse
DELAY_MS (110)
NEXT t

GOTO main 'After completing pulses return to start
end.
this should check gpio3 to see if it went high

Last edited by be80be; 3rd October 2009 at 04:56 PM.
be80be is offline  
Old 3rd October 2009, 04:23 PM   #4
Default

He states that he has the pins pulled low.

Mike.
Pommie is online now  
Old 3rd October 2009, 04:26 PM   #5
Default

If he has the pin pulled low and is looking for a low then of course it will run right through and not wait...
__________________
Mike2545
Mike2545 is offline  
Old 3rd October 2009, 04:32 PM   #6
Default

If the button function checks for a transition then it should always stop. One of the reasons I don't use canned functions, normally quicker to write my own and that way, I know exactly what they do.

Mike.
Pommie is online now  
Old 3rd October 2009, 04:34 PM   #7
Default

mike2524 that's what it was doing
I think this is what the OP needs
Code:

IF BUTTON(GPIO,5,0,1)then GOTO up 'check for button press for up
END IF
IF BUTTON(GPIO,3,0,1)then GOTO down 'check for button press for down
END IF 
I would do it like this
Code:
        IF GPIO.B5 =1 then goto up
        elseif GPIO.B3 =1 then goto down
        endif

Last edited by be80be; 3rd October 2009 at 04:47 PM. Reason: Not thinking LOL
be80be is offline  
Old 3rd October 2009, 04:48 PM   #8
Default

The Op is just testing for low state he needed to test for High state
be80be is offline  
Old 3rd October 2009, 05:39 PM   #9
Default

Hi again guys,

I have tried ALL the suggestions but still no joy.

Burt's code didn't compile as MB does not like the "GPIO.B3 = 1" until I removed the .B so there must be a difference in the software he is using.

Even then with Burt's code modified it then ignored either button altogether.

I have taken on board what was pointed out about the state bit and realised it should be BUTTON GPIO, 5,1,1 and not 5,1,0 as I had it, but still fails!

I have noticed that if I remove the button reference to pin 3 then the program works fine, so I am beginning to wonder if its something to do with the MasterClear pin that I have missed?

Should I have set that to anything particular?

Thanks............Al
__________________
Founder member of the Campaign to do Something about the nonexistent word "Somethink"
bigal_scorpio is offline  
Old 3rd October 2009, 06:12 PM   #10
Default

Are you using MikroBasic or MikroBasic pro there not the same the pro you have more to set up
+

Last edited by be80be; 3rd October 2009 at 06:15 PM.
be80be is offline  
Old 3rd October 2009, 06:55 PM   #11
Default

this is with microbasic pro
Code:
program steppertest

' Declarations section


dim temp as word

WPU = %00000000 'turn off weak pullups
TRISIO =%00101000 'set GPIO 0,1,2,4 as out and 3,5 as inputs
GPIO = %00000000 'turn off all outputs
CMCON =0x07 'set comparator to off
main:


while true
IF GPIO.5 =1 then GOTO up 'check for button press for up
END IF
IF GPIO.3 =1 then GOTO down 'check for button press for down
END IF
GOTO main 'if no presses then restart

up:
FOR temp = 1 to 5
GPIO = %00010001 'Set on bits for this pulse
delay_ms (110)
GPIO = %00000011 'Set on bits for this pulse
DELAY_MS (110)
GPIO = %00000110 'Set on bits for this pulse
delay_ms (110)
GPIO = %00010100 'Set on bits for this pulse
DELAY_MS (110)
NEXT temp

GOTO main 'After completing pulses return to start

down:
FOR temp = 1 to 5
GPIO = %00010100 'Set on bits for this pulse
delay_ms (110)
GPIO = %00000110 'Set on bits for this pulse
DELAY_MS (110)
GPIO = %00000011 'Set on bits for this pulse
delay_ms (110)
GPIO = %00010001 'Set on bits for this pulse
DELAY_MS (110)
NEXT temp

GOTO main 'After completing pulses return to start
wend
end
make sure you turn mclr off

Last edited by be80be; 3rd October 2009 at 06:57 PM.
be80be is offline  
Old 3rd October 2009, 07:06 PM   #12
Default

Quote:
Originally Posted by be80be View Post
Are you using MikroBasic or MikroBasic pro there not the same the pro you have more to set up
+
Hi Burt,

Its Mikrobasic mate, not pro, I didn't even know about the pro. Is it any better?

Also I may have solved the problem! If I pull UP GPIO3 and pull DOWN GPIO5, then check for the opposite on button it seems to work!

But if I pull BOTH UP or DOWN then the problem is back! Weird?

So I am now baffled about something else then, but at least I can make up the circuit now eh.

Al
__________________
Founder member of the Campaign to do Something about the nonexistent word "Somethink"
bigal_scorpio is offline  
Old 3rd October 2009, 07:58 PM   #13
Default Oh no!!!!!!

Hang on folks!

The switches seemed ok, in the fact that it didn't just run at first putting a high on 5 worked when it was tied to gnd and the button command was looking for a high.

Problem is that putting a gnd on 3 even though it is pulled high does not start the pulses, even though I have 3 pulled high and I can see the relevant led on 3 going out and the button command is looking for a low.

Even more baffled............Al
__________________
Founder member of the Campaign to do Something about the nonexistent word "Somethink"

Last edited by bigal_scorpio; 3rd October 2009 at 07:59 PM.
bigal_scorpio is offline  
Old 3rd October 2009, 09:15 PM   #14
Default Time to call it a day!

Hi guys,

Thanks for all the help, I've sorted it now!

Migrated to a 16F630 and not a hitch!

Shame though as Ithought the 12F629 had allI needed = 4 outputs and 2 inputs. Still wondering why it didn't work but never mind.

Though if anyone does has a definitve answer I would still be interested.

Thanks again........Al
__________________
Founder member of the Campaign to do Something about the nonexistent word "Somethink"
bigal_scorpio is offline  
Old 3rd October 2009, 09:26 PM   #15
Default

Did you turn mclr off you set it here
Attached Thumbnails
Help with MikroBasic program misbehaving please-try_this.png  
be80be is offline  
Reply

Tags
mikrobasic, misbehaving, program

Thread Tools
Display Modes


Similar
Title Starter Forum Replies Latest
Whats wrong with my program? MikroBasic bigal_scorpio Micro Controllers 18 3rd October 2009 03:35 AM
Mikrobasic help.. mramos1 Micro Controllers 11 12th November 2008 10:46 AM
mikroBasic compiler... simrantogether Micro Controllers 3 27th October 2007 10:19 AM
mikroBasic and Proton gramo Micro Controllers 0 17th March 2007 02:47 PM



All times are GMT. The time now is 06:03 AM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker