TMR 0 issue

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
Manie Serrao
Flowcode V4 User
Posts: 26
Joined: Mon Nov 28, 2011 3:19 pm
Location: Cape Town South Afica
Has thanked: 10 times
Been thanked: 2 times
Contact:

TMR 0 issue

Post 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 :(

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: TMR 0 issue

Post 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
Martin

Manie Serrao
Flowcode V4 User
Posts: 26
Joined: Mon Nov 28, 2011 3:19 pm
Location: Cape Town South Afica
Has thanked: 10 times
Been thanked: 2 times
Contact:

Re: TMR 0 issue

Post 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
Attachments
3. Digital Clock.fcf
This is a Matrix example which runs to quickly on my machine
(10.5 KiB) Downloaded 593 times

Manie Serrao
Flowcode V4 User
Posts: 26
Joined: Mon Nov 28, 2011 3:19 pm
Location: Cape Town South Afica
Has thanked: 10 times
Been thanked: 2 times
Contact:

Re: TMR 0 issue

Post 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
Attachments
Digital Clock with PWM.fcf
Just a test file...
(9 KiB) Downloaded 549 times

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: TMR 0 issue

Post 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
Attachments
Digital Clock with PWM V2.fcf
(9 KiB) Downloaded 578 times
Martin

Manie Serrao
Flowcode V4 User
Posts: 26
Joined: Mon Nov 28, 2011 3:19 pm
Location: Cape Town South Afica
Has thanked: 10 times
Been thanked: 2 times
Contact:

Re: TMR 0 issue

Post 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

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: TMR 0 issue

Post 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
Martin

Manie Serrao
Flowcode V4 User
Posts: 26
Joined: Mon Nov 28, 2011 3:19 pm
Location: Cape Town South Afica
Has thanked: 10 times
Been thanked: 2 times
Contact:

Re: TMR 0 issue

Post 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....

Post Reply