element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Embedded and Microcontrollers
  • Technologies
  • More
Embedded and Microcontrollers
Embedded Forum how to generate 50to 60 hz sine wave from pwm
  • Blog
  • Forum
  • Documents
  • Quiz
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Embedded and Microcontrollers to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Suggested Answer
  • Replies 7 replies
  • Answers 2 answers
  • Subscribers 464 subscribers
  • Views 1682 views
  • Users 0 members are here
  • c
  • microprocessor
  • answer
  • embedded_system
  • embedded
  • electronics
  • software
Related

how to generate 50to 60 hz sine wave from pwm

Former Member
Former Member over 11 years ago

I Want to know that how to generate the 50 -60 hz frequency by using pwm . If any body have any idea about then please tell me .

  • Sign in to reply
  • Cancel

Top Replies

  • kas.lewis
    kas.lewis over 7 years ago +2 suggested
    https://www.youtube.com/watch?v=qVeERT4nyz8 This may be a helpful and informative video, I sure found it to be so. Kas
  • dougw
    dougw over 11 years ago in reply to Former Member +1
    Hi Rahil, You could start by trying something like this which generates a slow triangle wave: PWM Signal Generation using AVR Timers Then shorten the timing until the brightness loop is ramping up and…
  • valiza
    valiza over 7 years ago in reply to sarah123 +1 suggested
    Can't just give you the full code but I will give you hints. Configure TimerCounter1 (TCCR1A and TCCR1B) to give a PWM of >6khz. Make a array of sine wave values with the resolution you want (100 in this…
Parents
  • dougw
    0 dougw over 11 years ago

    Hi Rahil,

    PWM can be converted to voltage using a lowpass filter - a simple R-C can be enough. To generate a sinusoidal voltage at such a filter the pulse width must be modulated sinusoidally.

    pulse width = sine (time) * MaxPulseWidth

    Time can be a simple count that increments with time. The increments must occur at a rate that forces the sine of the count to roll over to the same value 120 times per second. For example the sine of 360 degrees is the same as 0 degrees or 180 degrees or 720 degrees. So you could make the counter increment at a rate of 360 steps in 1/60th of a second. You can also reset the count when it reaches 360. The sine of the count will vary from 0 to 1, so it must be multiplied by the maximum pulse width before being sent to your PWM generator.

    Note that the frequency of the PWM signal should be much higher than the 60 Hz you are trying to create and the lowpass filter should have a cutoff frequency above 60 Hz.

    Doug

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • sarah123
    0 sarah123 over 7 years ago in reply to dougw

    hi sir,

    I Want to know that how to generate the 60 hz frequency by using pwm  using ardunio uno.please help me to  generate it.and can you please send the code also

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • sarah123
    0 sarah123 over 7 years ago in reply to dougw

    hi sir,

    I Want to know that how to generate the 60 hz frequency by using pwm  using ardunio uno.please help me to  generate it.and can you please send the code also

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
  • valiza
    0 valiza over 7 years ago in reply to sarah123

    Can't just give you the full code but I will give you hints.

     

    Configure TimerCounter1 (TCCR1A and TCCR1B) to give a PWM of >6khz.

     

    Make a array of sine wave values with the resolution you want (100 in this case)

     

    // In main.c

    uint8_t SinTable[100];

    for (i=0;i<100;i++)

         {

         SinTable[i]= sin(6.28/100)* 127+127 ; // 127 is the middle value, 127 is the amplitude, 6.28 for full "circle"

         }

     

    Feed them with a second timer to the pwm configured for 50hz * 100 values (5000hz) interrupt or 60hz*100 for 60hz.

     

    Like so.

    ISR(timer0_ovf_vect)

    {

    static uint8_t actualPos=0;

    OCR1A=SinTable[actualPos++];

    if (actualPos==100) actualPos=0;

    }

     

    Want to change the frequency from 50 to 60 dinamically? Timer0 should be configured as CTC mode, change the ICR0 value to set another TOP or OCR0 if you configured CTC with OCR0 as top.

    And calculate it.

    ICR0 = (F_CPU / ( (desiredFrequency*100) * configured_prescaler)) / 2 ; // IT IS DIVIDED BY TWO BECAUSE IT IS IN CTC MODE.

     

    Hope it helps probably not,

    Have a nice day!

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube