PWM = (pr2 + 1) x 4 x Tosc = HEadache!!

Discussion in 'Embedded Systems and Microcontrollers' started by dontventonme, May 30, 2009.

  1. dontventonme

    Thread Starter New Member

    May 30, 2009
    im working with MPLAB 8.30, C18 code.

    using pwm.h is fine, i can get things working good.

    though calculating the proper period from the datasheet formula is a bit confusing.

    i have a few different books, and tutorials and none of them give me a clear understanding of how to make sense out of getting the proper timing for a period. What weight does Tosc hold, is it one oscillation, or many?

    im working with a continous servo, and i need to achieve 20ms or so delay with 1.3-1.8ms high time.

    if someone has a tutorial of how to properly calculate this period to get proper values (since i cant seem to get them) that would be appriciated.

    with the openPWM2( (some random value) ); i can get it to pulse, but with out the proper timing i will probably blow the servo motor.

    thank you in advance for any help.
  2. mik3

    Senior Member

    Feb 4, 2008
    Tosc is the period of the uC oscillator (1/Fosc).
  3. dontventonme

    Thread Starter New Member

    May 30, 2009
    ty for replying.

    so i have:

    #pragma config FOSC = INTOSCIO_EC
    this proves to be 4mhz clock stable as of OSCCON

    so then its safe to say that 1/FOSC will be 250ns

    and then to get my 20ms i would have to add a scaler to break it down
    to get it to 20ms then.

    i will play with this a bit.

    thanks for some clarity, that helps alot.
  4. dontventonme

    Thread Starter New Member

    May 30, 2009
    period value = 250;
    ( (1/(4mhz / (16 prescaler)) ) x (period value) ) x (2 postscaler) = 20ms

    so with c18, 18f4550
    #pragma config FOSC = INTOSC_EC // 4mhz stable

    setDCPWM1(25); // gives 2ms pulse

    OpenTimer2(T2_PS_1_16 | T2_POST_1_2); // sets up scalers

    then this gave me the proper values needed.