Digital Clock

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
ben
Flowcode V4 User
Posts: 18
Joined: Thu Sep 24, 2009 5:02 pm
Been thanked: 1 time

Digital Clock

Post by ben »

Hello everyone,
I have recently been trying to get a very simple flowcode working! Benj kindly provided me with a file enclosed, but although the simulation works fine, I can't actualy get it working on the hardware. The clock ticks fine, but the external triggers have no affect. Also the timing seems to lag the actual time. I'll be very grateful for any advice. Many thanks in advance.
Attachments
5. Digital clock - modded.FCF
(18.25 KiB) Downloaded 441 times

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Digital Clock

Post by Benj »

Hello,

I have just tested the file here without any changes and it's working great on the hardware. By default the clock will not be running so I wonder about the setup of your switches. Have you used a pull up and pull down method like we use for the EB007 board? You can refer to the schematic at the end of the datasheet to check if your switches are wired correctly. Maybe also worth checking with a multimeter if you have one handy so you can see the voltage being applied to the input pins.

I have also noticed that in the device config settings you have the watchdog timer enabled. I would suggest you disable this. All the other settings look fine unless you need the external MCLR reset functionality.

Regarding the timing what speed crystal are you using? 20MHz as defined in the project options will not give you a very accurate clock. If you change to say a 19.6608MHz crystal then you can divide the clocks down to get a bang on count of 75 ticks per second. This will then have a max error of around 2 seconds a day using a 20PPM crystal.

ben
Flowcode V4 User
Posts: 18
Joined: Thu Sep 24, 2009 5:02 pm
Been thanked: 1 time

Re: Digital Clock

Post by ben »

Hi Benj,
Once again thank you very much for your assitance. The circuit is working prefectly now and the problem was my switch setting !! :D

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

Re: Digital Clock

Post by medelec35 »

Hi
Looking at flowchart you have posted, I can see there could be an issue regarding accuracy?
If you look at the properties of timer0 interrupt, at 20MHz the interrupt frequency is 152.588Hz
So instead of setting SECOND_COUNTER >= 153 on your Flowchart is is set for >=150
So Clock is going to run a bit too fast.
If it was me and I was not using built in PWM then easiest way would be to use Timer2 instead.
Note: Timer2 only simulates with Flowcode V5. So for simulation testing purposes use a call INTERRUPT_TMR2
(I have changed the name in the Flowchart I have modified)
If you look at timer2 properties you will see I have set the following values:
Prescaler Rate: 1:16
Postcaler Rate 1:16
Rollover Value 217
This gave an interrupt frequency of 90.006Hz which will be more accurate than 152.588Hz
To find the best Rollover Value I went to http://eng-serve.com/pic/pic_timer.html
Change Oscillator frequency to 20000000 and moved sliders to the right to give the lowest interrupt frequency possible.
Then I moved the lowest slider (PR2 register) until interrupt is rounded to the nearest whole value.
Int Timers.png
(64.6 KiB) Downloaded 1557 times
If I had more time I may have been able to get a better interrupt frequency, so I’m not stating the chosen one is the optimum value.
If you would like to use timer0 instead, then you may get a more accurate time by placing
Some code at the beginning of timer interrupt to preload timer0 with a different value other than 0 (e.g tmr0=0x20; )so rollover occurs more quickly. With trial and error or using a scope you can get interrupt frequency to be more accurate.
See:
http://www.matrixmultimedia.com/mmforum ... =26&t=8660

Hope this helps,

Martin
Attachments
5. Digital clock - modded2.FCF
(18.25 KiB) Downloaded 445 times
Martin

ben
Flowcode V4 User
Posts: 18
Joined: Thu Sep 24, 2009 5:02 pm
Been thanked: 1 time

Re: Digital Clock

Post by ben »

Hi Martin,
Thank you for your input, very informative. I'll try your suggestion in the very near future.

Carlos Viveiros
Posts: 30
Joined: Tue Dec 26, 2006 9:04 pm
Has thanked: 2 times
Been thanked: 1 time

Re: Digital Clock

Post by Carlos Viveiros »

I normally use a 4 Mhz (4000000 Hz) Crystal

Here is an example of a very acurate time for digital clock. In this case, 50 Hz.
:)
Attachments
50 Hz at 4Mhz Crystal
50 Hz at 4Mhz Crystal
time_clock.jpg (54.75 KiB) Viewed 6614 times

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

Re: Digital Clock

Post by medelec35 »

You can't get much more accurate than that! :lol:
Martin

Carlos Viveiros
Posts: 30
Joined: Tue Dec 26, 2006 9:04 pm
Has thanked: 2 times
Been thanked: 1 time

Re: Digital Clock

Post by Carlos Viveiros »

Yes, i guess not ... :P

Post Reply