24 hour clock with 4digit 7-seg display

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 2 and 3.

Moderators: Benj, Mods

Keke
Posts: 11
Joined: Thu Sep 27, 2007 11:11 am
Location: Finland

24 hour clock with 4digit 7-seg display

Post by Keke »

Hello.
Im new to flowcode and im trying to make 24 hour clock with 4 digit 7-segment display as a school project.
Is it possible to make whole thing with flowcode and if it is, could someone send me some sample what it should look like?

User avatar
Steve
Matrix Staff
Posts: 3433
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times

Post by Steve »

It certainly is possible within Flowcode. Here are some hints:
  • * use a timer interrupt
    * in the interrupt routine, maintain variables for seconds, minutes and hours
    * in the main routine, refresh your display

Keke
Posts: 11
Joined: Thu Sep 27, 2007 11:11 am
Location: Finland

Post by Keke »

okay ill try :)
i need to multiplex the display right and how does it actualy happen in flowcode ?

- Keke

User avatar
Steve
Matrix Staff
Posts: 3433
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times

Post by Steve »

Assuming common anode display...
  1. turn off anodes
    set cathodes for 1st digit
    apply anode for 1st digit
    short delay
    turn off anodes
    set cathodes for 2nd digit
    apply anode for 2nd digit
    short delay
    turn off anodes
    etc...

Keke
Posts: 11
Joined: Thu Sep 27, 2007 11:11 am
Location: Finland

Post by Keke »

I tried to do that what you said some days ago but i simply can't figure out how to actualy turn off the anodes and how to set variables for hours, minutes, seconds.

- Keke

User avatar
Steve
Matrix Staff
Posts: 3433
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times

Post by Steve »

You can use the "showDigit" macro of the 7seg LED component to show the appropriate number.

For the variables, you need to increment the hours variable once the minutes variable has reached 60 (etc.).

Keke
Posts: 11
Joined: Thu Sep 27, 2007 11:11 am
Location: Finland

Post by Keke »

The code is finished now and working almost perfectly. Just having a small problem and hoping if anyone could answer.

When running the clock (in flowcode) some numbers like 1 show as 7.. but when i switch the delay to slower it shows like 1 but it blinks the segment A ( with numbers 5 and 6 it blinks segment B ) just before the segment turns off. Is this just software side or is there something wrong with my code?

Going to test the code in action next week after getting my circuit finished

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:

Post by Benj »

Hello Keke

I have tested the 7 segment displays with a slow RC clock and there is no flicker at the end of displaying the 1. Are you using the latest version of Flowcode. You can upgrade to the latest version by downloading and installing the following file.

http://www.matrixmultimedia.com/softwar ... nstall.exe

Adding a small delay (eg 4-5ms) after each write to the 7 segment display should also help to make the numbers clearer and more defined.

Hope this helps.

Keke
Posts: 11
Joined: Thu Sep 27, 2007 11:11 am
Location: Finland

Post by Keke »

Tested this in action... it seems when i add the switches to flowcode the segments start to blink and on my hardware whole clock goes nuts.
i have two switches, one for minutes and one for hours. Hour switch is connected to same port with segment A (pin 6) and minutes to same with segment B (pin 7)

where should i connect these switches?

PS: i tested this on the flowcode programming/testing board

Keke
Posts: 11
Joined: Thu Sep 27, 2007 11:11 am
Location: Finland

Post by Keke »

Sorry for bumb but still havent found solution to this :(

i have two switches, one for minutes and one for hours. Hour switch is connected to same port with segment A and minutes to same with segment B

where should i connect these switches?

Usin PIC 16F628

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:

Post by Benj »

Hello

Have you got any spare I/O that is not being used.

I am guessing that the current config is this.

PortB 0 - 7 - Cathodes

PortA 0 - 3 - Anodes

What about pins RA4 and RA5.

ziggy1976
Posts: 16
Joined: Sat Jan 19, 2008 6:54 am

Re: 24 hour clock with 4digit 7-seg display

Post by ziggy1976 »

I am in the process of developing a stop watch with min secs and 1/1000th of a second digit displayed.

1/ I am using a 16X2 alphanumeric display. I need help on the refresh routine for displaying the count from the timer interrupt. Any suggestions on how to organise the LCD display subroutine would be helpful.

2/ What prescaler and clock freq will ensure an accurate 0.001 sec count please (I am thinking of using a 4MHZ freg with a prescaler setting of 1:16)?

3/ Any pointers on how to set up the main flowcode program or tips to ensure that the timing is accurate would be of great help.

4/ I want to divide a variable then use the remainder. For example:

TempVar = Mins/10

TempVar2= %Mins or remainder of Mins.

Is there a flowcode feature that allows the use of remainders?

6/ The start stop will be controlled by a button and a 433mhz reciever/decoder to allow automatic timing.

ANY advice, tips or flowcode snippets would be much appreciated.

Thank you.

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: 24 hour clock with 4digit 7-seg display

Post by Benj »

Hello Ziggy

In answer to your questions

1) The easiest way is to use a macro to do all of the cursor positioning and data outputing, using global variables to hold the data you want outputting.

2) The best thing you can do is play around with the clock speed in Flowcode. When you go into the Timer0 Properties it will tell you the interrupt frequency based on the prescalar and clock speed.

3) Timing will be accurate if A) Your interrupt service routine is kept to a minimum, B) You are using an XTAL or HS Oscillator.

4) This is not possible with 8 bit digital logic, You options are to A) multiply the number so the remainder will be an integer, B) use the 32-bit floating point library for Flowcode (see forum posts in support area).

ziggy1976
Posts: 16
Joined: Sat Jan 19, 2008 6:54 am

Re: 24 hour clock with 4digit 7-seg display

Post by ziggy1976 »

Thanks for the input. I looked at the examples that came with flowcode 3 in the program files on my computer. They are excellent. I recommend that anyone who needs help with sorting out timing for example will be able to adapt example 22 to achieve what they need. The examples are very very helpful and illustrate the capabilities of flowcode.

ziggy1976
Posts: 16
Joined: Sat Jan 19, 2008 6:54 am

Re: 24 hour clock with 4digit 7-seg display

Post by ziggy1976 »

I have adapted tutorial 22 for my stop watch project. I have implement a start button macro with debounce. I am finding it difficult stopping the program as a stop watch. Could anyone suggest how I could implement the stop and reset button please?

Thank you
Attachments
stop_button.JPG
stop_button.JPG (21.66 KiB) Viewed 18418 times
stopwatch.JPG
stopwatch.JPG (17.17 KiB) Viewed 18421 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: 24 hour clock with 4digit 7-seg display

Post by Benj »

Hello Ziggy

The Stop button has to disable the timer0 interrupts. This will stop the internal variables from counting and can be done by using an interrupt flowchart icon.

The Reset button has to assign 0 to all of the internal count registers. Eg secs, mins, hours etc.

ziggy1976
Posts: 16
Joined: Sat Jan 19, 2008 6:54 am

Re: 24 hour clock with 4digit 7-seg display

Post by ziggy1976 »

Thanks great help.

Keke
Posts: 11
Joined: Thu Sep 27, 2007 11:11 am
Location: Finland

Re: 24 hour clock with 4digit 7-seg display

Post by Keke »

OK i got the clock working but theres still one problem... The display isnt realy bright, in daylight its impossible to see the number but in dark room its possible... Could it be because i got just 1ms as delay between each 7-segment display. Maybe if i make the delays bit longer it could be brighter?

Before making the circuit i tested the 7-segs manualy and they were pretty bright, you could see the numbers in daylight from far away with ease.

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: 24 hour clock with 4digit 7-seg display

Post by Benj »

Hello Keke

Yes increasing the delays can have an effect on the brightness of the displays. Up to 4 or 5 ms per 7-seg normally does a good job. If you can see the displays flickering then lower the delay value slightly.

Our hardware 7-segs have transistors to help boost the current to the anode pins. Have you created your own hardware for these displays or are you using some of our hardware.

Sean has also mentioned that special tape is available to make the red lit segment bars stand out more from the background so this may also be an option for you.

Keke
Posts: 11
Joined: Thu Sep 27, 2007 11:11 am
Location: Finland

Re: 24 hour clock with 4digit 7-seg display

Post by Keke »

Thanks for fast answer.
In my circuit i got 4050CMOS non-inverting hex buffers between the PIC and 7-seg displays, they should work same way as transistors do.
Im gonna test increasing the delays tomorow since cant do that today.

Keke
Posts: 11
Joined: Thu Sep 27, 2007 11:11 am
Location: Finland

Re: 24 hour clock with 4digit 7-seg display

Post by Keke »

Sorry for double post but...
When i try to compile it the flowchar to .hex it gives me these errors

File name: K:\opinnäytetyö\KELLO.c
Generated by: Flowcode v3.0.3.27
Date: Friday, February 08, 2008 10:04:45
Licence: 50 User
Registered to: Pyynikin ammattioppilaitos/TAO


NOT FOR COMMERCIAL USE

http://www.matrixmultimedia.com



Launching the compiler...


..................

BoostC Optimizing C Compiler Version 6.52 (for PIC16 architecture)
http://www.sourceboost.com
Copyright(C) 2004-2006 Pavel Baranov
Copyright(C) 2004-2006 David Hobday

Licensed to FlowCode User under Single user Full License for 1 node(s)
Limitations: PIC12,PIC16 max code size:Unlimited, max RAM banks:Unlimited, Non commercial use only

internal error: can't parse input file name 'KELLO.c'

KELLO.c
Starting preprocessor: "C:\Program Files\Matrix Multimedia\Flowcode V3\BoostC\pp.exe" KELLO.c -i "C:\Program Files\Matrix Multimedia\Flowcode V3\BoostC\include" -d _PIC16F628 -la -c2 -o KELLO.pp -v -d _BOOSTC -d _PIC16


.....................................................................................................................................................................................................................................................................................................................................

KELLO.c(627:9): error: unknown identifier 'TMR0IE'
KELLO.c(627:9): error: unexpected '.' operator
KELLO.c(627:2): error: failed to generate expression
KELLO.c(627:2): error: invalid operand 'intcon.TMR0IE'
KELLO.c(627:15): error: failed to generate expression
KELLO.c(668:21): error: unknown identifier 'TMR0IF'
KELLO.c(668:21): error: invalid operand 'TMR0IF'
KELLO.c(668:18): error: failed to generate expression
KELLO.c(668:18): error: invalid operand '<<'
KELLO.c(668:13): error: failed to generate expression
KELLO.c(668:13): internal error: failed to generate 'if' expression
KELLO.c success

.


failure

Return code = 1

Vuokaavion C-koodin kääntäminen ei onnistu johtuen seuraavista virheistä:


Jos vuokaaviossasi on C-koodia, käy tämä huolellisesti läpi. Jos vuokaaviossasi ei ole C-koodia tai olet täysin tarkastanut sen, ota yhteyttä tekniseen tukeen.

FINISHED

it seems to be giving error about my TMR0 interrupt, when i take it off it compiles without any problems...
anyone knows solution to this

Sean
Valued Contributor
Valued Contributor
Posts: 548
Joined: Tue Jun 26, 2007 11:23 am
Has thanked: 6 times
Been thanked: 44 times

Re: 24 hour clock with 4digit 7-seg display

Post by Sean »

Hello Keke,

Ben is not available today so I will try to pick up this project.

The first thing i have noticed with your error report is that TMR0IF and TMR0IE are not defined for the PIC16F628. The required definitions are T0IF and T0IE respectively. Are you using a custom interrupt or C code?

If this does not help could you attach a copy of your code to the next posting and I will check it.

ziggy1976
Posts: 16
Joined: Sat Jan 19, 2008 6:54 am

Re: 24 hour clock with 4digit 7-seg display

Post by ziggy1976 »

Ben,

I have successfully implemented the stop and reset button respectively, thanks for the hint. I want to use a 4 MHZ crystal to generate a 100ms interrupt. I downloaded a piece of software called "Pic Timer Calculator Version 4". The software recommends a timer offset of 100, a prescaler ratio of 1:64 and calculated that a 99.5222 Hz timer freq will allow 1 instruction cycle time to equate to 10048 micro seconds which is not far off the interrupt time I want. In Flowcode, a prescaler setting of 1:64 for a 4 Mhz crystal allows an interrupt frequency of 61.0352 Hz. How do I implement the equivalent of a timer offset and will I be able to achieve a 10048 micro seconds interrupt?

ziggy1976
Posts: 16
Joined: Sat Jan 19, 2008 6:54 am

Re: 24 hour clock with 4digit 7-seg display

Post by ziggy1976 »

The link for the software I mentioned in the above post

http://users.picbasic.org/projects/PicT ... merCal.htm

Sean
Valued Contributor
Valued Contributor
Posts: 548
Joined: Tue Jun 26, 2007 11:23 am
Has thanked: 6 times
Been thanked: 44 times

Re: 24 hour clock with 4digit 7-seg display

Post by Sean »

The 61.0352Hz interrupt rate is based on the assumption that timer 0 is continually counting from 0 to 255 and generating an interrupt each time it overflows back to zero.

With a Xtal frequency of 4MHz, the system clock dividion of 4, and the selected prescaler division of 64, timer 0 is being clocked at 15625Hz (64us). Division by the 256 count required by Timer 0 results in the 61.0352Hz interrupt frequency.

If Timer 0 is preset to the value 100 at the start of each interrupt cycle, it will only require a further 157 count to overflow and generate the next interrupt. 157 x 64us = 10048us. (setting 101 will give 9984us).

To achieve this, set up the Timer 0 overflow interrupt with the specified prescaler value and write your interrupt macro. The first code block in the interrupt macro should be a C code block with the following command:

tmr0 = 100;

This will quickly change the timer register value from the normal overflow value of 0 to the required value of 100.

This is not a perfect solution because of the finite time taken to respond to the interrupt, but is accurate to a few us and is relatively stable.

Post Reply