Help for flowchart for it

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
mossana
Posts: 4
Joined: Thu Mar 11, 2021 2:29 pm
Contact:

Help for flowchart for it

Post by mossana »

Hello everyone
I want to write flowchart in flowcode for these 7segment
But I have problem
Can anyone help me
Attachments
7segment-degree
7segment-degree
20210311_153451.gif (3.15 MiB) Viewed 5638 times

chipfryer27
Valued Contributor
Valued Contributor
Posts: 617
Joined: Fri Jun 06, 2014 3:53 pm
Has thanked: 184 times
Been thanked: 195 times
Contact:

Re: Help for flowchart for it

Post by chipfryer27 »

Hi

I would recommend you have a look through the help examples and spend a little time on the wiki pages. Below is a link to the Getting Started Guide and also to the 7-segment entry.

https://www.matrixtsl.com/resources/fil ... dGuide.pdf
https://www.matrixtsl.com/wiki/index.ph ... :_Segment)

These guides should help you get started.

Regards

mossana
Posts: 4
Joined: Thu Mar 11, 2021 2:29 pm
Contact:

Re: Help for flowchart for it

Post by mossana »

I try to write but doesn't flash can help me ??
Attachments
Flowcode5eprom11.fcfx
(18.09 KiB) Downloaded 117 times

chipfryer27
Valued Contributor
Valued Contributor
Posts: 617
Joined: Fri Jun 06, 2014 3:53 pm
Has thanked: 184 times
Been thanked: 195 times
Contact:

Re: Help for flowchart for it

Post by chipfryer27 »

Hi

I have only had a quick look but if you are referring to your flasher macro, I don't see a Macro Call for such.

I see you are using an interrupt to detect a button press. Nothing wrong with this approach but interrupts are handled quickly and buttons "bounce" before settling. This means that your interrupt could be called many times even though you just pushed a button "once" and you may be taking readings before it fully settles. I would look to debounce those buttons.

A quick search of the forum gives the following for "debounce"

search.php?keywords=debounce

The LED display will only handle a single digit so be sure that your value is 0-9. It may also be a good idea to initialise your EEPROM locations with known data (e.g. write 0 to all used locations) at the beginning of your program.

I'll try and look again later.

Regards

mossana
Posts: 4
Joined: Thu Mar 11, 2021 2:29 pm
Contact:

Re: Help for flowchart for it

Post by mossana »

Thanks man I wait your answer

chipfryer27
Valued Contributor
Valued Contributor
Posts: 617
Joined: Fri Jun 06, 2014 3:53 pm
Has thanked: 184 times
Been thanked: 195 times
Contact:

Re: Help for flowchart for it

Post by chipfryer27 »

Hi Mossana

I've looked through your chart but I'm not sure I completely understand exactly what you are trying to do, so I hope this is of help.

You mentioned earlier that it doesn't flash. As far as I can see it is because the Macro in your chart isn't called. As an example I have put a Macro call at the beginning of the attached chart to call your Macro. Obviously you can move this to wherever you want.

You are reading a value from EEPROM before it is ever written to. I may be wrong but I am under the impression that all being well a previously unwritten location will contain 0xFF (255). Of course you have no actual way to know what is in a location until you either read/write to it, so it may be a good idea to initialise this by writing a known value. As a further example I have written 0x00 (0) to the first location. You should never assume a location to contain anything other than what you have set it to <s>

It is worth noting that if it did indeed initially contain 0xff (255), then in your Set Macro you read the EEPROM and set the variable "temp" to equal such, meaning temp = 255. This value cannot be displayed on your 7-Seg LED, only single digits. Later in your Macro you add "2" to the value. This would cause the value to rollover to "1" (255+2 = 1 as a byte can only contain 0-255. 255+1 = 0). As we are now using "odd" numbers your sequence will now be 1/3/5/7/9 etc.

If you Simulate the chart you will have the option to set the speed and also Step through the chart. When Paused you have the option to add expressions which will show you the current vale of your variables. Very handy feature.

As mentioned previously you are using an interrupt to check for a button press. Nothing wrong with that but you need to be aware of switch bounce. When a mechanical switch is made/broken it actually makes/breaks many, many times before settling on final state. This can cause havoc with microcontrollers as they receive a train of pulses rather than just one. There are many ways to debounce both in hardware and in software and you should choose a suitable method. Plenty of posts in the forum regarding this and a quick search will give you ideas.

One thing to also be aware of is that Interrupt routines should be as short as possible. Very short. Ideally you want the interrupt routine to test then set/unset a flag or such like (button1=1 / button2=0 for example), then in your Main routine check the status of this flag and branch accordingly. Perhaps test for flag status and branch, near the beginning of your Main Loop?

Pretty much straight away in your Macro you read both buttons, one after the other. Unless you move faster than lightning your routine is probably way too fast to be practical. Maybe consider some other way? Perhaps poll for key presses / flag status instead?

I hope this gives you some ideas and is of some help.

Let us know how you get on.

Regards
Attachments
Flowcode5eprom11_example1.fcfx
(18.76 KiB) Downloaded 134 times

mossana
Posts: 4
Joined: Thu Mar 11, 2021 2:29 pm
Contact:

Re: Help for flowchart for it

Post by mossana »

Thanks for your helping
First when press button must 7segment (flash light)(on off)(blinking) 5 times :cry:
Then stop blinking if I press button two times it changes value
I upload a video see it (about 2 minutes) :)
The epprom flash is good :)
First, when you press the button once, the 7segment flashes (blinking) five times, and if we press the button again while the 7segment flashes (blinking) , the value changes and flashes five times, and then the new value is fixed.in 7segment :roll:
Attachments
20210311_153451.gif
20210311_153451.gif (3.15 MiB) Viewed 5501 times

chipfryer27
Valued Contributor
Valued Contributor
Posts: 617
Joined: Fri Jun 06, 2014 3:53 pm
Has thanked: 184 times
Been thanked: 195 times
Contact:

Re: Help for flowchart for it

Post by chipfryer27 »

Hi

In your previous chart you used an Interrupt call to read the buttons but I thought you would have problems with that.

Instead of using an interrupt, you could poll the status of the buttons in your Main loop and call your Macro if any were active. In your Macro you are waiting 50mS before polling status again, which is effectively providing debounce although you may need to experiment with the delay for effective debounce but 50mS is a good start.

I have changed to reflect this and in simulation I can run up to 8 and back down to 2 without issue.

If you want the display to "flash" then just put calls to the flash Macro wherever you wish.

Hope this helps.

Regards
Attachments
Flowcode5eprom11_example2.fcfx
(18.78 KiB) Downloaded 124 times

Post Reply