logo elektroda
logo elektroda
X
logo elektroda

How to Set 20kHz PWM Frequency on PIC30F6010A With 16MHz Fosc in My Code?

45 6
ADVERTISEMENT
  • #1 21664724
    Muniyasamy S
    Anonymous  
  • ADVERTISEMENT
  • #2 21664725
    Peter Evenhuis
    Anonymous  
  • ADVERTISEMENT
  • #3 21664726
    Muniyasamy S
    Anonymous  
  • ADVERTISEMENT
  • #4 21664727
    Syed Shadab
    Anonymous  
  • ADVERTISEMENT
  • #5 21664728
    Todd Hayden
    Anonymous  
  • #6 21664729
    Steve Lawson
    Anonymous  
  • #7 21664730
    Steve Lawson
    Anonymous  

Topic summary

The discussion addresses generating a 20kHz PWM signal using a PIC30F6010A microcontroller with a 16MHz oscillator. The original code produces a low-frequency PWM (~275Hz) despite changes to the PTPER register. Key insights reveal that the PWM frequency depends on the PWM period register (PTPER) and the timer count register (PTMR), with the PWM period calculated as (PTPER + 1) × 4 × TOSC × prescale. The frequency remains unchanged because PTPER is set higher than PTMR, preventing the timer from reaching the period value. It is also clarified that the PIC30F6010A has two PWM modules: simple PWM and motor control PWM, with the latter using its own time base. Correct configuration of PTMR and PTPER is essential, ensuring PTPER is less than PTMR for proper PWM operation. Suggestions include removing delay loops (which do not affect PWM frequency) and using simpler code or tools like MikroC to generate a 20kHz square wave by toggling port pins with precise delays. The importance of understanding the specific PWM module in use and configuring its registers according to the datasheet is emphasized.
Summary generated by the language model.
ADVERTISEMENT