Loop keeps repeating

Moderator: Benj

Post Reply
Dutch
Posts: 102
Joined: Mon Aug 19, 2013 8:38 am
Location: Netherlands
Has thanked: 24 times
Been thanked: 5 times
Contact:

Loop keeps repeating

Post by Dutch »

Hello,

While looking on the net for how PIC microprocessors work just out of interest and maybe how to program these for my hobby I found this great program Flowcode and a free downgraded trail version perfect for testing if it would suit my needs…

Because I have programmers at my disposal from my work like Pickit3 and a Galep-5 it’s fun to try and explore… I have read and played some already and found a goal to make.. I stumbled upon all kind of small issues but found most answers on this forum.. (watchdog timer, spaces in the filename (sigh … Grrr  ))

I now have something I cant get sorted and tried a lot. I made a program with two leds. One led (2) is lit when no input is given. When the input is switched ‘on’ the second led (1) pulses, together with led 2 on/off for 3 times and then both remain solid 'on' until the switch is released again.

When I run the program in demo it does exactly what I want (have found two ways to do that actually). But when I load the program in the PIC it keeps flashing like it does not see the ‘second part’ of the line where two leds need to stay solid ‘on’ until the switch is released. It ‘skips’ a part and starts it’s line from top again writing the line again resulting in a repeating flash. when I replace the last both leds solid on by a output and a delay it works but does not react on releasing the switch obviously.
Both loops separately programmed does work fine.
....... Help.
Attachments
Flowcode1.fcf
(10.5 KiB) Downloaded 279 times

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times
Contact:

Re: Loop keeps repeating

Post by kersing »

I think the watchdog timer could be an issue. If you do not reset the watchdog periodically it will reset the controller. Try setting it to 'off'.
In the Build menu, choose 'Project Options', Push 'Configure chip' and set 'Watchdog timer' to 'Off'.
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Loop keeps repeating

Post by medelec35 »

Hi Dutch, I was also going to mention Watchdog timer, but kersing beat me to it. That causes a fair amount of issues if left enable and not using clear watch dog commands like kersing has stated.
Having Auto clear watch dog enabled will only clear WDT when a delay is reached, or a delay within a component. EG LCD or RS232
So if you have a loop with no delays, watchdog will time out and reset microcontroller.

The only other pearls of wisdom I can give are:
If programming via ICSP using MCLR then disable Low Voltage programming.
otherwise your lose the use of RB4. That will not affect the program you posted, but may affect programs developed in the future that will rely on RB4.
Since you have Master clear enabled, make sure MCLR is tied to +5V (via say 33K resistor is using ICSP)

Martin
Martin

Dutch
Posts: 102
Joined: Mon Aug 19, 2013 8:38 am
Location: Netherlands
Has thanked: 24 times
Been thanked: 5 times
Contact:

Re: Loop keeps repeating

Post by Dutch »

Thanks guys. I'll try that tonight or maybe this afternoon at work when it lets me :wink: .
I remember from my first try's the PIC did not function right when i had WDT off so i left it on.

Maybe i need to read up about the WDT... :roll:

Spanish_dude
Posts: 594
Joined: Thu Sep 17, 2009 7:52 am
Location: Belgium
Has thanked: 63 times
Been thanked: 102 times
Contact:

Re: Loop keeps repeating

Post by Spanish_dude »

The watchdog timer is a timer, that when it reaches it's max value (or something like that) it resets the microcontroller.
This is used to prevent the microcontroller of getting stuck inside a loop (or something similar).

Let's say you have a program with a main loop and you are using the watchdog timer as a means to reset your microcontroller in case something goes wrong.
When everything works fine, you'll have to reset the watchdog timer from time to time (let's say at the end of your main loop).
If you don't do that then it's going to reset the microcontroller even though there's nothing wrong.

Think of it as some kind of a timeout, like it's used when sending/receiving data to/from RS232 and other.

- Nicolas

Dutch
Posts: 102
Joined: Mon Aug 19, 2013 8:38 am
Location: Netherlands
Has thanked: 24 times
Been thanked: 5 times
Contact:

Re: Loop keeps repeating

Post by Dutch »

Ah, thanks. That clarifies the dog thing. Sounds logical
Hope it solves my issue... W'll see tonight in a few

Dutch
Posts: 102
Joined: Mon Aug 19, 2013 8:38 am
Location: Netherlands
Has thanked: 24 times
Been thanked: 5 times
Contact:

Re: Loop keeps repeating

Post by Dutch »

Oke..Turned off the WDT. now only led 1 goes on without any flash when I press the switch, nothing further happens...So it reads the switch.. and gives an action but does not perform the loopcount..Hmm
what command am I forgetting here?

dazz
Posts: 1314
Joined: Sun Jan 15, 2012 3:15 pm
Has thanked: 474 times
Been thanked: 458 times
Contact:

Re: Loop keeps repeating

Post by dazz »

Hi
try disabling the decision branch in your loop that counts, up load to chip, is that closer to what you need ?

Regards
Dazz
To sign up to the V5 forum follow this link http://www.matrixmultimedia.com/forum_upgrades.php

Dutch
Posts: 102
Joined: Mon Aug 19, 2013 8:38 am
Location: Netherlands
Has thanked: 24 times
Been thanked: 5 times
Contact:

Re: Loop keeps repeating

Post by Dutch »

I'll try that tonight. (or already did, donno anymore :wink: )
I'm guessing the programm dont even reach the decision i put in that line but i'll take part's off untill things change

strange is that when i take the second loop (while switch = 1) out of the line and replace it by portA=3 and a 60 second delay (both leds on for 60 seconds) it runs. but that is not my goal.

Thanks for thinking with me here Dazz...! let you know.

Nice that something simple as this can be hard and kinda hairpulling if you dont know where to look anymore :lol:
On the other hand i learn from it.. just my other projects are at a standstill. this gotto work!

Dutch
Posts: 102
Joined: Mon Aug 19, 2013 8:38 am
Location: Netherlands
Has thanked: 24 times
Been thanked: 5 times
Contact:

Re: Loop keeps repeating

Post by Dutch »

Oke, it works :D .
combination of setting the WDT in off position at two places and a good check of the osc circuit.

I'm not ready yet with my idea's but lets search the max of the demo version...

Thanks for looking guys.

Post Reply