I found Rpi ahs 4 PWM pins. I decided to use Pin 18 to test the water. Below is the hardware setup. Now I have debugged a python program to do the following. Set GPIO pin 18 high for 2 seconds, to switch on Blue LED to full brightness. Set the same GPIO pin 18 to output PWM of 1kHz, 50% duty cycle, to switch on/off Blue LED to result half. So I'd like to know if it is possible to drive multiple pins with PWM using a single PWM block and DEMUX. The idea is as follows: PWM frequency is 50 Hz. Duty cycle on time is around 0.5 ms to 5 ms. So, I thought that I could start pwm on pin 1, wait for a falling edge interrupt.
Attention, Internet Explorer UserAnnouncement: Jive has discontinued support for Internet Explorer 7 and below.In order to provide the best platform for continued innovation, Jive no longer supports Internet Explorer 7.Jive will not function with this version of Internet Explorer. Please consider upgrading to a more recent version of Internet Explorer, or trying another browser such as Firefox, Safari, or Google Chrome.(Please remember to honor your company's IT policies before installing new software!).
Check for missing pinsThat does look like it should work exactly as described in the datasheet. The main thing to watch out for is missing pins on lower pin-count packages; in this case ST put a full complement of 16 pins on ports A-C and simply added new ports (D and E) for the 100-pin version. Fortunately, none of your required pins are on ports D or E. Check for over-stated resourcesThe other thing to watch out for is designs that use muxes to share hardware. On some micros with equivalent marketing specs there might only be four output compare units muxed between each timer.
This would prevent you from using all the features at once, but it looks like this controller has a startlingly large amount of silicon dedicated to timers and it appears that you're good to go. Check that this is really necessary Do you really need 84 MHz PWM clocks?That said, 16 PWM outputs sounds like an awful lot for most of the high-speed applications I can think of like motor control, switch-mode power supplies, and power-factor correction. If you are in fact doing one of these things on 16 channels, then your product's primary purpose is probably to perform this PWM and it's perfectly acceptable and normal to use this hardware for this purpose.
Or can you do it with less hardware and some software?However, 16 channels sounds more like you're dimming an array of LEDs. If you're just dimming LEDs, then you can run your PWM at frequencies as low as 100 Hz or so, and there's little reason to utilize all this hardware for such a simple, easy task. Use one timer and some simple (fast) arithmetic in it's ISR to control the PWM for as many channels as you like on ordinary GPIO pins.ST went to a lot of expense to put some impressive hardware clocking silicon in this chip. If your design is likely to go through future iterations, you should consider whether you really want to use this hardware for something as simple as making an LED glow. You'd be using your only 32-bit timers, 4 of 6 timers with down and up/down counting ability, 4 of 8 timers with DMA request generation ability, and 8 of 18 capture/compare channels. If you're likely to make changes or add features that might need this hardware later, it doesn't make sense to use it for LED modulation.As I said before, though, if PWM is what you're doing, then use the hardware! Page 30:The STM32F40x include 4 full-featured general-purpose timers: TIM2, TIM5, TIM3, andTIM4.The TIM2 and TIM5 timers are based on a 32-bit auto-reload up/downcounterand a 16-bit prescaler.
The TIM3 and TIM4 timers are based on a 16-bit auto-reloadup/downcounter and a 16-bit prescaler. They all feature 4 independent channels forinput capture/output compare, PWM or one-pulse mode output. This gives up to 16input capture/output compare/PWMs on the largest packagesIt doesn't say which packages it are, but likely it's 144 and 176 pin devices, maybe 100. You'd have to check those pin ports and see if they are present, including the output compare I/O function.According to that paragraph, each timer can be connected to 4 output compares.
The output compare set the duty cycle basically, and the timer the frequency. Thus in the end you can have 4 groups with a set frequency, but each with an individual duty cycle.I don't know how critical the PWM accuracy is, or you're trying to get some continuous control of some sort, you could also try:.
Software PWM, manually setting output ports. Takes one timer and more processor time. PWM drivers, basicaly LED drivers abused as PWM drivers. PCA9634 for example, does fixed frequency(97kHz) but with an individual duty cycle. There are also 16-channel versions.
TI also makes a ton of LED Drivers, but most of those have constant current outputs, which I kinda avoid to interface with.I wouldn't see why this isn't advisable thing to do. If the chip can do it, go ahead.
Things I would consider is whether you can get the desired duty cycle accuracy at the set frequency. For example, if you need a 10-bit duty cycle accuracy (like 0-100% is set up in 0-1023) and 100kHz output, you basically need a 2^10.100k=102.4MHz reference clock.So actually, PWM is not just PWM, to be more specific about whether the chip suits your needs, maybe you could tell us more about the speed and accuracy required?