0
\$\begingroup\$

Short Question

Is a PIC24F16KM202 (Datasheet) powerful enough to vary the brightness of 12 LEDs from 12 PWM outputs without any visible stepping of brightness levels?

-------------------------------------------

Full Question

After using Microchip's PIC search tool to narrow down an MCU based on my project's requirements, it only really leaves me with PIC24F16KM202.

My concern is that some of the specs it has are at the very low end of the scale compared to other PICs, and having no real experience before with micro-controllers (this is my first MCU / electronics project), I'm not sure exactly if / how it will affect the performance of my project.

The project is really based on driving RGB LEDs via PWM, and I want to make sure that the PIC is capable of fading the LEDs smoothly with no visible jumping between brightness levels, and also if the MCU will be powerful enough to store and run the program.

I'd like to get some advice before buying some and finding out they're not going to be good enough and starting over.

Brief Project Outline:

  • 12*PWM to drive 4 sets of RGB LEDs independently (through transistors).

  • UART to connect to a bluetooth module (RN4020?) to control the colour of the RGB LEDs.

  • 6 input pins to change the state of the RGB LEDs.

  • EEPROM to store last state between on/off.

RGB LED colour will be changed infrequently by UART / bluetooth. Brightness / on / off will be driven frequently by 6 inputs.

PIC24F16KM202 specs:

  • Max. PWM Outputs: 16

  • PWM Time Bases: 5

  • PWM Resolution (bits): 16

  • PWM Resolution (ns): 62

  • CPU Speed (MIPS): 16

  • Program Memory (KB): 12

I've been reading the PIC24F Datasheet and Googling for ages to try and figure it out, but honestly I'm overwhelmed by the amount of information that I don't yet understand. I'd very much appreciate if someone could help me out by answering my question, and/or point me to some concise and relevant material that will allow me to learn how to answer the question myself.

Thanks for your time :)

\$\endgroup\$
  • \$\begingroup\$ You are nowhere saying how much current you need for your LEDS, say how big your program is, or quantify the required smoothness of your LEDs switching. Without that information how should anyone be able to tell if it is a match? \$\endgroup\$ – PlasmaHH Aug 20 '15 at 9:48
  • \$\begingroup\$ @PlasmaHH: Current: LEDs will be driven from transistors, so I guess current is minimal. Program Size: unknown, but I tried to give a description to indicate complexity/size. Required Smoothness: undetectable by the human eye. Sorry if the information is lacking, I'm very new to this. Thanks \$\endgroup\$ – parrowdice Aug 20 '15 at 9:52
  • 1
    \$\begingroup\$ "undetectable by the human eye" means different things depending on whether the observer is stationary relative to the LEDs. Also, if you find you need a more powerful PIC, it probably won't require "starting over". Just get some samples and try things .... \$\endgroup\$ – Roger Rowland Aug 20 '15 at 9:54
  • \$\begingroup\$ @RogerRowland: Interesting. What would be the difference between best and worse case (assuming stationary and 60mph relative difference)? \$\endgroup\$ – parrowdice Aug 20 '15 at 9:57
  • 1
    \$\begingroup\$ @parrowdice Yes they do. I'm in the UK and I regularly order samples. Small quantities and limited to three orders per month, but all free. Just have to wait a while for delivery. \$\endgroup\$ – Roger Rowland Aug 21 '15 at 8:23
3
\$\begingroup\$

Looking at the datasheet for that device, you would need to use the output compare function to control the PWM. However it looks like you wont be able to set 16 individual PWM periods, therefor this may not do what you are hoping. You would probably be better off using the outputs pins as general I/O and using interrupts to create your own PWM periods. If you do it yourself using interrupts, your choice of micros may open up.

\$\endgroup\$
  • 1
    \$\begingroup\$ This is the correct answer. The PWM frequencies you require are fairly low, and you can just set up a table in advance of (time to next event , pin to switch on/off) and run the whole thing off one high-priority timer interrupt. \$\endgroup\$ – pjc50 Aug 20 '15 at 10:57
  • \$\begingroup\$ How did you get that information from the datasheet? Do you mean I wouldn't be able to set 16 individual duty cycles? Wouldn't I just need 1 period, but to vary the duty cycle on the 12 different output pins? Thank you \$\endgroup\$ – parrowdice Aug 20 '15 at 12:12
  • \$\begingroup\$ This statement - 13.3 Output Compare Mode - Output Compare mode compares the Timer register value with the value of one or two Compare registers. Therefore you wont be able to have individual duty cycles, because there are only one or two comparison registers. \$\endgroup\$ – HandyHowie Aug 20 '15 at 12:24
  • 1
    \$\begingroup\$ Quite a few years ago I made a panel of stars to go above a bed. It had 88 white LEDs made to twinkle like stars by using PWM. It was controlled by a 16f877 PIC. You can see it here - handyhowie.co.uk/handyhowie/Stars.html \$\endgroup\$ – HandyHowie Aug 20 '15 at 20:22
  • \$\begingroup\$ @HandieHowie Very nice project! \$\endgroup\$ – Spehro Pefhany Aug 20 '15 at 23:18
3
\$\begingroup\$

Not sure any micro has 12 individual hardware PWM outputs. Other than that (not so) little detail, the micro you mention should be fine.

There are several options that come to mind:

  • use multiple micros- communication has to be figured out, but low risk

  • try to do PWM using existing peripherals on one chip- high risk of performance shortfall if you are very fussy- 7 bits may be almost undetectable steps for some people, for others it might take 10 bits. If PWM base has to be 1kHz the 1us jitter is 1 LSB. That's a 16 MIPS processor, not sure that it is practical to control 12 outputs to a microsecond or two.

  • use external CPLD or FPGA to do PWM- another development system with steep learning curve, but high flexibility and performance

  • use micro + ASIC chip designed for LED video sign with built in PWM- easiest option, in my opinion

\$\endgroup\$
  • \$\begingroup\$ I'm a little confused. On page 24 it shows at least 12 MCCP/SCCP/PWM pin outputs, or am I interpreting it wrong? Or are you saying that the pins can't be individually controlled, in which case, why are they individual pins? Thank you. \$\endgroup\$ – parrowdice Aug 20 '15 at 12:08
  • \$\begingroup\$ Can't you typically use multiple capture/compare registers on one timer to generate multiple PWMs with the same base frequency and tie them to outputs? You won't need 12 freely programmable PWMs to accomplish what is needed. \$\endgroup\$ – Arsenal Aug 20 '15 at 12:14
  • \$\begingroup\$ Can't see it now, but I think there are 5 individual PWM duty cycle outputs on this chip (2 SCCP + 3 MCCP). \$\endgroup\$ – Spehro Pefhany Aug 20 '15 at 12:18
  • \$\begingroup\$ @Arsenal OP only needs one period but I don't think the chip can generate 12 individually set PWMs. If the capture compare could be used with limits on min/max duty cycle that might be possible. It would take some studying of the docs. \$\endgroup\$ – Spehro Pefhany Aug 20 '15 at 12:20
  • \$\begingroup\$ Yes that seems correct, the description of the modules capability are a bit misleading (up to 6 outputs! (but only 2 registers for comparing)). \$\endgroup\$ – Arsenal Aug 20 '15 at 12:54
1
\$\begingroup\$

If I'm reading the datasheet correctly, you have 2 SCCP and 3 MCCP although the MCCP reads like it could output up to 6 PWM outputs, there are only 2 output compare registers per SCCP and MCCP, so even if you can use each of them as a separate output you'd end up only with 10 different duty cycles (I'm not sure if that is possible, actually).

So this PIC is probably not able to do that just with it's timer modules. If you want to do it that way, there are other controllers available.

The STM32F051 for example offers 8 timer modules, 7 have capture compare capabilities, in total you have 17 capture compare channels available (yes, each channel has it's own settable capture compare register).

You have to check for the right package though to get all those outputs not colliding with each other (they cannot freely be mapped to any pin on STM32)

(I mention this controller only because I'm working with it currently and have the datasheet open, there are surely other brands around which offer the same capability)

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.