Posted on Leave a comment

CH32V203C8 LED Clock – Part 2

4 April 2025

I got all of one more segment wired up, PB1 = segment b, when I discovered that PB2 is not wired to the connector pins of the WeAct Studio BluePill+ board. It is connected to an on-board blue LED via a 1.5KΩ resistor. I already knew about the LED, but assumed it was still brought out to the header pins. I assumed incorrectly.

This is not the show-stopper I thought it was last night. I just need to assign another pin to segment c duty and reconfigure the software. As long as I pick another pin on GPIOB, it will actually be pretty simple to accommodate.

It’s also worth noting that PB2 serves as the BOOT1 input, which controls how the chip boots up. In any case, it was not difficult to “adjust” the software to assign PB12 as the segment c driver pin. Since it also belongs to the same port as all the other pins currently being used, all I had to do was modify the bit mask used to set or clear the driver pins.

I had originally done the traditional read-modify-write cycle when controlling the GPIOB pins, wherein one reads the current state of the pins, clears the bits of interest, sets any required new values, then writes the result back to the output port. Then I remembered that the CH32V family of parts has the same bit-level control over the GPIO ports as the STM32, with which I have worked extensively in the past. You can set or clear individual bits without disturbing the other bits in the port by using the BSHR or BCR registers available on every GPIO port.

This worked well and had the additional benefit of allowing me to specify the segment bit masks as single ‘1’ bits, instead of ‘0’ bits. “Tomato, tomato,” I can hear you say. But just try coding some hexadecimal constants both ways and you tell me which one is both easier to wrote and later read again. I think you will agree with me, eventually.

So now I have a 1/32 duty cycle display with no visible flicker and a modest yet readable intensity. At this duty cycle, I can actually push triple the current through the LEDs, except that we’re nearing the limit (25 mA) of what the individual GPIO pins of the CH32V chip can deliver. And the whole point of this exercise was to see if we could get a reasonable display appearance with an absolute minimum of external components. At the moment, we’re using four (4) current-limiting resistors and no other driver components of any kind. I’m using through-hole axial 1/4W resistors in this prototype, as they are more breadboard friendly. The cost of the surface-mount versions of these components defies the imagination. They are almost completely free of cost, as far as the exchange of currency is required. The last time I bought them, they were less than one tenth of a cent per piece. Cheeep!

Right now the software is just going through a loop, illuminating each segment in turn. I need to add the actual time-keeping code to this project so that I will have a map of segments that can be turned on or off, as needed. That’s not going to be too difficult, I think, as I can just lift most of the code from the previous project and use it here, with minimal changes.

I’m also thinking I can up the apparent brightness of the display by not allocating a slot for all thirty two (32) possible segments. There’s no situation where this clock needs to display “8.8.8.8.” that I can envisage. What I ought to do, but can’t quite figure out a simple way to do it, is to map out all the possible segment patterns for the traditional 12 hour clock of my people and see what the maximum number of simultaneously lit LEDs actually is. Right now I only know it’s less than 32 and greater than zero, so we’ve got it properly bracketed for now. A more precise answer awaits. Anything that reduces the duty cycle will increase the apparent brightness of the display.

One option is to only scan through the display and light up the segments that need it, and not pause for the non-illuminated segments. The problem with this approach is that the more segments need displaying, the dimmer the overall effect. 10:08 is dimmer than 1:11, and that’s just not acceptable to me.

I also need to be thinking about just how wild I want to get with the individual colon LEDs that I have picked out for this prototype.

Leave a Reply