Quad 7 segment set up nightmare

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

Moderator: Benj

Post Reply
407charles
Posts: 122
Joined: Thu Jun 26, 2014 12:01 pm
Has thanked: 41 times
Been thanked: 19 times
Contact:

Quad 7 segment set up nightmare

Post by 407charles »

I'm having a problem in trying to set up the quad-seven segment display. I have been reading the different forum topics about this and I found one about setting the proper clock speed for the different microcontrollers. I'm using the PIC 16F877a and looking at the datasheet I found out the instruction speed is 200ns. this converted to frequency equals 5MHz. I got the display working quite better but I would like to see it working as a regular 7-segment display in where the digits are solid lit and not blurry and hard to differentiate (some times the display has some segments partially lit making it hard to understand the right number). I have seen as well an example from Benjamin where he mentions that some microcontrollers should have a supplementary C code at the beginning of the program but I did not clearly understand where he got that data from, also he used a switch command that I don't know how to use it (I would like to know if possible, because the interrupt he use has no commands on it just the begin and end commands) very tricky . there are like four lines of code that I would like to know what they mean and where they coming from to be able to use when I needed. First, there is any way to know which ones need this supplementary code? I got the PIC 16F877a set up word 0x3f3a and a 5MHz. clock speed at Build-Project Options, right underneath target I set this speed. What do I missing? The quad-7-segment display should lit with solid numbers right? when I use a program without interrupts just digit four lit solid and the other ones are not visible but when I use the interrupt the all digits are visible but blurry and difficult to differentiate. Please I need to fix this to complete my project. Can somebody help me? :(
Attachments
COUNTER MOD_v6.fcfx
Benjamin Example
(10.31 KiB) Downloaded 248 times
Rotary encoder.fcfx
My project
(9.26 KiB) Downloaded 234 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: Quad 7 segment set up nightmare

Post by medelec35 »

Hi 407charles.
The best way to set up 7seg LED is to have them within timer interrupt which is dependent on how many 7seg displays you have.
You will be best aiming for 50 to 100Hz per display.
For example if you have 3 x 7seg displays then interrupt frequency should be min of 3 x 50 = 150Hz.

One of the flwcharts you posted has got interrupt frequency of 19200Hz which is way too fast.
Display will not be that clear and it will look like segments will be on that are not suppose to be on. i.e blurry as you described.

Also none of the flowcharts are set up for 16F877a which does not have an internal oscillator, so the C code block in question e.g for 8Mhz:

Code: Select all

osccon=0x70; 
is not required at the start of main.
Plus the encoder pins are assigned to the same pins as 7seg so that will cause display issues.

I have recently posted a flowchart using 3 of the 4 7seg display here
You will need to assign the pins for your harware, but it should work just fine.

Can you post a flowchart that you will be trying on hardware and I can look at it for you.

Martin
Martin

407charles
Posts: 122
Joined: Thu Jun 26, 2014 12:01 pm
Has thanked: 41 times
Been thanked: 19 times
Contact:

Re: Quad 7 segment set up nightmare

Post by 407charles »

Hi medelec 33 nice to meet you, some how I posted the wrong file. Thanks a lot for your help, I will try the data you share with me on this subject and see if everything is OK. Here is my project: Let me know what's wrong.
Attachments
Rotary encoder II.fcfx
(8.9 KiB) Downloaded 234 times

User avatar
QMESAR
Valued Contributor
Valued Contributor
Posts: 1287
Joined: Sun Oct 05, 2014 3:20 pm
Location: Russia
Has thanked: 384 times
Been thanked: 614 times
Contact:

Re: Quad 7 segment set up nightmare

Post by QMESAR »

medelec35 wrote:Display will not be that clear and it will look like segments will be on that are not suppose to be on. i.e blurry as you described.
As Martin said your Display frequency is very high and in you newly posted file you have <= 4KHz reduce this to something like 160 -200 Hz
Then Martin posted a link to a Flowchart he did see how he uses a case structure to select the Digits and display them that is a good practice he shows
Attachments
1.jpg
1.jpg (51.07 KiB) Viewed 7815 times
2.jpg
2.jpg (47.73 KiB) Viewed 7815 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: Quad 7 segment set up nightmare

Post by medelec35 »

Hi
407charles wrote:found out the instruction speed is 200ns. this converted to frequency equals 5MHz.
That is not the frequency the osc runs at.
For 200ns you don't set clock speed at 5000000 (5MHz)
For the maximum clock speed you need (1/200x10E-9) * 4 = 20MHz
so for maximum speed you need a 20MHz crystal or resonator.
What matrix do makes good sense, instead of 20MHz they use a 19660800Hz crystal (I would recommend you do the same).
This is so timer interrupts can be divided down to a whole number e. 75.00Hz or 150.00Hz etc.

As for your flowchart, I have changed encoder so it utilises port B interrupt on change.
I prefer to use an interrupt because if polling an input like encoder, then when encode changes state it could be missed.

If you used a different crystal to 19660800Hz then don't forget to change the timer0 interrupt frequency to at least 200Hz
Attachments
Rotary encoder III.fcfx
(11.83 KiB) Downloaded 237 times
Martin

407charles
Posts: 122
Joined: Thu Jun 26, 2014 12:01 pm
Has thanked: 41 times
Been thanked: 19 times
Contact:

Re: Quad 7 segment set up nightmare

Post by 407charles »

Dear medelec 35 thanks for all your help and advice, your version of my project works flawless, I just needed to change the reset counter from 1 to zero in the last decision box because it was resetting to zero every time I turn the quadrature encoder. I may change as well the resolution of the counter as well to get single unit increments. Could you tell me how the switch command works? In what situations is useful? I really appreciate your help, I would never come out with this version, now I feel that I learn a lot by just looking at your work. I learn more about the interrupts and how to improve data in by using them. Also the switch command which is new to me, I always wonder how is used since there is not example in the matrix online course about this tool. Thanks a lot again, it works fantastic!!! :D :lol: :!:

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: Quad 7 segment set up nightmare

Post by medelec35 »

Hi 407charles,
407charles wrote:Dear medelec 35 thanks for all your help and advice, your version of my project works flawless
You're welcome and that's great!
407charles wrote:I may change as well the resolution of the counter as well to get single unit increments.
That's the issue with quadrature encoders, with one click the internal switches would have changed states 4 times!
Hence you see increment or decrement by 4

I do have a solution, attached is your flowchart modified to count up/down only once per encoder click.
For simulation purposes only, since not actually using encoder component, I have added two switches so you can simulate counting and see how flowchart works.
You can use the mouse to click on the count switch or press the letter c or your pc keyboard has I have key mapped the switch to that letter.
For your hardware you just use the encoder as normal.
407charles wrote:Could you tell me how the switch command works? In what situations is useful? I
If you select Help, Index, then enter switch into the search box then you will see:
switch icon.png
(175.23 KiB) Downloaded 4804 times
select:

Code: Select all

Switch Icon Properties
and that will explain how the switch component works.
Its very useful if on the result of a variable you need to branch and do something depending on the variable value.
It's so much less involved than using individual decision branches.

Martin
Attachments
Rotary encoder IV.fcfx
(14.93 KiB) Downloaded 256 times
Martin

407charles
Posts: 122
Joined: Thu Jun 26, 2014 12:01 pm
Has thanked: 41 times
Been thanked: 19 times
Contact:

Re: Quad 7 segment set up nightmare

Post by 407charles »

Hi guys thanks a lot for your replies. Medelec 35, I want to say thanks, I really appreciate your help and advice in this issue. The second version you upgrade works fantastic as well. I'm doing my program in blocks and this is just a part of it, a part that was eating my brains. Thanks for the information about the switch, now I know how to use it in the future. I also have a different perspective of how to use an interrupt for more precise data processing. hopefully in the future I will return the favor. Thanks a lot again.

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: Quad 7 segment set up nightmare

Post by medelec35 »

You're welcome and glad hardware is working for you.
Reading though the help and looking at examples is a good way of learning.

Interrupts do come in very handy, so it's worth learning how they work.

Good luck with the rest of your project

Martin
Martin

User avatar
AbhijitR
Posts: 299
Joined: Fri Nov 07, 2014 12:48 pm
Location: Pune, India
Has thanked: 280 times
Been thanked: 79 times
Contact:

Re: Quad 7 segment set up nightmare

Post by AbhijitR »

Dear Friends
Hello

First of all thanks to all of you for discussing this topic, I am even facing some problems in this regards.

- My first doubt is what should be the basic hardware change I will need to do if the four 7 seg displays are common cathode (I am presently using a PIC development board for testing my programs, it has got four 7 seg CC displays)
- Does the crystal value selection from the "Project Options" and the one used at actual makes a very big difference in the working, as I have selected 20 Mhz from the parameters and at actual using 12 Mhz, because when I use 20 Mhz in the hardware the display do not work/glow/lit.
- Is the loading capacitor value equally important and how to find the correct one?

In the attached example posted by Martin previously, I have made some changes as per the availability of the PIC I had

- I have used PIC16F873A
- I have changed the entire port which is used for the segments (a...g and dp) along with the common pins, previously it was port D for the seg and half of port C for the common pins, I have changed it to port C and A respectively)
- I have observed one thing, kindly correct if I am wrong, the common pins of all the four displays connected to the four transistors on my development board are from right to left (i.e. DIS3---DIS2---DIS1---DIS0: RA3---RA2---RA1---RA0 respectively) and on contrary the display used in the simulation mode on the "2D:Dash Board Panel" as well the actual hardware eBLOCKS "Quad 7-Seg display board" the four displays are marked from left to right (i.e. 0---1---2---3)
- My doubt is are the single digits refreshed one by one, and is it from left to right or vice versa
- So I modified the connection of all the four common pins from the original program exactly the reverse (ie CP0  RA3, CP1  RA2, CP2  RA1, CP3  RA0) and the “Display type” to Cathode, but the display only glows bright and well, but nothing change after the input.
- So I again changed the Display type to anode, and surprisingly the display works but reverse, I mean the “ZERO” is displayed with the only segment glowing “g” and the “dp” (except the “dp” of DIS1)

Friends, kindly excuse me for writing so long explanation.

Thank you all well in advance, and hear you soon.

Regards
Abhi
Attachments
20150407_161238.jpg
Aode selection in the flow code and at actual
(1.08 MiB) Downloaded 1956 times
Rotary encoder IV.fcfx
Modified flow code previously posted by Martin
(14.25 KiB) Downloaded 192 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: Quad 7 segment set up nightmare

Post by medelec35 »

Hi Abhi,
Do you still require any help?

If so, do you have a link to the datasheet of the pic development board?

Martin
Martin

Post Reply