| View previous topic :: View next topic |
| Author |
Message |
ThePyroElectro PyroElectro Admin

Joined: 12 Nov 2007 Posts: 401 Location: Earth
|
Posted: Mon Nov 12, 2007 10:36 pm Post subject: DC Motor Control |
|
|
The DC Motor Control Tutorial Write-up
| Quote: | If you want your next project to be mobile, being able to reliably control
motors is a must. In this tutorial, we use the LMD18245 to control a simple
12v DC motor.
|
Questions & Comments? |
|
| Back to top |
|
 |
Kevin Newbie Pyro
Joined: 23 Nov 2007 Posts: 17
|
Posted: Fri Nov 23, 2007 9:48 pm Post subject: |
|
|
Hi Chris,
Firstly, I want to say that you have an awesome website for electronics tutorials. Keep up good work.
I have a question about the DC motor's speed. I have read the datasheet of the LMD18245, and I understand that to change the speed, you simply change V DAC of {M4,M3,M2,M1}. Therefore, you have the following code for full speed:
PORTC = 0b00001111; // 0x0F Full Speed
For 3/4 full speed, shouldn't it be 15*3/4 ~ 11 = 0b00001011 or am I missing something here?
This is what you have for 3/4 full speed:
PORTC = 0b00001110; //0X0B 3/4 Full Speed |
|
| Back to top |
|
 |
ThePyroElectro PyroElectro Admin

Joined: 12 Nov 2007 Posts: 401 Location: Earth
|
Posted: Fri Nov 23, 2007 11:02 pm Post subject: |
|
|
Hi, thanks for checking out the site.
You're right.
11 = 0x0B = 0b00001011
Looks like i made a typo. I'll go ahead and correct it in the tutorial.
Thanks for the comment
~Chris |
|
| Back to top |
|
 |
Kevin Newbie Pyro
Joined: 23 Nov 2007 Posts: 17
|
Posted: Sat Nov 24, 2007 2:07 am Post subject: |
|
|
Dang it, they charge a shipping fee for the H-Bridge driver sample now. Do you know a "free" alternative IC?  |
|
| Back to top |
|
 |
ThePyroElectro PyroElectro Admin

Joined: 12 Nov 2007 Posts: 401 Location: Earth
|
Posted: Sat Nov 24, 2007 3:50 am Post subject: |
|
|
| Kevin wrote: | Dang it, they charge a shipping fee for the H-Bridge driver sample now. Do you know a "free" alternative IC?  |
The L298 is another very popular H-Bridge. I use the LMD18245 because
they are particularly easy to get setup, working & troubleshoot.
I'd stick it out if you can for shipping but st.com should have L298's for sample. |
|
| Back to top |
|
 |
BushidoShonin Newbie Pyro
Joined: 05 Mar 2008 Posts: 4
|
Posted: Mon Mar 10, 2008 2:52 pm Post subject: |
|
|
When programming the PIC can you use variables to represent a specific port/pin? somethin like this:
Break = "PORTBbits.RD0"; // Brake
Dir= "PORTBbits.RD1"; // Direction
then later when you want to do something with these all you have to do is:
Break = 1;
Dir = 1;
Would something like this work? |
|
| Back to top |
|
 |
ThePyroElectro PyroElectro Admin

Joined: 12 Nov 2007 Posts: 401 Location: Earth
|
Posted: Mon Mar 10, 2008 4:05 pm Post subject: |
|
|
Sure you can , use the #define statement at the very top of your program.
Example (top two lines are what you're looking for):
| Code: | #define Break PORTBbits.RD0 // Brake
#define Dir PORTBbits.RD1 // Direction
...rest of your program...
#include <p18f4550.h>
...
..
void main(void)..{
..
}
|
This makes it so whenever you type Break or Dir in your program it actually means "PORTBbits.RD0" or "PORTBbits.RD1" . |
|
| Back to top |
|
 |
BushidoShonin Newbie Pyro
Joined: 05 Mar 2008 Posts: 4
|
Posted: Mon Mar 10, 2008 5:22 pm Post subject: |
|
|
Thanks a lot, but I have a ton more questions.
First: How would you define a number variable? Like this?
int var1 = 123
Second: How would you state a random number? Like this?
int randNum = (rand() / RAND_MAX) * 100 //Random number between 0 and 100
Third: When defining a var like in my last post, does this all have to be outsite the main function? |
|
| Back to top |
|
 |
ThePyroElectro PyroElectro Admin

Joined: 12 Nov 2007 Posts: 401 Location: Earth
|
Posted: Mon Mar 10, 2008 10:34 pm Post subject: |
|
|
Hi BushidoShonin,
From your last few questions, I'm led to believe you don't have much experience programming in C/C++ . If that's the case I'd really suggest finding a free online "Learn C in 24 Hours" ebook. You can find one just through a simple google search and then skim through it to get the basics.
If that's not the case, here's the answer to your questions:
(1)
In C numbers are stored in numerical data types (int, long int, double, float to name a few). The proper syntax for declaring a numerical data type is:
(2)
In order to generate a random number you will need a library that provides some type of random number generator. The stdlib.h library included with the PIC C18 library provides such functionality with the rand() function.
Bear in mind that rand() may produce similar values in each trial unless you seed some dynamic value into the random number generator using srand().
(3)
The previous post defined no actual value. It equated that whenever the compiler sees 'Dir' it should replace it with 'PORTBbits.RD1' before compiling the code.
The C18 compiler is based off of ANSI C which means variables should be declared after the main statement and not mid-way through the program. |
|
| Back to top |
|
 |
1976922 Newbie Pyro
Joined: 26 Nov 2009 Posts: 1
|
Posted: Thu Nov 26, 2009 10:35 am Post subject: |
|
|
Hi Chris,
According to your project, it just utilize h-circuit and processor to control the motor. Do you have an experiment that using h-circuit and motor encoder/decoder via processor to be a close loop circuit to control the motor?
Since I have some confuse for the motor encoder, would you please to give me some comment or suggest?
Since I know that has chips to be the encoder/decoder, the motor which I have included a internal encoder. Is this encoder's function can be the Optical Encoder. Moreover, I don't have decoder chip. How about the flow path for program of decoder in 8051.
Thank you so much.
Matt |
|
| Back to top |
|
 |
ThePyroElectro PyroElectro Admin

Joined: 12 Nov 2007 Posts: 401 Location: Earth
|
Posted: Tue Dec 29, 2009 7:59 am Post subject: |
|
|
Hi Matt,
I'm working on a write-up like that. I don't currently have any tutorials or projects with closed loop systems. Sorry!
Best of luck. |
|
| Back to top |
|
 |
|