-
Very wierd problem
Hi folks,
I've scratched my head over this one for most of the day and after paring my original program down to the minimal number of lines, I'm still stuck. First, the code:
Code:
@ DEVICE INTRC_OSC, LVP_OFF, WDT_OFF, MCLR_OFF
count1 var word
init:
count1 = 0
check1:
if count1 = 0 then high 0
--------------
if count1 = 7 then
high 1
pause 20
low 1
endif
-------------
IF count1 = 20 then low 0
if count1 = 100 then
count1=0
else
count1 = count1 + 1
endif
pause 20 ' 20 ms increments
goto check1
This is essentially an LED flasher where I can control the duration and delay of the flashes but substituting different numbers in the "if count1=" lines. Hopefully it's pretty easy to follow. Initially, ignore the "if count1=7 ... endif" lines.
When I run this on my 16F628, I expect to see my LED flash at a constant rapid rate. When count1=0, the LED goes on. When count1=20 the LED goes off. When count1=100 we start all over again.
What actually happens is that as soon as I power up the PIC, I get one flash, a short delay, then the rapid flashes I expect. It's this rogue flash at the beginning that I can't figure out.
Now about the HIGH 1/LOW 1 lines. I added these in to flash a "debugging" LED when count1 reached certain values. What I found was that, for the first cycle only, count1 was being reset when it reached 6! If I leave the code as shown (IF count1=7), the LED at 0 does it's initial wierd flash before running smoothly. If I change it to (IF count1=6), then I get a flash from BOTH LEDs during the first rogue flash.
Can anyone offer any explanation to this? After the first errant flash everything runs fine. I just don't get it.
Thanks for your time,
Jeff
-
hummmm. i'm not familiar with those High0, High1.... but PIC16F628 have internal comparator that must be disable pior to acces to those pin...
CMCON=7
what is High 1 refer to ... i mean on wich PORT ?
regards
-
HIGH and LOW set PORTB, but looking at the pbp manual, PORTB.0=1 would be a more effecient way to do this.
Well, I have a strange "fix" to my strange "problem." As it turns out, there is no problem at all. If I unplug and re-plug in the power connector, the LED does just what it is supposed do. So, the problem is generated when I re-program the PIC via the EPIC progammer's ICSP port.
This is very stange, but at least it ends up working the way its supposed it!
Thanks,
Jeff
-
well that's indeed an strange problem... humm... i always program my PIC in ICSP and never had any problem like this...
You don't get any error when programming ? can you try MCLR_ON and post results... i'm curious on that problems.
Maybe some others have an other idea here?