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:
https://www.imagesco.com/articles/picservo/02.html
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:
https://www.imagesco.com/articles/picservo/02.html