Pulsin alternative for 2khz pwm


Closed Thread
Results 1 to 4 of 4
  1. #1

    Default Pulsin alternative for 2khz pwm

    I have a 12F683 (8mhz internal osc) measuring the pulse width of a 2khz pwm signal coming in on the GP3/MCLR pin.

    I'm currently using pulsin (5us period) and get a resolution of 100 units over the 500us width of the PWM signal.

    I want to improve that to 256 units or better resolution by using timer1 and interrupts or similiar to capture the pulse length on the pin.

    The problem i have is what osc frequency will give me a reliable 256 units over 500us pwm pulse.

    Should I set the osc freuency to try and get as near to 256 as possible or just use as much accuracy as timer1 will provide at 8mhz, then manipulate the result to give my reqd 256 unit range.

    I can't easily change pin or I might have tried the Timer1 special capture mode.

    The CCP1 pin is also in use by another part of the software.

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,517


    Did you find this post helpful? Yes | No

    Default Re: Pulsin alternative for 2khz pwm

    Hi,
    Generally speaking, use as much resolution as you can and then manipulate your results after capturing. The reason for this is that you say you want 256 units or better. If you use as much resolution as you can then it's easy to tweak the result to whatever is needed later on - instead of changing the frequency again. The obvious drawback is that it needs calculations done to it aftwerwards which, depending on the application, may or may not be an issue.

    If you want 500us divided into a byte variable, ie 0-255, then each bit is "worth" 1.953125us which equals a frequency of 512kHz so clocking TMR1 with 512kHz will give a TMR1 value of 255 for 500us.

    TMR1 is 16bits wide, clocking it with Fosc/4 (using your 8MHz oscillator) and a prescaler of 1:1 means it overflows after 65536/2000000=32.768ms so it's MORE than enough for your 500us period. It'll give you a resolution of 1000 units since each timer tick is 0.5us.

    Again, the drawback here would be that if you really need 256 units then it'll be a "tricky" calculation since 255 doesn't divide evenly into 1000 but I think TimerValue**16712 should get you close.

    Too bad you can't use capture mode, it would have been ideal. Now you're going to have to use IOC since that's what's available on GP3 and then account for the interrupt latency when you grab the timer value.

    Only my $0.02 of course.

    /Henrik.

  3. #3
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,611


    Did you find this post helpful? Yes | No

    Default Re: Pulsin alternative for 2khz pwm

    Hi,

    Thinking closer to it ...

    IF you intend to use internal osc ... no real need for over resolution as your timebase precision will be out of the needed precision ...

    so ... whole project to clean up !!!

    too bad, ehhhh ????

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  4. #4


    Did you find this post helpful? Yes | No

    Default Re: Pulsin alternative for 2khz pwm

    Thanks for the ideas.

    One of the reasons I am looking to get the incoming 2khz PWM pulse into a 0-255 variable is that my device is passing through the pwm and using the HPWM output to mimic the input.

    So the input pwm is being measured, manipulated by my program if reqd and squirted out using hpwm which uses a byte variable for the duty.

    I'm trying to keep the maths simple and improve on the resolution that the pulsin command provides.

Similar Threads

  1. Alternative for 'printf'
    By Sach_1979 in forum General
    Replies: 1
    Last Post: - 25th September 2009, 02:02
  2. 18f4550 USB and pulsin or pulsin alternative
    By vacpress in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 15th January 2009, 14:14
  3. Pulsin alternative
    By sbobowski in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 4th October 2008, 10:21
  4. Alternative Methods ...
    By T.Jackson in forum Off Topic
    Replies: 3
    Last Post: - 9th June 2008, 14:13
  5. alternative Pin for vref
    By ruijc in forum General
    Replies: 6
    Last Post: - 15th January 2008, 11:46

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