AVR DISCUSSION

Go To Last Post
30 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

<i'm new in the AVR so can anyone tell me how to make 1mhz pwm frequency>

Rjchoudhary

Last Edited: Sat. Mar 21, 2020 - 02:27 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Rajat choudhary wrote:

<i'm new in the AVR so can anyone tell me how to make 1mhz pwm frequency>

 

I assume you mean 1MHz (1,000,000Hz)?

 

What resolution do you need on your pulse width? 8-bit? 16-bit? Something else?

 

I hope you can see that achieving 8-bit resolution, ie 256 steps, on a 1MHz signal means clocking the counter at 256MHz. Which isn't going to happen on an AVR.

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

Greetings and welcome to AVR Freaks!

 

First question: what do you know about microcontrollers, generally.

 

Second question: what microcontroller do you want to use?

 

Third question: what do you mean by 1MHz PWM frequency? Are you talking about the repetition frequency of the  PWM signal or are you talking about the rate of the clock that creates the PWM?

 

Fourth question: how much resolution do you need for changes in the PWM? For example, I could, fairly  easily  make a PWM signal that ONLY has 50% duty cycle and that could be made on many AVR microcontrollers. If I wanted 25%, 50%, and 75% on times, then that is somewhat harder for most AVRs at a 1 MHz PWM repetition frequency. If I need 255 steps in the PWM, then only a few will do it. More than 256 steps limit the choice to a very small number of MCUs.

 

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

Last Edited: Fri. Mar 6, 2020 - 04:13 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It's not going to be much of a PWM at 1MHz given that AVRs generally have top speeds of just 16, 20 or (Xmega) 32MHz so even if you run a PWM mode where you can vary TOP (frequency) the best you can hope for is 16, 20 or 32 steps so your entire counting period lasts for 1us (ie freq=1MHz). So the PWM duty will then only be variable as 1/16th, 1/20th or 1/32nd of the counting range - which is a pretty coarse granularity !!!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

A few XMegas have a PLL multipliers and a special fast counter that let you do a counter clock of 128MHz. With one of these, you can get a granularity of 1MHz/128MHz. Still pretty course, but depending on the OP's needs, it could work. It is not a trivial task for someone "new in the AVR", though!

 

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

I'd like to know what uses a 1 megahertz PWM signal.

 

JIm

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

can i achive in 16bit or i want achive to  as maximum as possible in atmega16

Rjchoudhary

Last Edited: Fri. Mar 6, 2020 - 05:38 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

actually i want to know the maximum amount of fpwm i can achive and how...???

Rjchoudhary

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Have you looked at the  atmega16 datasheet & application notes?

 

https://www.avrfreaks.net/commen...

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

not yet completed sir i'm still going through it.

Rjchoudhary

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 #define F_CPU 8000000UL
 #include <avr/io.h>
 #include <util/delay.h>

void PWM_INIT()
{   
    DDRB=(1<<PB3);
    TCCR2=(1<<WGM20) | (1<<WGM21) | (1<<COM20) | (1<<COM21) | (1<<CS20); 

}

this is whta i have made for the atmega8 pwm.

if it can be done better for increasing frequency(if it can be ) then i'll be greatful to have your help.

Rjchoudhary

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

With an external crystal (or other clock source) you can run your AVR up to 16 or possibly 20MHz (depending on the chip).  Change your F_CPU definition to match the external clock.  S.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The numbers say everything:

 

(1) FCPU 8MHz

 

(2) Counter prescale 1 (that is the smallest possible prescale) so that the timer is clocked at 8MHz.

 

(3) For a 16 bit counter (PWM or no PWM), it takes 2**16 clocks to roll over (that is the period). So the repetition frequency will be 8MHz / 2**16 ~ 122Hz. That is the fastest you can go with 8MHz and 16 bits. Period.

 

(4) There are ONLY two ways to make this faster: (a) Faster MCU clock, or (b) reduce the roll-over count. Both are possible within limits, though you may have more flexibility by changing the roll-over count. You need to change the timer mode to do this. Look for a mode in which TOP is set by one of the associated registers that is different than what sets the PWM duty cycle.

 

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You appear to have picked the wrong AVR.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ka7ehk wrote:
There are ONLY two ways to make this faster:

 

What about an external DDS chip from Analog devices?

 

 

Another Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well, if you use that as an external clock for the MCU, that comes, in my mind, under the heading of "make the clock faster". Yes, you have lots of frequency flexibility but I would think that would be about the only benefit. DDS chips tend to be both pretty power hungry and pretty expensive.

 

BUT, a dds is no cure-all. An ordinary AVR is limited to something in the range of 16MHz to 20MHz with a fair number than don't even have spec'd operation to 16MHz. So, for a 16-bit PWM, the OP is still going to be stuck with something well under 500Hz (PWM repetition frequency), not 1MHz that was the stated goal.

 

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

Last Edited: Fri. Mar 6, 2020 - 11:43 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ka7ehk wrote:
UT, a dds is no cure-all. An ordinary AVR is limited to something in the range of 16MHz to 20MHz with a fair number than don't even have spec'd operation to 16MHz. So, for a 16-bit PWM, the OP is still going to be stuck with something well under 500Hz (PWM repetition frequency), not 1MHz that was the stated goal.

 

Yabbut an external DDS chip can be controlled via SPI/I2C so it wont matter what the OP is running the AVR at as the DDS will be using it's own clock.  And the OP would get the resolution they are looking for.

 

ka7ehk wrote:
pretty power hungry and pretty expensive.

 

Like the song says...."You can't always get, what you want"

 

10 - 12 bit DDS are available on Digikey for $12 - $24 USD....Single piece, not too bad. SOIC package too.

 

Another Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sir I'll be glad if you can give me any example code.. Related to my quarry..... Maximum pwm frequency using internal clock frequency

Rjchoudhary

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Sir I'll be glad if you can give me any example code.. Related to my quarry..... Maximum pwm frequency using internal clock frequency

 What have you done for yourself so far? Have you looked at any of the many examples for AVR PWM?  Please state or show what you have done ---then it is easier to offer detailed feedback.

https://www.electroschematics.com/avr-pwm/

http://maxembedded.com/2012/01/avr-timers-pwm-mode-part-ii/

 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

avrcandies wrote:
 What have you done for yourself so far?

Indeed!

 

Things like maximum frequencies are stated in the datasheet.

 

Have you looked at any of the many examples for AVR PWM?

Including the Application Notes previously mentioned.

 

And the Tutorials section on this website.

 

And many previous discussions here.

 

If you have specific questions about something you've read - then ask the specific question.

Remember to give context - eg, a link.

 

show what you have done

For how to properly post source code, see Tip #1 in my signature, below (may not be visible on mobile)

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Sat. Mar 7, 2020 - 10:27 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'd show some code but I need to know which AVR and what speed it's clocked at. There are mentions of both mega16 and mega8 above also 16MHz and 8MHz. As you require such an unusually high PWM frequency you really want the fastest AVR you can find being run at its highest speed possible. 

 

PS I  do wonder where the 1MHz requirement comes from? Is this something that has been specified and can't be changed or have you just pulled the number out of your hat?

Last Edited: Sat. Mar 7, 2020 - 02:52 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

More & more switching power supplies operate in that PWM range...so perhaps making a AVR-based one.

 

Rather than put all the work on the AVR, you can use a LM555, or similar, timer (to make the 1 MHZ), and let the AVR adjust the control voltage.  The AVR can slooooowly increase/decrease the duty cycle over many cycles of the PWM.

You can also do it digitally with a high speed clocked counter/divider circuit & let the AVR set a divisor value. 

 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

A 555 at 1 MHz ?

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

A 555 at 1 MHz ?

Of course!   Some of the newer versions go to 3MHz, if I recall.  We used 555's all the time to gen 455 KHz to make our "radios' in school. 

There are plenty of other one-shot, timers etc, that you can use...even a fast comparator can be pressed into service (the 555 is a comparator with a flip-flop & some other malarky).

 

I remember when  ____ made a 3amp output CMOS 555...I have the databook somewheres & seem to remember it being purplish.

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hello sir my previous question about pwm is solved and thanks for the support.

now i'm trying to find the calculation to get the temperature of 100k ntc thermister.

if any one can suggest me or can give me  any example code that will be helpful to me.

Rjchoudhary

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Rajat choudhary wrote:
my previous question about pwm is solved

Then please mark the solution - see Tip #5 (in my signature, below; may not be visible on mobile)

 

 

 

now i'm trying to find the calculation to get the temperature of 100k ntc thermister.

Yes - you've posted that twice already!

 

https://www.avrfreaks.net/forum/...

 

https://www.avrfreaks.net/commen...

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What research have you done? The thermistor is hardly new, so you're not on the bleeding edge. If you Google arduino thermister, you'll get a few pertinent hits. Start your research there.

 

Hint - add Arduino to just about anything you have a question about (regarding microcontrollers). Odds are you'll get something useful as anything that is of any interest to a hobbyist has probably been done with an Arduino, a blog written about it and sample code and circuit. Don't tell me you don't want to use Arduino, as this makes little difference - the Arduino is just an AVR on a circuit board - no magic.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Note that there are already answers in the other thread:

 

https://www.avrfreaks.net/commen...

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

And how can we help without seeing you code?

 

[EDIT]

 

That's very weird. The post I saw when I pressed 'goto first unread' doesn't seem to be here anymore.

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

Last Edited: Sat. Mar 21, 2020 - 02:28 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I moved the post brian. Ill lock this one

Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

Topic locked