Basically my question is, what is the maximum number of PWM outputs on the Artemis Nano I can use, if I want 10ma from each to drive LEDs, and also a single i2c bus for a breakout board. I’m hoping to get 16 of the 17 total pwm outputs, and use the two remaining GPIOs for i2c, if I can. I will probably have to use the GPIOs from the Qwicc connector. The 3.3v regulator is meant to have a maximum current of 300ma, so I’m hoping I can source 160ma from the GPIO at once for LEDs.
Explanation:
For my project, I need at least 24 PWM outputs to power LEDs , to drive 3 of the Dual 7-Segment Display - LED (RGB) (https://www.sparkfun.com/products/13999).
I am going to use the SparkFun 16 Output I/O Expander Breakout (https://www.sparkfun.com/products/13601) to give me this plus more. But I later found out that this breakout is optimized for current-sink driving of LEDs, not current-source which I need because of the way the LEDs are multiplexed. This is a slight problem because the max output of this breakout is 8ma per pin and I need 10ma for the red LEDs. Correct me if I’m wrong, but I’m going to use MOSFETs to switch this slightly larger amount of current. I want to solder the least amount of MOSFETs possible, so I want to use as many of the PWM outputs on my microcontroller instead.
Thanks for the details on the project it really helps with some context so I can help you as best I can.
First of all - I assume you are planning something unusual with the 7-segment displays? Because if you are just wishing to display text you could save a lot of hassle using this product (lots of color options too!): https://www.sparkfun.com/products/16425
Wait a minute I just took a closer look and realized that the display you show is RGB. That’s pretty cool.
Good research into the problem also. I looked at the datasheet of that pin expander and confirmed what you are saying. How come you need 10 mA exactly? Have you tested that brightness and decided it is what you want? I only bring that up because it might not be a total dealbreaker. But it is understandable if you need more current driving capability, particularly to balance the R, G, and B channels visually.
Okay so now to actually provide an answer about the PWM on the Nano. The Apollo3 is a little weird with its hardware PWM generation - it has 8 timer modules, each with two “halves” of a timer (up to 16 now) and each of those can have two outputs (up to 32 now). However the two outputs on a particular half are not completely independent. The frequency of the “master” output must determine the frequency of the “slave” output. For some uses this restricts the Apollo3 to just 16 independent PWM outputs. But in your case (when only the duty cycle is important - not the frequency) you should be able to use all 32. Now we just need to make sure that there are indeed 16/17 PWM GPIO exposed on the RedBoard Artemis Nano. (You could definitely achieve this with the “ATP (all the pins)” version btw - but of course the Nano form factor is very cool) Checking out the schematic (https://cdn.sparkfun.com/assets/5/5/1/6 … s-Nano.pdf) confirms that there are 17 PWM outputs that are exposed - sadly two of them are hidden in the Qwiic connector (as you suggested). There are test points that you could solder to and there are cables that you could purchase to get at these pins. But if you still want I2C functionality… then you would need a pair of SDA/SCL lines from the same IOMaster. You’re in luck - pins 9 and 10 are SCL and SDA of the IOMaster #4 respectively. Only one (pin 9) was a PWM pin to begin with. So just like magic your prediction is in fact true. You can get 16 PWM pins with two remaining to run I2C. Each pin should be able to have its own duty cycle as long as master/slave output pairs share a frequency (which should not affect this application). I recently fixed some bugs in the Arduino PWM interface (analogWrite) and made some improvements that should make this easy for you to set up in code.
Ooh minor disappointment - I just realized that you are trying to drive at least 3 segments - requiring 24 outputs not 16… One Nano could drive two segments without any help (edit: no it can’t, we need addtl pins for cathode control). (I thought you might still want I2C for sensor readings or something). Hmmm. I do have one concern - matching the apparent brightness of the Nano PWM and the expander PWM might require a little work - perhaps all in software. Not a deal breaker but a consideration.
Grr… an Artemis Thing Plus has 21 GPIO… closer but not quite 24 yet! (Not to mention that you also need 3 more GPIO per digit to control the low sides…) Ahh I was hoping that it might do the trick and keep the nice small form factor.
You can definitely do what you need using only capabilities of the Artemis module. It seems like none of our boards can do it except the RedBoard Artemis ATP which has a large form factor.
Here’s another thing you could consider… try prototyping this with the ATP (https://www.sparkfun.com/products/15442). When you get it working you could design a board that would accept an Artemis module as well as your displays. That would be a very slick compact way to build what you have in mind and it would not require an in-between IO expander. If you have never designed a PCB before it could be a fun way to develop a new skill. If you had questions about how to do it you could post in the “Designing with Artemis” forum and I’m sure some people would be eager to help out. (here’s one post of someone who built their own carrier board viewtopic.php?f=170&t=51685)
Wow - that was a fun one to think about. Thanks for sharing. Whatever route you end up taking I hope you’ll share the end result with us. It would be cool to see.
Thanks so much for all of that! I’m going to use the Multiplexer Breakout - 8 Channel (https://www.sparkfun.com/products/13906) for the low side switching, which will be controlled by the I/O expanded, which is controlled over i2c. I glossed over the Artemis Nano Schematic and didn’t see it had so much info about the pins! (forgot that “~” could mean pwm!)
So if my SDA4 and SCL4 are on IOMaster #4, what does this mean? The concept of an “IOMaster” seems to be a Sparkfun / Ambiq specific term, how does it work in terms of programming?
Anyway, seems like it should work, and I’ll have 1 pin left! Can I use this pin for a One-Wire temperature sensor?
The IOMaster is the name of the particular peripheral hardware / IP that resides within the Apollo3 to handle I2C / SPI communication. There are 6 of them (0, 1, 2, 3, 4, 5) and they each are connected only to one set of pads (they cannot be remapped).
You probably can do that. I think you will have to handle the 1-Wire protocol entirely in software however because there is no built-in 1-wire driver. Perhaps you could take advantage of some of the other peripherals like timers