Using PWM with dsPIC30F6012 MCU

Discussion in 'Embedded Systems and Microcontrollers' started by satcom, Apr 2, 2015.

  1. satcom

    Thread Starter New Member

    Apr 1, 2015
    24
    0
    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.
     
  2. Papabravo

    Expert

    Feb 24, 2006
    10,145
    1,791
    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: Apr 2, 2015
  3. satcom

    Thread Starter New Member

    Apr 1, 2015
    24
    0
    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
     
  4. Papabravo

    Expert

    Feb 24, 2006
    10,145
    1,791
    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.
     
  5. satcom

    Thread Starter New Member

    Apr 1, 2015
    24
    0
    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.
     
  6. Papabravo

    Expert

    Feb 24, 2006
    10,145
    1,791
    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.
     
  7. jpanhalt

    AAC Fanatic!

    Jan 18, 2008
    5,696
    904
    Does it have to be for the dsPIC30F6012 ? Would code for other chips, like the 12F629 or 16F88 help?

    John
     
  8. blueroomelectronics

    AAC Fanatic!

    Jul 22, 2007
    1,758
    98
    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.
     
  9. satcom

    Thread Starter New Member

    Apr 1, 2015
    24
    0
    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?
     
Loading...