PyroElectro.com Forum Index PyroElectro.com
Build what you want, Be the pyro you are.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

DC Motor Control

 
Post new topic   Reply to topic    PyroElectro.com Forum Index -> Tutorials
View previous topic :: View next topic  
Author Message
ThePyroElectro
PyroElectro Admin


Joined: 12 Nov 2007
Posts: 401
Location: Earth

PostPosted: Mon Nov 12, 2007 10:36 pm    Post subject: DC Motor Control Reply with quote

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
View user's profile Send private message Send e-mail AIM Address MSN Messenger
Kevin
Newbie Pyro


Joined: 23 Nov 2007
Posts: 17

PostPosted: Fri Nov 23, 2007 9:48 pm    Post subject: Reply with quote

Hi Chris,

Firstly, I want to say that you have an awesome website for electronics tutorials. Keep up good work. Smile

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
View user's profile Send private message
ThePyroElectro
PyroElectro Admin


Joined: 12 Nov 2007
Posts: 401
Location: Earth

PostPosted: Fri Nov 23, 2007 11:02 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail AIM Address MSN Messenger
Kevin
Newbie Pyro


Joined: 23 Nov 2007
Posts: 17

PostPosted: Sat Nov 24, 2007 2:07 am    Post subject: Reply with quote

Dang it, they charge a shipping fee for the H-Bridge driver sample now. Do you know a "free" alternative IC? Very Happy
Back to top
View user's profile Send private message
ThePyroElectro
PyroElectro Admin


Joined: 12 Nov 2007
Posts: 401
Location: Earth

PostPosted: Sat Nov 24, 2007 3:50 am    Post subject: Reply with quote

Kevin wrote:
Dang it, they charge a shipping fee for the H-Bridge driver sample now. Do you know a "free" alternative IC? Very Happy


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
View user's profile Send private message Send e-mail AIM Address MSN Messenger
BushidoShonin
Newbie Pyro


Joined: 05 Mar 2008
Posts: 4

PostPosted: Mon Mar 10, 2008 2:52 pm    Post subject: Reply with quote

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
View user's profile Send private message
ThePyroElectro
PyroElectro Admin


Joined: 12 Nov 2007
Posts: 401
Location: Earth

PostPosted: Mon Mar 10, 2008 4:05 pm    Post subject: Reply with quote

Sure you can Cool , 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" Very Happy.
Back to top
View user's profile Send private message Send e-mail AIM Address MSN Messenger
BushidoShonin
Newbie Pyro


Joined: 05 Mar 2008
Posts: 4

PostPosted: Mon Mar 10, 2008 5:22 pm    Post subject: Reply with quote

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
View user's profile Send private message
ThePyroElectro
PyroElectro Admin


Joined: 12 Nov 2007
Posts: 401
Location: Earth

PostPosted: Mon Mar 10, 2008 10:34 pm    Post subject: Reply with quote

Hi BushidoShonin,

From your last few questions, I'm led to believe you don't have much experience programming in C/C++ Surprised . 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.

Exclamation If that's not the case, here's the answer to your questions:

Arrow (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:
Code:
int my_number = 0;


Arrow (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().

Arrow (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
View user's profile Send private message Send e-mail AIM Address MSN Messenger
1976922
Newbie Pyro


Joined: 26 Nov 2009
Posts: 1

PostPosted: Thu Nov 26, 2009 10:35 am    Post subject: Reply with quote

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
View user's profile Send private message
ThePyroElectro
PyroElectro Admin


Joined: 12 Nov 2007
Posts: 401
Location: Earth

PostPosted: Tue Dec 29, 2009 7:59 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail AIM Address MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    PyroElectro.com Forum Index -> Tutorials All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group