View Full Version : help with PIC16F628 conditional program
joseph
- 4th July 2010, 15:21
i'm having problem working with a conditional program,
@ DEVICE PIC16F628A, INTRC_OSC_NOCLKOUT, WDT_OFF, PWRT_OFF, MCLR_OFF,PROTECT_ON,CPD_ON, BOD_OFF, LVP_OFF
DEFINE OSC 4
CMCON = 7
VRCON = 0
TRISA = 95
TRISB = 0
PORTB = 0
GS1 var PORTA.0
GS2 var PORTA.1
TEMP var PORTA.2
FWD VAR PORTA.3
REvs VAR PORTA.4
Neut var PORTA.7
forward var PORTB.0
revers var PORTB.1
one var PORTB.2
two var PORTB.3
three var PORTB.4
starterd var PORTB.5
start: IF Neut = 1 then
low forward
low revers
else
if (FWD = 1) and (REvs = 0) then
low revers
high forward
else
low revers
low forward
if (FWD = 0) AND (REvs = 1) then
low forward
high revers
endif
endif
endif
goto start
end
i need to monitor all the possible conditions in my input then ouput the right combination following this table.
------ INPUTS-------|-----OUTPUTS-----
FWD---Neut--REvs-|---forward---revers
--0-------0------1---|------0-----------1
--1-------0------0---|------1-----------0
--0-------1------0---|------0-----------0
--0-------1------1---|------0-----------0
--1-------1------0---|------0-----------0
also i have problem on making PORTA.7 work as an input
i plan to add more functions when this part worked
TIA.
Acetronics2
- 4th July 2010, 16:38
i'm having problem working with a conditional program,
------ INPUTS-------|-----OUTPUTS-----
FWD---Neut--REvs-|---forward---revers
--0-------0------1---|------0-----------1
--1-------0------0---|------1-----------0
--0-------1------0---|------0-----------0
--0-------1------1---|------0-----------0
--1-------1------0---|------0-----------0
also i have problem on making PORTA.7 work as an input
TIA.
Hi, joseph
@ first ...
your motor must be powered only if ( FWD ^ REVS = 1 ) AND ( NEUT = 0 ) ... ELSE outputs OFF
after that
forward = FWD and reverse = NOT forward ...
what gives us ...
IF ( FWD ^ REVS ) AND NOT NEUT THEN
forward = FWD : reverse = NOT forward
ELSE
forward = 0 : reverse = 0
ENDIF
Instead of writing :
TRISA = 95
Write
TRISA = % 01011111 ' 95 in binary
And you see instantly ... you've set Porta.7 as an output ...
Alain
joseph
- 4th July 2010, 17:21
sir i tried to compile this
@ DEVICE PIC16F628A, INTRC_OSC_NOCLKOUT, WDT_OFF, PWRT_OFF, MCLR_OFF,PROTECT_ON,CPD_ON, BOD_OFF, LVP_OFF
DEFINE OSC 4
CMCON = 7
VRCON = 0
TRISA = %01011111
TRISB = 0
PORTB = 0
GS1 var PORTA.0
GS2 var PORTA.1
TEMP var PORTA.2
FWD VAR PORTA.3
REvs VAR PORTA.4
Neut var PORTA.7
forward var PORTB.0
revers var PORTB.1
one var PORTB.2
two var PORTB.3
three var PORTB.4
starterd var PORTB.5
start: IF ( FWD ^ REVS ) AND NOT NEUT THEN
forward = FWD : revers = NOT forward
ELSE
forward = 0 : revers = 0
ENDIF
goto start
end
it compiles but does not work
this part is not clear to me:
IF ( FWD ^ REVS ) AND NOT NEUT THEN
forward = FWD : revers = NOT forward
ELSE
forward = 0 : revers = 0
ENDIF
thanks for the reply :D
joseph
- 4th July 2010, 17:37
IF ( FWD ^ REVS ) AND NOT NEUT THEN
forward = FWD : revers = NOT forward
ELSE
forward = 0 : revers = 0
ENDIF
IF ( FWD ^ REVS ) AND NOT NEUT THEN <---- do this mean, if FWD and REVS are opposite and NEUT is low then
forward = FWD : revers = NOT forward <---- forward is equal to what is FWD and revers is equal to opposite of forward else
forward = 0 : revers = 0 <---- turn the outputs low
joseph
- 4th July 2010, 18:00
RA7 won't be an input until i independently configured it as an input so i placed this line
INPUT neut :confused:
@ DEVICE PIC16F628A, INTRC_OSC_NOCLKOUT, WDT_OFF, PWRT_OFF, MCLR_OFF,PROTECT_ON,CPD_ON, BOD_OFF, LVP_OFF
DEFINE OSC 4
CMCON = 7
pause 1
VRCON = 0
pause 1
TRISA = 95
TRISB = 0
PORTB = 0
GS1 var PORTA.0
GS2 var PORTA.1
TEMP var PORTA.2
FWD VAR PORTA.3
REvs VAR PORTA.4
Neut var PORTA.7
forward var PORTB.0
revers var PORTB.1
one var PORTB.2
two var PORTB.3
three var PORTB.4
starterd var PORTB.5
input neut
start: IF ( FWD ^ REVS ) and not neut THEN
forward = FWD : revers = NOT forward
ELSE
forward = 0 : revers = 0
ENDIF
goto start
end
this works, but for some reason instead of revers/portb.0 going steady high when the input condition rules i got some oscillations, the led connected on this on my simulation blinks :confused:
thanks :D
Acetronics2
- 4th July 2010, 18:28
RA7 won't be an input until i independently configured it as an input so i placed this line
INPUT neut
Did you notice IF you want Porta.7 as an input ... the TRIS value must be > 127 ???
here you have 95 ... tadaaaa ...
this works, but for some reason instead of revers/portb.0 going steady high when the input condition rules i got some oscillations, the led connected on this on my simulation blinks
no reason for that ... simulators are just toys :p, so do not believe what they say ... :rolleyes:
may be you could add some debouncing to your inputs ... but simulation :eek: won't show anything.
Alain
joseph
- 4th July 2010, 18:48
:eek: i didn't notice that
here's a screenshot:
http://img231.imageshack.us/img231/5378/pulses.jpg
this happens to all ports on portb except rb0 where i get a straight line
thanks :D
Acetronics2
- 4th July 2010, 19:14
Could you post your ISIS file here ??? ( xxx.DSN )
Alain
joseph
- 4th July 2010, 19:29
here
direct link:
http://dc187.2shared.com/download/D7VAeRiX/ecu.DSN?tsid=20100704-142736-ef003566
if the direct link doesn't work, here:
http://www.2shared.com/file/D7VAeRiX/ecu.html
thanks :D
Acetronics2
- 5th July 2010, 10:19
Hi, Joseph
Definitly a simulator issue ... :rolleyes: ( one MORE for Proteus ... :eek: )
Just run your program in MPSIM ( MPLAB Simulator ) in step by step mode, and you won't see any change for the output ...
I did told you Sims are toys ... :D , forget about them !!!
BTW, Correct code is:
IF ( FWD ^^ REVS ) AND NOT NEUT THEN
forward = FWD : revers = NOT forward
ELSE
forward = 0 : revers = 0
ENDIF
Doesn't change anything ... but brain satisfying !!! ( it's a logical EXOR, and not a bitwise one )
Alain
Darrel Taylor
- 5th July 2010, 12:20
Joseph,
Add some resistors in series with the LED's that are being overdriven.
It will stop blinking.
Proteus Rules.
MPSIM is Lame.
Acetronics2
- 5th July 2010, 12:53
Joseph,
Add some resistors in series with the LED's that are being overdriven.
It will stop blinking.
Proteus Rules.
MPSIM is Lame.
Hi, Darrel ...
did you try to close Forward, then the two other switches ( or/and ) ... :eek:
you said " lame " ??? ... funny ...
Alain
Judge of peace: my EasyPic5 ... Proteus is OUT !!!
joseph
- 5th July 2010, 13:54
Joseph,
Add some resistors in series with the LED's that are being overdriven.
It will stop blinking.
Proteus Rules.
MPSIM is Lame.
whoa it seems that proteus simulates the overload protection, it worked
thanks Darrel, thanks Alain :D
i will try to complete the code. i'l update this thread soon
Powered by vBulletin® Version 4.1.7 Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.