May I ask how the wires are connected for the 7 segment driver example ?
You certainly can and you are absolutely right, the LED display has no ground connection, this is intentional.
A LED illuminates whenever current flows through it. It is a diode, so this will happen any time its anode is more positive than its cathode. The LED doesn't care whether its cathode is connected to ground or to an IO pin. It just does what it does based on the voltages at its two pins.
So, if your LED is connected between two IO pins and the anode side is at '1' and the cathode side is at '0' it will illuminate. This is the only case that makes it light up; For '00' and '11', the two sides are at the same voltage, so there is no reason for current to flow. In the '0' anode, '1' cathode case, the LED behaves like the diode it is and blocks any current flow, so no illumination there either.
So that explains why your LED lights both ways round but at opposite times; the two outputs you connected it to are flipping up and down really fast and at different times. The LED will light whenever the pin on its cathode is '0' and the pin on its anode is '1', which for two bits busy flipping up and down will be true some of the time whichever way round you connect your LED.
In fact, if you use the LED driver core instead of the test core and depending on what characters the display is showing, if you look carefully you may notice a difference in intensity for the LED in one polarity than the other because one pin happens to be spending more time in the '1' state than the other.
So, why doesn't the 7 segment display have or need a ground? It is because the core is doing what is called 'multiplexing'.
If we used a ground, we would need 32 (4 digits x 7 segments and a decimal point) IO pins to drive it. While the Guzunty could provide that amount of IO, there would hardly be enough pins left to tell it what to display! Instead, we drive just one digit at a time, but so fast your eye sees all the digits at once.
Thus, we get all four digits using only 12 IO pins; 1 'enable' pin for each digit plus the 8 pins for each LED of the digit. The ‘enable’ pins provide a temporary ground to the eight LEDs, current flows and the appropriate segments of the digit illuminate. Using the same signals to drive multiple devices is called ‘multiplexing'. In this case, the multiple devices are the four digits of the display.
Did we get something for free? Not really, the display is slightly dimmer as a result because the digits are being illuminated one at a time. However, we can choose the current limiting resistor values to compensate for that, so in a way we did get a free lunch.
The core uses a square wave output by the Pi on GPIO4 to tell it when to move to the next digit. When you use a signal like this to help the CPLD logic count the passage of time, it's called a 'clock' (though it doesn't tell the time, its more like the rhythm a drummer gives to a band). This clock is very fast to fool your eye. Armed with that knowledge, you don't have to take my explanation above on faith; If you change the demo code to slow the clock right down, you'll see the digit refresh happening with your own eyes. Go try it!
Finally, have a look at the LED driver waveform page, https://github.com/Guzunty/Pi/wiki/gz_l ... r-waveform
. The upper waveform shows the workings of the SPI interface, so it’s not relevant to our discussion here. The lower image shows the four digit enables (digit_enas) and it shows the seven segment signals (segments). Note that the displays I sourced did not have the decimal point working so I only needed seven signals.
The waveform tells you the same story as I did above but in chart form.
the same story. In practice, the LED display I used was a common anode type which means that the digit enable signals provide a temporary voltage source and those segments we want to illuminate are set to a zero. The principle is the same, current still flows, just in reverse. You can buy common cathode display types and in that case the story is exactly as above (but you’d need a slightly modified core which no one has asked for so far).
See how the digit enable bits go high one after the other diagonally up to the right and note how the segment signals switch configuration at the same moment to form the different digits. Some segment signals stay low for more than one clock cycle. That is because successive digits both require that segment to be illuminated. Segment 1 needs to be on for all four digits, so it never goes high (when displaying the example ‘2013’). From that, you can figure out that segment 1 is the upper right segment of the seven.
Conversely, some signals stay low for more than one clock cycle because they need to be off in successive digits. Although the pattern looks a bit complicated, if you study it you’ll see that it repeats every time the digit enables start again at digit 0.
One last comment; note that some devices would not like an LED being attached between IO pins in this way, but the CPLD in the Guzunty is designed to eat this kind of job for lunch. I wouldn't recommend doing multiplexing directly on the GPIO pins of the Raspberry Pi. If the LEDs were low enough power, you might get away with it, but you're better off with using a device designed for the job.
Hope that helps. Do please get back to me with any follow up questions you may have.
Guzunty: A fully programmable peripheral you build yourself! https://github.com/Guzunty/Pi/wiki