PDA

View Full Version : Discussion Servo Motor Controller NEED HELP


Newbie_pilot
Jan 18, 2009, 03:27 AM
I wanted to create a program which can do a countdown and activates the servo motor.

This are the things I intended to use:
Microcontroller chip: PIC18F452
Programming language: C language
Compiler: MPlab IDE

My project goes like this; when the microcontroller is ativated, it will start to do a countdown ( the time will be set in the program and the value will depend on the user ) and eventually activate the servo moving it from position A to position B.

I will divide my program into 3 section:

1. Countdown timer
2. PWM that moves the arm of the servo from position A to position B
3. return the servo arm to the original position after the task

I need help in the 1st and 3rd part. Hope someone who is experience in c language can guide me, thank you.

CombatWombat
Jan 18, 2009, 11:44 AM
To use C in MPLAB IDE you will need a C compiler, like Hitech-C, CCS, etc.

A Pic18 is also rather overkill for what you want, but if you have one on hand, there is nothing stopping you from using it. However, something like a 12F683 has CCP module, multiple timers, and is available in physically smaller packages (weight savings?).

1st part: use a timer (prefarably 16bit as it gives you more leeway in overflowing on longer delays). When the timer overflows go to the interrupt routine and switch your PWM to go to one extent. A google search for "pic timers" will give you many links on how to set the timer up for the delay you want.

You dont specify how you know when the task is complete, so I cant advice on how to know when to return to the original position.

Newbie_pilot
Jan 18, 2009, 12:03 PM
Hi,

Ok I will continue doing research on the pic timer. I did read some books on the timer example of the PIC but still not really familiar with them. Are they some short of delays which slow things down? In my case, if I want a countdown timer of 30seconds then I will need a delay of 30seconds :o .

Quote: You dont specify how you know when the task is complete, so I cant advice on how to know when to return to the original position.

- For the task to be completed, the sevo's arm has to move from position A to B (the arm at position B will indicate the task is completed). So I'm thinking of doing a 'reset' or some short of program which can return the servo's arm back to its original position (position A) after the arm has completed its task. Hope you get what I'm trying to say :p .

Thanks for the reply, hope that you can continue helping me.

Regards,
John

Malc C
Jan 18, 2009, 03:46 PM
It might help if you informed us what the project is, or what the servo will be doing once it reaches position B. If you want some form of timed switch then it's simpler to make a pin go high when the timer reaches zero and use that pin to drive a FET.

Tomapowa
Jan 18, 2009, 04:31 PM
Some similar projects are described here... with good details. Do a search in the forums here... you'd be amazed what has already been discussed.

http://www.rcgroups.com/forums/showthread.php?t=964916
http://www.rcgroups.com/forums/showthread.php?t=983121
http://www.rcgroups.com/forums/showthread.php?t=970142

Newbie_pilot
Jan 19, 2009, 07:30 AM
Hi,

Actually I'm a friend of Momo ( the TS of the 2nd thread ) and refering to the same project.
Yups, we did got some codes from some helpful people around here but what we are looking for are program written in C language.

Our supervisor wanted us to use MPLab c18 compiler for the project.

Just wanted some help on how we should we shall start on the c program code.

Thank-you.

Regards,
John

Tomapowa
Jan 19, 2009, 12:12 PM
You also need to determine which PIC you require for your app... as the PIC18F452 is way overkill. For servo control, a PIC that has a HPWM function (CPP/Hardware PWM) would be great. The PIC12F629 does not have this function but the PIC12F683 does... but for your app, you might get away with using the standard pwm function in a loop (small delays should work...). I can't help with the "C" but I'm sure there's plenty around there out on the web that should work. Some demo "C" compilers out there might even have some sample files that should help... this is a fairly easy project with servo PWM and a timer function (a few lines of code I would think).

Acetronics
Jan 20, 2009, 04:35 AM
Hi,


Our supervisor wanted us to use MPLab c18 compiler for the project.

Regards,
John

why not use a 18F1320 in 18 Pins package ??? :rolleyes: just for Mplab C18 :censored:

...

Note I realized a similar project ... with a 12F629 !!! ( no need PWM at all - just care with the timing !!! :cool: )

Alain