![]() | ![]() | ![]() |
| | |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
| | Thread Tools | Display Modes |
| | (permalink) |
| New Member | Hi, I need your help on the following problem. I'm trying to use PIC18F452 microcontroller to drive a servo motor. The circuit I built is quite simple. It consists of a crytal oscillator with frequency of 4MHz with 2 22pf capacitors and 1 more capacitor and 1 resistor just for voltage supply purpose. I programmed the uC using C18 compiler and MPLAB ICE2, the code I'm using is as follows: #include <p18f452.h> #include <pwm.h> #include <timers.h> void main(void) { TRISC = 0b11111011; PORTCbits.RC2 = 0; OpenPWM1 (0xF0); OpenTimer2 (TIMER_INT_OFF & T2_PS_1_1 & T2_POST_1_1); SetDCPWM1 (1024); } I want to send a pulse train of 20ms of period and 8% of duty cycle to port C (RC2) of the uC, but it seems that I cannot get the priod and duty cycle desired using the formula: PWM period = ([period] + 1) * 4 * Tosc * prescaler... Also when I try to see the signal on the oscilloscope, it could not get it. Do i have to include some kind of high resistor between PORTC and the oscilloscope probe? I hope you could help me to figure this out. How to get the period desired and to display them properly to the oscillator? Is there anything that need to be added into the circuit i built. it's kind of simple but I dun know what to improve. Thank you very much and hope to hear from you soon. :? P.S. the circuit i built looks quite like this one: http://www.imagesco.com/articles/picservo/02.html |
| | |
| | (permalink) |
| Experienced Member | Did you use any sort of external driver? A PIC pin only puts out 20mA or so and cannot drive a motor. Also a motor's inductance creates spikes with PWM, this might even cause latchup in your device if the motor is on the pin without a flyback diode. You need a bipolar or MOSFET transistor and a protection diode on it.
__________________ I thought what I'd do was I'd pretend I was one of those deaf-mutes. |
| | |
| | (permalink) | |
| New Member | Sir, the servo motor I used has its own voltage supply, please refer to the below figure for the circuit: ![]() The only difference is I'm using PIC18F452 instead of PIC16F84 and the output port is set to RC2 instead of RB0 as shown in the diagram. Quote:
Pls help me figure this out. Thank you. | |
| | |