2x1=10

because numbers are people, too
Persönliches
Fotografie
Programmierung
    • Frequency-variable PWM generator in Simulink

      I recent­ly came across the prob­lem that I need­ed a PWM (i.e. pulse-width mod­u­lat­ed rec­tan­gu­lar sig­nal) gen­er­a­tor block in Simulink with vari­able fre­quen­cy and duty cycle inputs. I couldn’t find one in the library, so I wrote one.

      Frequency-Variable PWM in Simulink

      The rather sim­ple imple­men­ta­tion basi­cal­ly con­sists of three parts: An inte­gra­tor block with an exter­nal reset input is used to cre­ate a saw­tooth sig­nal. The saw­tooth is then com­pared to a thresh­old val­ue giv­en by means of the duty cycle to cre­ate a rec­tan­gu­lar sig­nal. Last­ly that sig­nal is scaled to a stan­dard out­put range of 0..1.

      Frequency-Variable PWM in Simulink

      The edge or lev­el trig­gered reset input can be enabled in the integrator’s block prop­er­ties. The block is then wired to inte­grate the fre­quen­cy val­ue and be reset when­ev­er the out­put cross­es the val­ue of one. This can be real­ized by sub­tract­ing one and com­par­ing the result to zero.

      The result­ing saw­tooth sig­nal then looks like the fol­low­ing, assum­ing a con­stant fre­quen­cy of 1Hz:

      PWM generator sawtooth

      By sub­tract­ing the saw­tooth from the duty cycle “fac­tor” and tak­ing the sign, the rec­tan­gu­lar sig­nal is cre­at­ed. Since the sign block cre­ates val­ues in the range of -1..1, a shift and scale is applied to bring it to the range of 0..1.

      This is what the result looks like with a fre­quen­cy of 1Hz and a duty cycle of 25% (like in the first pic­ture):

      1Hz PWM 25%

      When apply­ing a fre­quen­cy ramp — 1Hz/s in the fol­low­ing exam­ple — with the same duty cycle of 25%, a chirp-like out­put sig­nal is cre­at­ed:

      1Hz/s Chirp PWM 25%

      And this is what it looks like when keep­ing a con­stant fre­quen­cy (1Hz again) while ramp­ing down the duty cycle by 25%/s from 100%:

      PWM generator duty cycle ramp-down

      That last exam­ple is a bit counter-intu­itive though as the duty cycle is reduced con­tin­u­al­ly (as opposed to every sec­ond), which is — for exam­ple — why there is no seg­ment of 100% duty cycle; but you’ll get the idea.

      April 10th, 2014 GMT +1 von
      Markus
      2014-04-10T02:57:57+01:00 2014-04-10T03:09:47+01:00 · 13 Kommentare
      Matlab Simulink PWM
      MATLAB

      13 Kommentare auf „Frequency-variable PWM generator in Simulink“

      1. Reynaldo sagt:
        Donnerstag, Mai 29th, 2014 05:17 pm GMT +1 um 17:17 Uhr

        Thank you for this mod­el, I found it very use­ful. With my solver set­tings how­ev­er, I was get­ting into an alge­bra­ic loop at the trig­ger.
        I added a mem­o­ry block on the inte­gra­tor feed­back loop, and it worked well for me.

        Thanks again!

        Antworten
      2. Ebi sagt:
        Sonntag, Juni 22nd, 2014 09:08 am GMT +1 um 09:08 Uhr

        Hi there,
        Thanks for use­ful infor­ma­tion. I have a ques­tion about amount of fre­quen­cy. How can I cal­cu­late it? for exam­ple I want fre­quen­cy about 1MHz, What shall I do?

        Antworten
        • Markus sagt:
          Sonntag, Juni 22nd, 2014 02:54 pm GMT +1 um 14:54 Uhr

          I’m afraid I don’t under­stand your ques­tion, since for this mod­el the fre­quen­cy is a required para­me­ter. You can (re-)calculate the fre­quen­cy from the out­put, if that is what you mean, by either count­ing all ris­ing edges (low-to-high jumps) per giv­en time (100 ris­ing edges per sec­ond makes 100 Hz) or deter­mine the time between two ris­ing edges, as this is the peri­od length. Is that what you mean?

          Antworten
      3. Ulrich sagt:
        Mittwoch, Juni 24th, 2015 04:48 pm GMT +1 um 16:48 Uhr

        The alge­bra­ic loop can be avoid­ed when the feed­back is done from the state port of the inte­gra­tor instead of the out­put of the inte­gra­tor. To have the state port avail­able you need to set “Show state port” in the block para­me­ters.

        Antworten
      4. Praveen sagt:
        Montag, September 21st, 2015 08:25 am GMT +1 um 08:25 Uhr

        if I have total time and duty cycle as input then how to gen­er­ate PWM sig­nal with­out using gen­er­a­tor block/signal sim­ply using math­e­mat­i­cal oper­a­tional block in Simulink.

        Antworten
        • Markus sagt:
          Montag, September 21st, 2015 10:08 am GMT +1 um 10:08 Uhr

          As Ulrich point­ed out, there will be an alge­bra­ic loop when using sim­ple oper­a­tors, because you’ll have to feed back the result on the oper­a­tion itself (think x=x+1, which is invalid), so you will need at least some sort of delay. That said, the sim­plest form of inte­gra­tion is addi­tion.

          If you divide your duty cycle by the time­frame, you’ll obtain the fre­quen­cy. The rest would be as shown.

          Antworten
      5. Saad sagt:
        Samstag, Oktober 24th, 2015 06:01 am GMT +1 um 06:01 Uhr

        Hi,

        Can you tell me how can I gen­er­ate a saw­tooth wave whose frequency/time is chang­ing in every cycle.

        Antworten
        • Markus sagt:
          Samstag, Oktober 24th, 2015 12:20 pm GMT +1 um 12:20 Uhr

          The saw­tooth is the core trick in this mod­el and is shown in the first plot. The right half of the mod­el is about con­vert­ing the saw­tooth into a square wave under con­sid­er­a­tion of the duty cycle. Just leave that out and you should be good to go.

          Antworten
      6. santhan sagt:
        Sonntag, April 17th, 2016 07:39 am GMT +1 um 07:39 Uhr

        Hi,

        I couldn’t able to find inte­gra­tor block,please help me

        Antworten
      7. Canberk sagt:
        Freitag, Juni 10th, 2016 04:06 pm GMT +1 um 16:06 Uhr

        Hi,

        This code is quite help­ful. Thanks. I have a ques­tion. I have to cre­ate PWM sig­nal with vari­able fre­quen­cy. I am apply­ing input with exter­nal USB joy­stick device. But when i apply, some error occurs. Joystick’s out­put is ana­log (not exact­ly ramp func­tion, it looks like step input). What can i do? Thanks.

        Antworten
      8. Bernardo sagt:
        Samstag, Juli 2nd, 2016 11:48 pm GMT +1 um 23:48 Uhr

        Hel­lo! Your mod­el is awe­some! Thank you very much! I adopt­ed Ulrich’s solu­tion and it works fine

        Antworten
      9. newbee sagt:
        Freitag, August 25th, 2017 05:04 pm GMT +1 um 17:04 Uhr

        How can I gen­er­ate a vari­able for this kind duty cycle.
        I got a block like this for a spe­cif­ic hard­ware. A sim­ple con­stant is not enough. I want to gen­er­ate a sine wave out of the hard­ware withe this pwm-block.
        Can you help me please?

        Antworten
      10. Lecke Mio sagt:
        Samstag, Februar 23rd, 2019 11:07 pm GMT +1 um 23:07 Uhr

        Clever idea and works fine. Many thanks

        Antworten

      Antworte auf Bernardo

      Hier klicken, um das Antworten abzubrechen.

    1. « newer
    2. 1
    3. …
    4. 18
    5. 19
    6. 20
    7. 21
    8. 22
    9. 23
    10. 24
    11. …
    12. 43
    13. older »
    • Kategorien

      • .NET
        • ASP.NET
        • Core
        • DNX
      • Allgemein
      • Android
      • Data Science
      • Embedded
      • FPGA
      • Humor
      • Image Processing
      • Kalman Filter
      • Machine Learning
        • Caffe
        • Hidden Markov Models
        • ML Summarized
        • Neural Networks
        • TensorFlow
      • Mapping
      • MATLAB
      • Robotik
      • Rust
      • Signal Processing
      • Tutorial
      • Version Control
    • Neueste Beiträge

      • Summarized: The E-Dimension — Why Machine Learning Doesn’t Work Well for Some Problems?
      • Use your conda environment in Jupyter Notebooks
      • Building OpenCV for Anaconda Python 3
      • Using TensorFlow’s Supervisor with TensorBoard summary groups
      • Getting an image into and out of TensorFlow
    • Kategorien

      .NET Allgemein Android ASP.NET Caffe Core Data Science DNX Embedded FPGA Hidden Markov Models Humor Image Processing Kalman Filter Machine Learning Mapping MATLAB ML Summarized Neural Networks Robotik Rust Signal Processing TensorFlow Tutorial Version Control
    • Tags

      .NET Accelerometer Anaconda Bitmap Bug Canvas CLR docker FPGA FRDM-KL25Z FRDM-KL26Z Freescale git Gyroscope Integration Drift Intent J-Link Linear Programming Linux Magnetometer Matlab Mono Naismith OpenCV Open Intents OpenSDA Optimization Pipistrello Player/Stage PWM Python Sensor Fusion Simulink Spartan 6 svn tensorflow Tilt Compensation TRIAD ubuntu Windows Xilinx Xilinx SDK ZedBoard ZYBO Zynq
    • Letzte Kommetare

      • Lecke Mio bei Frequency-variable PWM generator in Simulink
      • Vaibhav bei Use your conda environment in Jupyter Notebooks
      • newbee bei Frequency-variable PWM generator in Simulink
      • Markus bei Using TensorFlow’s Supervisor with TensorBoard summary groups
      • Toke bei Using TensorFlow’s Supervisor with TensorBoard summary groups
    • Blog durchsuchen

    • April 2014
      M D M D F S S
      « Mrz   Jun »
       123456
      78910111213
      14151617181920
      21222324252627
      282930  
    • Self

      • Find me on GitHub
      • Google+
      • Me on Stack­Ex­change
      • Ye olde blog
    • Meta

      • Anmelden
      • Beitrags-Feed (RSS)
      • Kommentare als RSS
      • WordPress.org
    (Generiert in 0,931 Sekunden)

    Zurück nach oben.