Low frequency PWM


Closed Thread
Results 1 to 4 of 4

Hybrid View

  1. #1
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Re: Low frequency PWM

    Well heres my thoughts:

    If writing to a pin will cause too much delay, then software PWM is out anyway I think. I may be wrong, but it seems to me that is like a pause. What I mean is program waits for the pwm to finish before going further.

    I am not sure of the above, someone PLEASE correct me if I am wrong!!

    you say you want 100 to 125 Hz. Does that mean you can tolorate variation between the 2? ie: 112 Hz plus or minus 12 Hz?

    You can get twice as much time to do things if you run the pic at 8MHz. Double the instructions executed in the same time.

    Use timer 2 with a prescale set to 16, tmr2 output would then be 500K (@8Mhz). set the postscale to 16 and you will get a flag at 122Hz on TMR2IF with PR set to 255.

    Just poll TMR2if in your main if you don't want to use interupts.

    You haven't given any info as for the resolution you want for the duty cycle but I think you can play with PR to get your duty cycle. but I need to think about that some more.
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  2. #2
    Join Date
    Dec 2010
    Posts
    409


    Did you find this post helpful? Yes | No

    Default Re: Low frequency PWM

    I can tolerate variation in the absolute frequency (say 112 +/- 12 or even a little more) as long as the on / off ratio is stable. I have flexibility in the resolution too - I've been targetting 11 (ish) ratio positions including 0%, 10%, 20%, ... 100%. I need full off and full on.

    Polling TMR2 is an interesting idea I have not explored - I'll play with that for a bit and see where I get to. Thanks for a new lead!

  3. #3
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Re: Low frequency PWM

    Using the polling method the "stability" will be dependent on the duration of the main loop.

    Absolute on and off is easy, set or clear the output

    if you use a PR value so TMR2IF sets 10 times per period, you can use a counter to decide when to turn the output on/off

    Again accuracy will depend on loop duration, but running at 8Mhz will more then likely be plenty fast enough to give you a barely noticable error.

    Ok some math and assumptions:

    lets assume you have 1000 ASM lines to process for each loop. That would take .5msec.
    If you output is 100 Hz, thats 10 msec. So with these numbers, I guess you could be off by 5% on the duty cycle. Hmmm... Not so good. But 1000 lines is HUGE. Also you could check the count in 5 evenly spaced places throughout your main, then the possible error would only be 1%. In case I have stated this wrong, I mean to say 10% duty could be 11%, or 90% could be 91%. So I guess I don't mean duty cycle % error, I really mean the time it takes to get to the next counter check.

    Hopefully I have not confused you or anyone else too badly.

    If you need utmost accuracy, use interupts
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts