Using PWM with dsPIC30F6012 MCU

Thread Starter

satcom

Joined Apr 1, 2015
65
Can anyone show an example of assembly code for dsPIC30F6012 of using 4 channel PWM to control the brightness of the LEDs? (one channel per LED)
Besides, each PWM module feeds the numbers representing the light output required, obtained from Digital Filters, which separates input audio signal into four frequency bands.
 

Papabravo

Joined Feb 24, 2006
21,227
I have never been very happy with the use of PWM for controlling LED brightness.
The response is highly non-linear and compressed to one end of the spectrum. If I were doing it, I would use a voltage controlled current source. That way you could use the PWM through a low pass filter to control the LED current.

What frequency and duty cycle did you have in mind?
What voltages do you have available?
What is your clock frequency?
 
Last edited:

Thread Starter

satcom

Joined Apr 1, 2015
65
I haven't chosen these parameters yet, but PWM frequency should be around 300Hz. I will use 12V LED in the output, and MOSFET's IRF8313 to drive each bank of LEDs.
Not sure what would be better 4MHz Crystal or 7.37MHz
16xPLL - 64MHz/16MIPs at 4MHz XTAL
118MHz/30MPIs at 7.37MHz XTAL
 

Papabravo

Joined Feb 24, 2006
21,227
So depending on your clock frequency you'll want to set the period register of Timer 2 or Timer 3 to a period of:
1 /300 = 3.333... milliseconds. These timers feed the Output Compare device which is used to generate PWM waveforms. Do you have any reason for choosing Timer 2 over Timer 3?

7.3728 MHz. is a good frequency for baudrate generation. If high speed serial communications is part of the project I'd strongly favor this choice.
 

Thread Starter

satcom

Joined Apr 1, 2015
65
the application is LED lighting effect (light organ), where LED light is perfectly synchronized to the music.
The high speed serial communications is not a priority in this project.
I read spec about Interrupt Priority, but not sure about Timer 2 vs Timer 3.
 

Papabravo

Joined Feb 24, 2006
21,227
Timer 2 and Timer 3 are connected to the Output Compare Module. It is the output compare module that is most convenient for creating a PWM signal. I'd like to mention again that for this application you will be very disappointed with the results of using PWM directly on the LEDs. Much better results will be had by doing a PWM(voltage) to current conversion.
 

blueroomelectronics

Joined Jul 22, 2007
1,757
My guess is the OP is going to do some DSP stuff (the filters) and the 8 channel PWM is nice. They could just push curve tables into the PWM so it's not linear.

As for doing it in assembly, naa. do it in C. After all it's just a write to a register or two to change duty cycle once PWM is running.
 

Thread Starter

satcom

Joined Apr 1, 2015
65
yes, I want use digital filters to split audio into frequency bands, and dsPIC30F6012 is preferable. What's way to do PWM with voltage to current conversion?
 
Top