PDA

View Full Version : 12f675 making me a crazy person



Meriachee
- 16th September 2009, 02:11
Hi folks,

Here is some code. I am looking for some wisdom. It runs great. ONCE. It appears that the variable is either never counting to "300", or not getting reset to "10". The input causes the other output to go high, as it should, in a very repeatable manner.
Ideas?
Gary

DEFINE OSC 4
ANSEL=%00000000
CMCON=7
trisio = %00000100

' Chubb input gpio.5
' Output to panel - Trig var gpio.2
' Photo Guy gpio.4
input gpio.5
Chubb var gpio.5
output gpio.4
Led var gpio.4
low led
output gpio.2
Trig var gpio.2
low trig

'Variable for the photo guy
x var word
x = 10

' Test the photo guy
PAUSE 2000
HIGH LED
PAUSE 250
LOW LED
PAUSE 250
HIGH LED
PAUSE 250
LOW LED
PAUSE 2000

'start here
loop:
if Chubb = 0 then
high trig
endif

if Chubb = 0 then
if X < 11 then
X = 12
gosub cola
endif
endif

if chubb = 1 then
low trig
endif

if x > 11 then
x = (x + 1)
endif

if x >= 300 then
x = 10
endif

if x = 100 then
GOTO foto1
endif

pause 100
goto loop
end


foto1:
high led
pause 100
low led
pause 250
high led
pause 100
low led
return
goto loop

cola:
high led
pause 100
low led
return
goto loop
end

mackrackit
- 16th September 2009, 02:24
You have RETURNs with GOTOs .
Try going to the subroutines with GOSUB and then RETURN. Not both GOTO and RETURN.

Meriachee
- 16th September 2009, 02:29
Dave,

There are two iterations of that, in a somewhat silly attempt to validate that the RETURN was working - or failing. No difference. Irrespective, they've been removed.
The TRIG output goes high and low exactly as it should, when the CHUBB input goes high or low. That tells me the loop is looping. (Loopy?)
After startup, the TWO led routines do work. ONCE.
I can't see anything that is unhappy in the counting, the compiler likes it, and it seems to read ok, it just doesn't work.

What the heck....

Archangel
- 16th September 2009, 03:13
Hi Gary,
try ADCON0 = 0

Meriachee
- 16th September 2009, 04:23
Joe,

No better.
This is very very strange....

Jerson
- 16th September 2009, 04:34
DEFINE OSC 4
ANSEL=%00000000
CMCON=7
trisio = %00000100

' Chubb input gpio.5
' Output to panel - Trig var gpio.2
' Photo Guy gpio.4
input gpio.5
Chubb var gpio.5
output gpio.4
Led var gpio.4
low led
output gpio.2
Trig var gpio.2
low trig

'Variable for the photo guy
x var word
x = 10

' Test the photo guy
PAUSE 2000
HIGH LED
PAUSE 250
LOW LED
PAUSE 250
HIGH LED
PAUSE 250
LOW LED
PAUSE 2000

'start here
loop:
if Chubb = 0 then
high trig
if X < 11 then
X = 12
gosub cola
endif
else
low trig
endif

if x > 11 then
x = (x + 1)
endif

if x >= 300 then
x = 10
endif

if x = 100 then
GOTO foto1
endif

pause 100
goto loop
end


foto1:
high led
pause 100
low led
pause 250
high led
pause 100
low led
goto loop

cola:
high led
pause 100
low led
return
end

This should work

mackrackit
- 16th September 2009, 04:46
Something is strange.

I just tried your code for giggles and this is what happened.


Executing: "C:\PBP\PBPW.EXE" -ampasmwin -oq -z -p12F675 "C:\MAC\PIC PROGS\TEST\12f675.bas"
PICBASIC PRO(TM) Compiler 2.50c, (c) 1998, 2008 microEngineering Labs, Inc.
All Rights Reserved.

ERROR: RAM END must be defined.
ERROR: RAM BANKS must be defined.
ERROR: No LIBRARY statement or LIBRARY parameter.
ERROR: No LIBRARY statement or MACRO parameter.
ERROR: Unable to open file PBPMAC.INCHalting build on first failure as requested.
BUILD FAILED: Tue Sep 15 20:40:41 2009

It is not your code, something else is the matter. A lot of folks seem to be having problems with this chip....

Meriachee
- 16th September 2009, 06:11
Dave,

That's interesting.....
I tried with various settings in the config, watchdogs on and off, etc. I always use a 4k7 from MCLR to +5. That's just a "standard" here, and I always use the internal osc, and have never strayed far from 4mhz, so suffice to say that the config is pretty "plain".

Most of the timing floats someplace around variations of 1000 so that an aprox count in seconds should tell me when things happen.

The ONLY change here since the last functional chip is 4.31 software on the MELabs Programmer. And it's interesting that there's another thread nearby that the fellow is using the same programmer (although a much older code) and having "odd" issues.

Once again I've shipped it over to MELabs with a request for help.

Thanks to all who have responded. This kind of discussion is enlightening..

Cheers
Gary

Meriachee
- 16th September 2009, 06:15
Jerson,

The only change I see in your suggestion is an "else" for the Chubb. That part of the code is the only part that works repeatedly....

There is something whacked in the way the counter stuff is getting either compiled or put to the chip, or interpreted by the chip. That part is going off into lala land.

Gary

Acetronics2
- 16th September 2009, 08:57
Hi,

Here is the V2.60 Answer :



C:\PROGRAM FILES\MICROCHIP\MPLAB IDE\PROJETS\MERIACHEE.BAS ERROR Line 63: Syntax error.
C:\PROGRAM FILES\MICROCHIP\MPLAB IDE\PROJETS\MERIACHEE.BAS ERROR Line 76: Syntax error.
C:\PROGRAM FILES\MICROCHIP\MPLAB IDE\PROJETS\MERIACHEE.BAS ERROR Line 83: Syntax error.
C:\PROGRAM FILES\MICROCHIP\MPLAB IDE\PROJETS\MERIACHEE.BAS ERROR Line 34: LOOP without a matching DO.Halting build on first failure as requested.
BUILD FAILED: Wed Sep 16 09:47:12 2009



Translated : Do not use " Loop " but "LoopA" ...

No more error after changing " loop "



Considering your program behaviour ...

The IF THEN sequences looks highly Hazardous to me ...

I'd recommend you to make it somewhat clearer ... but it's me !!!

Alain

Jerson
- 16th September 2009, 09:07
Gary,

Can you add the following lines to your code and compile it with the PM assembler like this
C:\PBP\PBPW.EXE -apm -p12F675 "C:\MAC\PIC PROGS\TEST\12f675.bas



@ device INTRC_OSC_NOCLKOUT, WDT_OFF
@ device MCLR_OFF, PWRT_ON
@ device CPD_ON, PROTECT_ON


This will embed the configuration into the HEX file. The way you have it now, I have simulated the code and find it is incrementing and repeating after 300. If you want the code to block per trigger of Chubb, you need to add the following to your trigger code



if Chubb = 0 then
high trig
if X < 11 then
X = 12
gosub cola
while Chubb : wend ' wait while Chubb is 1
endif
else
low trig
endif


Good luck

Acetronics2
- 16th September 2009, 09:36
Jerson,

The only change I see in your suggestion is an "else" for the Chubb.

Gary

Not so sure ... you caught it !

the "foto1" Label MUST end with a " GOTO " ...

Lala land is the GOSUB result ...

Alain

Meriachee
- 16th September 2009, 16:21
Jerson,

That won't work. The Chubb needs to be high or low irrespective of the Led.

Alain,

P&J, toast and jam, goSUB and return. Can't change one without the other. Code works like a charm. It may not be elegant, but I'm not charging myself very much for it either... :)

Cheers
Gary

Jerson
- 16th September 2009, 17:06
Try this for the PM assembler. If you hold Chubb high, foto1 will fire repeatedly. Release Chubb and trig will go low

Enjoy



@ device INTRC_OSC_NOCLKOUT, WDT_OFF
@ device MCLR_OFF, PWRT_ON
@ device CPD_ON, PROTECT_ON

DEFINE OSC 4
ANSEL=%00000000
CMCON=7
trisio = %00000100

' Chubb input gpio.5
' Output to panel - Trig var gpio.2
' Photo Guy gpio.4
input gpio.5
Chubb var gpio.5
output gpio.4
Led var gpio.4
low led
output gpio.2
Trig var gpio.2
low trig

'Variable for the photo guy
x var word
x = 10

' Test the photo guy
PAUSE 2000
HIGH LED
PAUSE 250
LOW LED
PAUSE 250
HIGH LED
PAUSE 250
LOW LED
PAUSE 2000

'start here
loop:
if Chubb = 0 then
high trig
if X < 11 then
X = 12
gosub cola
endif
else
low trig
endif

if x > 11 then
x = (x + 1)
endif

if x >= 300 then
x = 10
endif

if x = 100 then
GOTO foto1
endif

pause 100
goto loop
end


foto1:
high led
pause 100
low led
pause 250
high led
pause 100
low led
goto loop

cola:
high led
pause 100
low led
return
end

Acetronics2
- 16th September 2009, 17:19
Code works like a charm.Gary

Hi, Gary

I did understand it was the reason for you to show it here ... sure !

Alain

mackrackit
- 16th September 2009, 17:55
Originally Posted by Meriachee

Code works like a charm.Gary

So you have it all figured out now? What did you do to fix it?

Meriachee
- 16th September 2009, 21:55
There was a goto a subroutine, and a return at the end of it. Funny how PBP doesn't understand that it was s'posta go back to where we left off. :)

The panel got installed this afternoon, and after a small expected timing change to the photoguy, it works like a charm.

Thanks for all the help.

Gary