Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Generating PWM with PIC32MX460F512L

Status
Not open for further replies.

ssquared

Junior Member level 3
Joined
Jun 6, 2015
Messages
30
Helped
1
Reputation
2
Reaction score
1
Trophy points
8
Activity points
213
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.

Code:
#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
}
 

Hi,

I have tried to test my code but it is not work.
This is no useful information.
--> give a detailed error description.

What did you already do to debug the code?
What were the results?
Comment out all code that you don't want to test, focus on what you want to test.

Klaus
 

Hi,

I think you are trying to generate a PWM so I would suggest you to break your code in pieces. First of all, simply generate a regular pulse and then try to change its frequency by fine tuning. PIC Microcontrollers have builtting pins but you have to enable the registers as well in order to use them for PWM purposes.

Thanks.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top