1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

PWM formula confused

Discussion in 'Microcontrollers' started by elecLear78, Jun 18, 2017.

  1. elecLear78

    elecLear78 Member

    Joined:
    Jul 16, 2013
    Messages:
    226
    Likes:
    1
    Location:
    india
    I have seen the following formula for dpsic30f4011 formula for PDC duty cycle resolution calculation. What is the significance of this formula? Why should i do this calculation. I am asking this as i want to arrive the value from PTPER period register which is simple i assume. Do I need to do this calculation? please suggest. Another doubt i have is suppose if i want pwm frequency of 1KHz. The formula is Fcy/Fpwm - 1, so it is 20Mhz/1k -1 = 19999 PTPER value. So every count value corresponds to 0.05 Hz?

    upload_2017-6-18_13-48-16.png
     
  2. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,159
    Likes:
    907
    Location:
    Rochdale UK
    You don't do the calculation!!! That formula shows how you determine resolution ( the micro does it automatically ) from the Tcy and the tpwm.. When you select your period (PTPER) and your cycle count (PTMR) for the given tosc (Tcy) then the resolution will be X and X can be worked out using that formula..
     
  3. elecLear78

    elecLear78 Member

    Joined:
    Jul 16, 2013
    Messages:
    226
    Likes:
    1
    Location:
    india
    Thank you very much for the reply. Actually in one of my programs i was doing that calculations, now i can safely remove those calculations. But i am not loading any value into PTMR register. Is it OK? One doubt i have for a long time is PWM in any way related to any of timers (in any of pic families) that is if i disable all the timers, the PWM will still work? I have seen some example programs in some pic families where PWM and timer 0 are referred together. Please advise.
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,159
    Likes:
    907
    Location:
    Rochdale UK

    Okay... Basics! You load the PTPER with a value the PTMR will start to count... When the count matches the value in the PTPER the period ends... IF you are doing central align then bit 15 of the PTPER will allow a count down to end the period.. either way the period can be the size of a 15 bit register 0~32767..

    The duty cycle is controlled by the PDC registers PDC1~ PDC3 as up to three outputs are available..
    This way you can produce 3 phase ac outputs..

    The PTMR should run when the PTEN is set...

    Lastly!!! Remember the ancillary registers... The OVDCON register and ensure polarity is correct!!

    I am assuming you are controlling a BLDC motor... I can't see any hall inputs on this model!! I think you need to control the PEN bits manually!!
     
    • Like Like x 1
  6. elecLear78

    elecLear78 Member

    Joined:
    Jul 16, 2013
    Messages:
    226
    Likes:
    1
    Location:
    india
    Yes so many registers so many configurations. Very confused. :banghead:
     
  7. yuniorgr

    yuniorgr New Member

    Joined:
    Jul 5, 2017
    Messages:
    1
    Likes:
    0
    If you want you can use others tools like PIC Compiler for example. The setup and development of the project is more easy and you save time.
     

Share This Page