Page 1 of 1

TMR 0 issue

Posted: Thu Nov 27, 2014 3:39 pm
by Manie Serrao
Hi All,

I am having problems with using TMR0, it does not seem to overflow at a 75Hz , frequency is 19660800 and prescaler set at 256. After I could not get my own file to "clock" correctly I loaded the "Digital Clock" example provided by Matrix and it to runs at wrong speed also i.e. realtime = 1 second and Digital Clock is much more.
Heave I got a global setting or something set up incorrectly.

Help please :(

Re: TMR 0 issue

Posted: Thu Nov 27, 2014 7:04 pm
by medelec35
Hi Manie Serrao,
you have forgot to post your flowchart, so we are not able to check it for you.
If you post it,i will take a look at it for you.

Martin

Re: TMR 0 issue

Posted: Thu Nov 27, 2014 7:14 pm
by Manie Serrao
Hi Martin,
Thanks for quick reply...
Any file I create using the interrupt runs at it's own pace, not real time.
I have just "written" a new file and tried a different approach but still same problem, will upload it as well.
Regards,
Manie

Re: TMR 0 issue

Posted: Thu Nov 27, 2014 7:33 pm
by Manie Serrao
Attached is another "test" file.
This is a project I started last year, a kiln controller with elapsed time as well as automatic ramp-up of the temperature as the kiln progresses through the different stages, am also using PID to smoothe the firing process. The actual project has turned into a monster, but what a challenge....will upload the file when I put all the "bits" together as one with it's dozen or so macros.
Manie

Re: TMR 0 issue

Posted: Thu Nov 27, 2014 8:03 pm
by medelec35
Hi Manie,
No problem.

The issue with your first flowchart is you have not got

Code: Select all

if count = 75 then count = 0: seconds = seconds + 1
etc.
Since timer 0 is set for an interrupt frequency of 75 Hz then the interrupt macro is being accessed 75 times every second.
Hence

Code: Select all

 if count = 75
is required.

The problem with your second flowchart is you have got the timer interrupt properties set to

Code: Select all

Transition on TOCKI
and not internal clock.
you must change it before it will work.
Also you did not have the configuration settings set.
I have done that for you.

I am assuming that you have a 19.66Mz crystal and you have done the 1Hz flash LED test?

Martin

Re: TMR 0 issue

Posted: Fri Nov 28, 2014 6:14 pm
by Manie Serrao
Hi Martin,
Thanks for the help...... Flowchart Digital Clock with PWM V2 .....I have not hooked up any hardware to do a physical test yet....all done in "simulation" with 19,66 Mhz - prescaler = 256 = 75 Hz
I have set the Interrupt properties to "internal clock", added the variable reset count = 0, but when i run simulation "as fast as possible" real time = 15 seconds and flowchart reads exactly 2 seconds (in variable watch) ie the TMR0 has called the "Clock" macro 150 times.



Excuse the ignorance but the 1 Hz LED test I assume is the same as my test in the flowchart of output port A = 1 when Count_t is < 75 and output port A = 0 when Count_t is > 75 and when count_t = 255 it resets to count_t = 0 and and a new on / off cycle begins.

Am I missing some point or other....or have I got another wrong setting somewhere.....in the system..... divide by.............????

Nuts... so frustrating these "school fees" but nevertheless still fun and rewarding especially with the successes ...

Manie

Re: TMR 0 issue

Posted: Fri Nov 28, 2014 7:04 pm
by medelec35
Manie Serrao wrote:when i run simulation "as fast as possible" real time = 15 seconds and flowchart reads exactly 2 seconds
Flowcode simulation with FC V4 and FC V5 is way slower than real time!
With FC V6 simulation is faster than real time.
The best way to check timing is with real hardware.
Manie Serrao wrote:Am I missing some point or other....or have I got another wrong setting somewhere.....in the system..... divide by.............????
There are loads of references regarding 1Hz flash test
Its purpose is to check that osc speed is running at the correct speed bu using the very basic delays and output only.

We do not recommend using interrupts for this test since there could be a mistake made which could lead to misleading results.
So the way is
Main:
While (1)
A0>1
delay 500ms
A0>0
delay 500ms
Repeats for ever.


Only if osc is running at the correct speed then LED will be flashing at 1Hz i.e on for 500ms then off for 500ms etc


Martin

Re: TMR 0 issue

Posted: Fri Nov 28, 2014 9:00 pm
by Manie Serrao
Cool, was not aware that the simulation was slower than the real world......problem solved. Once again thanks for the help and advice.
OK now I can continue....