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.

Controlling speed of DC motor using PIC18F452

Status
Not open for further replies.

Theo89

Newbie level 4
Joined
Feb 27, 2012
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,316
How do I program my PIC18f452 to control the speed of a DC motor. I just need a simple circuit and solution. Please forgive me I am very bad at writing code.
 

you can use pwm... set ports high at intervals after some delay.. if ur using mikroc there's a pwm function
 

Rajsekhar thank you for your help.. Actually my entire project is to control the speed of a DC motor using PWM on the 18F452. The speed will depend on the reflection of light on the surface of a chip. This is to help with the fabrication process. I am still doing my degree and this is something new to me... I would appreciate it if you have any sample codes for me to begin with because currently i am dumbstruck and unable to start.
 

First you have to tell us which compiler you are going to use.

mikroC has library functions for PWM built-in and they're pretty easy to use. Here's an example:
https://tahmidmc.blogspot.com/2011/06/example-of-how-to-generate-pwm-in.html

I would also recommend that you learn the workings of the PWM module in the PIC by reading about the CCP module and associated registers, so that, even if you use the mikroC functions and not the registers directly, you know what is happening.

Hope this helps.
Tahmid.

---------- Post added at 20:40 ---------- Previous post was at 20:38 ----------

For the mikroC PRO for PIC versions, you can use something like this:
Code:
void main (void){
     TRISC = 0;
     PORTC = 0;
     ADCON1 = 7;
     T2CON = 0;
     TMR2 = 0;
     PWM1_Init(40000); //40kHz
     PWM1_Set_Duty(128); //50% duty cycle
// Choose Duty cycle as such:
// PWM_Set_Duty(x);
// x = ( (Duty Cycle in %) / 100) * 255
     PWM1_Start(); //Start PWM
     while (1){ //Loop forever
// Whatever else might be needed to be done while PWM is running
     }
}
 

I really appreciate your help. I's actually using MPLAB IDE v8.70 as my compiler. Do you think the same code segment will work on different compilers??
 

No. The PWM library functions used are exclusively for mikroC. Which compiler are you using with MPLAB? Hi-Tech or CCS or something else? Your compiler will also provide library functions for PWM. Do check the manual.

Hope this helps.
Tahmid.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top