Initializing problem

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
Michaelt
Posts: 38
Joined: Sun Sep 23, 2012 9:46 am
Has thanked: 13 times
Contact:

Initializing problem

Post by Michaelt »

Hello and thanks for a superb forum.

I have made a Combined RGB controller and HIGH POWER Headlight for my mountainbike, i am using the pic 16F785 and i have a question about how i initialize the pic..

In the very top of my program i call a Initialize macro and underneth that call i enter a LOOP (while 1). and inside this loop all my programming is, now my problem is that the pic sometimes runs the initializing step in the middle of the program.

I am also using delays in the program, am i right to understand that the delays are freezeing the pic activity for the given time and then continuing, this means that the pic does not execute anything else while the delay is on.. i just thaught that maybe the delays could have something to do with restarting the pic :idea: ..

if needen i can upload my program,

Have a nice day
Regards Michael

User avatar
DavidA
Matrix Staff
Posts: 1076
Joined: Fri Apr 23, 2010 2:18 pm
Location: Matrix Multimedia Ltd
Has thanked: 58 times
Been thanked: 258 times
Contact:

Re: Initializing problem

Post by DavidA »

Hi Michael,

Are you turning the watchdog timer off in config settings?

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: Initializing problem

Post by Enamul »

Please post your program
Enamul
University of Nottingham
enamul4mm@gmail.com

Michaelt
Posts: 38
Joined: Sun Sep 23, 2012 9:46 am
Has thanked: 13 times
Contact:

Re: Initializing problem

Post by Michaelt »

the watchdog is disabled

here is my program, i have added some english comments hope it is not to confusing :D

Have a good weekend everyone
Attachments
Flashlight and RGB.fcf
(63.91 KiB) Downloaded 271 times

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: Initializing problem

Post by LeighM »

Your Timer Interrupt only needs to be enabled once, so best to move it outside your “While 1” loop.
Also you might need to check the properties, as the Prescaler is currently set to 1:1 so has a very high interrupt frequency.

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: Initializing problem

Post by Enamul »

Can you please try now and let us know. You interrupt frequency is really high.
Attachments
Flashlight and RGB.fcf
(63.93 KiB) Downloaded 271 times
Enamul
University of Nottingham
enamul4mm@gmail.com

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: Initializing problem

Post by medelec35 »

What I would do (once you have chaeked timer interrpt setting are correct) is check if chip is resetting.
To this could be done by setting at a fixed LED flash pattern that only runs once, e.g in the INITIALIZE macro.
You could have:

Start of Loop
Led on
500ms delay
Led off
500ms delay
Loop 5 times.

Then if your chip is power for the 1st time or resets then you will know its hardware resetting rather than issue with a mistake within your flowchart.

Martin
Martin

Michaelt
Posts: 38
Joined: Sun Sep 23, 2012 9:46 am
Has thanked: 13 times
Contact:

Re: Initializing problem

Post by Michaelt »

Hi Guys.

Thanks for all the replies so far. I did not know that it was only nessesary to call the TMR0 interrupt once. i thaught that it was suposed to run every scan to make the desired clock speed, well one learns every day :D About the very fast TMR0 ration, this controls the outputs of the PWM to the RGB control.
Is this not supposed to be as fast as possible to smothen the RGB cycle??

I have tryed to put in the sugested sequence just after the initialize, to spot a restart ond yes every time i pres the switch in the flashlight operation the pic restarts itself, after this i have started clering out stuf from the program to find the error. but it does not seem to remove the error, it seems that my error is in the handling of or in the Flashlight lut table..

How much data is it possible to store in lut tables??

Thanks again for the help so far :)
Have a nice sunday

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: Initializing problem

Post by medelec35 »

Michaelt wrote: How much data is it possible to store in lut tables??
If you mean how may elements then maximum is 255.

Also the maximum value is 255, but you can have two LUT for values up to 32767 etc.

Whats vital is if you have only 10 elements e.g
2,4,6,8,10,12,14,16,18,20
and you use something like:

Code: Select all

FCV_FADE_TABLE_VALUE = FADE_TABLE[FCV_LUT_TABLE_LINE_ALL];
then LUT_TABLE_LINE_ALL value must never exceed the value of 9
If it does then program will be jumping into wrong location and will either freeze or reset.
I'm not saying that's happening, but it's something to keep an eye out for.

What I would do for debugging is either used Flowcode built in ICD or send value of variable i'm intrested in via RS232 so you can use a terminal program to view value of both LUT_TABLE_LINE_ALL and what value is retrevied.
If program is resetting, then you can send a program status number via RS232.
E.g before a code thats about to be excuted you could send "status=1" afer the code "status=2"
So only if code is successfully carried out you will see both status=1 and status=2 on your RS232 terminal program.
If chip reset during code, then you will only see status=1 etc.
Martin

Post Reply