EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise
You are here: Home / Topics / Generating PWM with PIC32MX460F512L

Generating PWM with PIC32MX460F512L

|

Microcontroller › PIC › Generating PWM with PIC32MX460F512L

  • This topic has 1 reply, 2 voices, and was last updated 7 years, 10 months ago by Hari Prasaath K.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • June 8, 2018 at 10:34 pm #4938
    Oteggewo Osojoh Ebot Sidney Smith
    Participant

    I am working on a project to generate PWM signal with PIC32MX460F512L to drive a motor. I have written the code to drive a motor with a signal of frequency 10KHz. I have tried to test my code but it is not work. I would appreciate of someone can advice me one how to proceed.

     

    #include <plib.h>

    #include <stdio.h>
    #include <stdint.h>
    #include "Cerebot.h"
    #include "Lcd.h"
    #include "config.h"
     
    void initTimer();
    void initOC();
     
     
    int main(void)
    {
    Init_Cerebot32MX(); 
    initTimer();
    initOC();
     
    _CP0_SET_COUNT(0); // Delay 4 Seconds
    while(_CP0_GET_COUNT()< 4*40000000)
    {
    ;
    }
     
    OC1RS = 500; // Set Duty Cycle to 50%
    TRISG = 0x0000; // Set PORTG as output
     
    while(1)
    {
    PORTGbits.RG12 = 0; // Set pin RG12 as output
     
    }
     
    } //end main
     
    void initTimer()
    {
    T2CONbits.TCKPS = 1; // Timer 2 Prescaler of 1:8
    PR2 = 999; // Period = (PR2+1)*N*12.5ns = 100us
    TMR2 = 0; // Initial TMR2 count is 0
    T2CONbits.ON = 1; // Turn on Timer 2
    }
     
    void initOC()
    {
    OC1CONbits.OCM = 0b110; // PWM Mode without fault pin
    OC1RS = 250; // Duty Cycle = OC1RS/(PR2+1) = 25%
    OC1R = 250; // Initialize before turning OC1 on
    OC1CONbits.ON = 1; // Turn on OC1
    }
    July 16, 2018 at 9:24 am #14859
    Hari Prasaath K
    Participant

    Hi,

    Mention about the error you faced with your code, and how do u tested that.

  • Author
    Posts
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
Log In

RSS Recent Posts

  • Smart Buoy project May 15, 2026
  • Need Guidance to reduce noise in 3-stage Transimpedance amplifier May 15, 2026
  • Wall Radiator Heating: Efficiency and Placement Questions May 15, 2026
  • Parasitic Draw Question May 15, 2026
  • Phone Charger 5v to 12v May 14, 2026

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2026 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise