Measuring duty cycle of short duration pulses with long period


Closed Thread
Results 1 to 13 of 13

Hybrid View

  1. #1
    Join Date
    Jun 2005
    Location
    West Australia
    Posts
    116

    Default Measuring duty cycle of short duration pulses with long period

    Hi All,

    I want to measure the Duty Cycle of piezo automotive (in particular diesel) injectors where typical idle on-time is 500us and full load is 1000us. Results will be used in a feedback loop to control other parameters. The clincher is shortest period will be around 20ms or 50hz frequency at maximum revs so the pulses are far between noting only one cylinder's injector needs to be monitored.

    With gasoline solenoid injectors this is easy as their on-time is measured in ms so DC math follows the traditional (on-time*100)/off-time.

    I can probably rig up some analog stuff to integrate the pulses and then scale the output voltage in A2D measurement but the varying frequency component will have major effects and is totally devoid of digital precision in the acquisition section.

    I can't think of any way to measure/calculate DC without first defining what 100% DC is in microseconds - can this be done otherwise in real time? PIC of choice is 16F88 but can be changed if required.

    All suggestions appreciated.

    Regards,
    Bill

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


    Did you find this post helpful? Yes | No

    Default Re: Measuring duty cycle of short duration pulses with long period

    What sort of resolution do you need and what is the longest period (minimum rpm) you're expecting?

    On rising edge of signal, start timer.
    On falling edge of signal, read timer, this is the "on-time".
    On next rising edge of signal, stop timer, this is the period time. While waiting here you need to keep track of the number of overflows that occurs and add up the total time.

    /Henrik.

  3. #3
    Join Date
    Jun 2005
    Location
    West Australia
    Posts
    116


    Did you find this post helpful? Yes | No

    Default Re: Measuring duty cycle of short duration pulses with long period

    Hi Henrik,

    Thanks for the reply - I knew I could count on you for some helpful advice.

    I understand the concept you've mentioned and have this working with good results - if I state 100% DC is 1000us. I'm using a 12F683 with 2 pots to emulate the engine, one for variable frequency (5-55hz = 600-6600rpm) the other for variable pulse width (0-1000us) and a switch for pulse polarity choice. Resolution needs to be 10us (equivalent to 1% DC).

    How do I track the overflows? I've not delved into timers before this.

    Thanks for your help as always,
    Bill

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: Measuring duty cycle of short duration pulses with long period

    Hi Bill,
    Your definition of dutycycle differs from mine but I think I understand what you want.
    The period (on-time + off-time) of the signal is 18-200ms and the on-time is 500-1000us. You want to measure the dutycycle, ie the ratio between on-time and period.

    If the period is 125ms and the on-time is 565us the dutycycle is 4.52%.
    If the period is 45ms and the on-time is 795us the dutycycle is 17.66%.

    Is this the number you're after?

    Let's see if we can make this easy....
    The longest time you want to measure is 200ms. Using a 16bit timer with a 4us "tick" you'll measure up to 262ms with 4us resolution without having to worry about overflows. Then the overflow can be used to signal invalid mesasurment (motor not running).

    Are we on the right track?

    /Henrik.

  5. #5
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: Measuring duty cycle of short duration pulses with long period

    795us over 45ms is 1.76%, not 17.6% as I wrote earlier.

    Anyway, here's a piece of code that may do what you want. It uses TMR1 and CCP1 to measure the input signal, calculates the dutycycle and displays it with .1% resolution. It compiles for a 16F88 but I have not tested it.
    Code:
    ' Program expects 4MHz oscillator.
    ' CCP1 inputpin is either RB0 or RB3 depending on the CCPMX bit in CONFIG.
    
    CapRise CON %00000101		' Value to configure CCP1 for capturing every rising edge
    CapFall CON %00000100		' Value to configure CCP1 for capturing every falling edge
    
    CCP1IF 	VAR PIR1.2		' Alias to CCP1 Interrupt flag
    
    Period 	VAR WORD
    Width 	VAR WORD
    Duty 	VAR WORD
    Dummy	VAR WORD
    
    T1 	VAR WORD
    T2 	VAR WORD
    T3 	VAR WORD
    
    T1CON = %00100001		' TMR1 clock from FOsc/4, Prescaler 1:4
    
    Main:
        ' Capture the the time where the pulse starts
        CCP1CON = CapRise
        CCP1IF = 0
        WHILE !CCP1IF : WEND
        T1.HIGHBYTE = CCPR1H : T1.LOWBYTE = CCPR1L
    
        ' Capture the time where the pulse ends
        CCP1CON = CapFall
        CCP1IF = 0
        WHILE !CCP1IF : WEND
        T2.HIGHBYTE = CCPR1H : T2.LOWBYTE = CCPR1L
    
        ' Capture the time where the period ends (which is when the next pulse starts) 
        CCP1CON = CapRise
        CCP1IF = 0
        WHILE !CCP1IF : WEND
        T3.HIGHBYTE = CCPR1H : T3.LOWBYTE = CCPR1L
    
    
        Width = T2 - T1
        Period = T3 - T1
        Dummy = Width * 1000
        Duty = DIV32 Period
    
        ' Duty is now in units of .1% (111 = 11.1%)
    
        LCDOUT $FE, 1, "W:", DEC Width, " P:", DEC Period
        LCDOUT $FE, $C0, "Duty:", DEC Duty/10, ".", DEC Duty//10, "%"
    
    Goto Main
    /Henrik.

  6. #6
    Join Date
    Oct 2012
    Posts
    82


    Did you find this post helpful? Yes | No

    Default Re: Measuring duty cycle of short duration pulses with long period

    I’m not sure how much this will change things but shouldn’t maximum period expected be 20 ms not 200 ms?
    And if it is so, should the timer setup be changed or it will still work?

    Nick

Similar Threads

  1. Count Pulses and duration
    By ruijc in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 13th February 2014, 22:04
  2. Measuring Period of a pulse
    By c_moore in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 17th February 2012, 05:15
  3. Measuring duty cycle when it can be 0 to 100.
    By Tobias in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 3rd December 2011, 18:24
  4. Pin max current - short duration?
    By kevj in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 2nd January 2008, 12:53
  5. Measuring Period & Hz
    By MaurI in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 29th July 2005, 04:03

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