Problema con dsiplay de 7 segmentos

Any bugs you encounter with Flowcode should be discussed here.
mnfisher
Valued Contributor
Posts: 1518
http://meble-kuchenne.info.pl
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 138 times
Been thanked: 729 times

Re: Problema con dsiplay de 7 segmentos

Post by mnfisher »

As a thought - and as you use C0..C7 for the LED pins. On 'hardware' (only) - you could do without the component...

So PortC (output) = .segments would write all the segment data in one operation. Would need to set the correct 'common' pin as well.

Would lose the benefit of simulation - but for hardware it would be much simpler and quicker....

Martin

chipfryer27
Valued Contributor
Posts: 1575
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 357 times
Been thanked: 560 times

Re: Problema con dsiplay de 7 segmentos

Post by chipfryer27 »

Hi Martin

Not sure I follow, but as it's late O'clock and I am in the closest thing I can find to a pub that may not be too surprising.

I am under the impression that write segments allows you to control each individual segment within a display (a-g + point), with the common pin activating it.

Would it not be more troublesome to select common, write segments, then move on to next digit than use existing component?

Without HW to test I am not certain but I think through random Bon Chance you may possibly be able to 😊 so I will defer...

Regards

mnfisher
Valued Contributor
Posts: 1518
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 138 times
Been thanked: 729 times

Re: Problema con dsiplay de 7 segmentos

Post by mnfisher »

Enjoy the pub alike...

Difficulty wise - about the same - see the last version. Getting all the segments is just from a little lookup table..
As the demo uses a single port for all of the segments, it would save the overworked MCU a lot of cycles.

I haven't tested on hardware - having a lazy day😴

Martin

Carmelo
Posts: 123
Joined: Thu Oct 14, 2021 10:04 am
Has thanked: 50 times
Been thanked: 4 times

Re: Problema con dsiplay de 7 segmentos

Post by Carmelo »

mnfisher wrote:
Sun Mar 02, 2025 11:49 am
I rewrote 'multiplex' to show with decimal point and '---' if temp >= 100 (note that to allow integer maths - I multiple the actual temp by 10)

I removed the negative numbers for clarity.

If you want the '---' to flash then you need a counter and swap between '-' and ' ' for segments (0x40 and 0). I lifted the lookup table for the character set from the component (and added the '-')

And for fun - I changed the LEDs to green :-)

Martin
Thank you very much for the response Martin and for the work of the program.

I have reviewed it and I understand the multiplex part of the switch how it works, but the rest at the beginning are the part where you put the "." In front of the names I don't understand how it works. Are variables local to this macro only?

On the other hand, I don't see where you have selected the "-" indication and therefore I don't see where to place the counter to flash.

I also don't understand the line: .segments = .LookupSegs[.x % 10] | (0x80 * (digit == 1))
and much less the expression "LookupSeg"

Would you be so kind as to give me a brief description of the indicated queries?

mnfisher
Valued Contributor
Posts: 1518
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 138 times
Been thanked: 729 times

Re: Problema con dsiplay de 7 segmentos

Post by mnfisher »

Yes '.' in front of a variable names selects a local variable.

LookupSeg - is an array of bytes (local in Multiplex) that holds segment patterns for the digits 0..9 and (Lookupseg[10] is '-')
The decision if x < 1000 (values are multiplied by 10) checks if the temperature is below 100 and we can display or >= 100 and we need to set the digits to '-'. Previously the code would set all three digits to '-' rather than multiplexing them.
In this decision we can have a counter (a global - always use locals whenever possible :-) ) and set segments to '-' or 0 (all off) depending on the value.

.segments = LookupSegs[.x % 10] - gets the value from the array for .x modulus 10 (get the relevant digit).
The 0x80 x (digit == 1) is a slight cheat - I want to set bit 8 of segments (which corresponds to the decimal point) for digit == 1. I could have used a conditional (if digit == 1) or added it to the switch statement (though then need to repeat the check for temp overflow to avoid setting the dp for '-')
It's a Boolean expression (digit == 1) that returns 0 if digit != 1 or 1 if it is... (Any boolean expression is valid so for example .y = (.x > 0) will be set .y to 0 or 1 depending on the value of x)

I think it is (slightly) neater (and it might be very slightly smaller / faster code) than a conditional (if x > 0 then ...) - but it is a matter of preference which you use...

Martin

Carmelo
Posts: 123
Joined: Thu Oct 14, 2021 10:04 am
Has thanked: 50 times
Been thanked: 4 times

Re: Problema con dsiplay de 7 segmentos

Post by Carmelo »

Muchas gracias Martín por la explicación.
Ahora no estoy delante del pc.
Más tarde revisaré todo lo que me explicado para tratar de entenderlo y quizás pueda aplicarlo en futuros proyectos.

¿Existe algún lugar donde pueda ver/conocer esas pautas de programación con flowcode?

Cuando implemente el parpadeo, seguiré con el proyecto realizando un pequeño menú de opciones para poder seleccionar por programa los valores de activación/desactivación del relé de acuerdo a la temperatura.

Carmelo
Posts: 123
Joined: Thu Oct 14, 2021 10:04 am
Has thanked: 50 times
Been thanked: 4 times

Re: Problema con dsiplay de 7 segmentos

Post by Carmelo »

With your instructions, Martin, I have already understood the modification that I attached.
In addition, I already included the aforementioned flashing and also when the temperature reaches 0, I have added the display indication of the E1 value to notify the user of an error.

Now I will move on to creating a small menu to use the buttons to adjust the relay's operating values.

mnfisher
Valued Contributor
Posts: 1518
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 138 times
Been thanked: 729 times

Re: Problema con dsiplay de 7 segmentos

Post by mnfisher »

Well - inspired by chipfryer27 I had a beer... Ooops - no I wired up a 4 digit 3641BS display. to a PIC16F887. This has an 8MHz clock (internal - ext can go up to 20MHz) - took a bit of fiddling to get an interrupt rate that looked acceptable with no flickering.

Things did not go smoothly. The device has 4 digits ( - the wiring is the same as for 3 displays it's just internal :-) )
I made a mistake and wired b2 to display 1 .. b5 to display 4. I've confused myself with the digit select - can't work out how 0b1000 >> digit to the select pins (d2..d5) works unless output reverse the byte...

The display then seems to have opposite logic to yours - so common had to be high and .... So - although it would have made more sense to use the 4 digit display component (probably - I didn't test it) I scrapped the displays in the end and made multiplex work without...

I used 220Ohm resistors on the display select lines - I notice that display brightness varies slightly depending on how many segments are set - I don't have the patience to have a resistor on each segment pin - which is what it needs, but too fiddly on a breadboard!

My use of segments - from the look up table - needed to invert the value (using the ~ operator.
IMG_20250302_173759.jpg
IMG_20250302_173759.jpg (177.62 KiB) Viewed 906 times
As there are four digits to play with - I set the initial temperature to 1234 (123.4) and set 'overflow' as 10000. I don't have a thermistor attached so just increment the value in a loop... Power is from the PicKit3. Despite the photo - '1' would be a brighter digit (less segments to light)

It's not quite right - the decimal point on digit 1 ((at right) flashes... In fact '0' has the wrong data - showing as all segments set (hence the dp flash...) Fixed - typo in lookup data....
Attachments
Multiplex HW.fcfx
(29.69 KiB) Downloaded 21 times

mnfisher
Valued Contributor
Posts: 1518
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 138 times
Been thanked: 729 times

Re: Problema con dsiplay de 7 segmentos

Post by mnfisher »

With your instructions, Martin, I have already understood the modification that I attached.
In addition, I already included the aforementioned flashing and also when the temperature reaches 0, I have added the display indication of the E1 value to notify the user of an error.
Good progress....

Carmelo
Posts: 123
Joined: Thu Oct 14, 2021 10:04 am
Has thanked: 50 times
Been thanked: 4 times

Re: Problema con dsiplay de 7 segmentos

Post by Carmelo »

To physically test it, I won't be able to assemble it properly in a few days. On this point I will report the result.
I greatly appreciate the trouble you are taking to physically set up the project.

But....
Here again with a new problem.
The project is the same as what you mentioned above with the addition of the blinking in the temperature reading part.

As I said, I have started to create the programming menu and for this I have created the falling false interrupt in INT0. Within your macro I only deactivate TMR2 and increment a counter.
Then in the main I deactivated the icon for reading the temperature, to check the new macro part created for reading the button in B0 and I have created a new macro just to see a message on the displays when B0 has been pressed.

Well, when I run the simulation, although it does not act on B0, after running through the new macro, it starts executing the 1s delay icon. and right after, the same process should be executed again indefinitely: macro (habProg and delay).
The fact is that right after the delay is executed, even though B0 has not been pressed, the program JUMPS to execute the Multiplex macro without being called.

Where could that error be?
I don't see any logic in it.
Attachments
Termostato_10_90_v02.fcfx
(46.89 KiB) Downloaded 21 times

Post Reply