Control frequency and duty cycle by AVR ??

Go To Last Post
75 posts / 0 new

Pages

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

JohanEkdahl wrote:
Quote:
Because the driver IC specifies 400Hz.

One trick to get good answers is to supply pertinent information. Tell us what driver this is - preferably a link to a page where we can d/l and read the specs and/or data sheet.

We disagree there. What that would do is result in comments like "use a different IC" or "why don't you hook up a piece of peanut butter to pin 12 and smack the donkey" blah blah.

I specified I wanted 400Hz... what "pertinent information" was missing? The "why" of my 400Hz is rather irrelevant, no? theusch needed his curiosity satisfied and I obliged, but it certainly wasn't necessary for answering the question. I'm constantly perplexed with this forum how people seem to need every bit of history and reasoning leading up to a question... as though the question itself is never the proper one. I'm not knocking it (too much)... this is probably the most helpful forum I've found for this stuff... but at the same time, there's a real ego complex going on. Instead of "I don't know" or "here's the answer" its constantly "why would you want to do that?" and "do this instead". Which CAN be helpful depending on the context... but more often than not, its a result of the answerer making presumptions. This was the case here.... theusch obviously presumed I had no good reason for needing a specific frequency.

Often, presumptions lead to a LOT of blah blah and wasted time. See, now I'm having to explain my explanation.

- Steven

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

Quote:

I specified I wanted 400Hz... what "pertinent information" was missing?

Because >>you<< "simply" said ...
Quote:

I'm trying to simply set the brightness of an LED via PWM

... and nothing about a driver chip interface.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

Seriously, if you pose your question accurately and carefully, you can get an answer immediately. Or within one or two replies.

Let's face it. You initialise TCCR3A, TCCR3B, ICR3 and the appropriate DDR bit for the OC3A pin. Then set the duty cycle with OCR3A register.
I make this 4 init statements and one programmable statement.

Try the Secret Service method and the thread goes on for weeks. It is hardly worth all the invisible ink and ray guns!

David.

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

I've no idea what you're going on about with your "Secret Service" talk. If you're presumption is that I have something to hide... well, that's one more presumption that's way off base. Not every question requires a complete background to answer. This one certainly didn't and neither did the OP's.

Don't you get sick of reading people's entire code and schematics and life story just to answer a "how do I" question?

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

theusch wrote:
Quote:

I specified I wanted 400Hz... what "pertinent information" was missing?

Because >>you<< "simply" said ...
Quote:

I'm trying to simply set the brightness of an LED via PWM

... and nothing about a driver chip interface.

Completely irrelevant. I clearly stated "specifically at 400Hz". Whether its for a driver chip interface or just because the hair on my toes really really like the hum of 400Hz... its entirely irrelevant.

Officer asks: Sir, do you know how fast you were going?

Logical person answers: [no | yes | 62 mph]
Avrfreak answers: Is your wife satisfied at home?

Which one gets the ticket and which one gets a slap up the side of the head?

:lol:

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

No, the experienced engineer immediately realizes the question has insufficient info to have a good engineering answer made regarding tradeoffs in price, speed, power consumption, size of package, heat dissipation in the (non)specified usage environment, etc etc. So far everyone has described using a timer register for pwm frequency. If I can get 62500 pwms a sec with 16MHz and an 8 bit timer, I could get 31250 by just setting the a compare reg to 127 instead of the full scale 255, and using another compare reg from 0 to 127 for duty cycle. You trade off bits of duty as the period gets smaller, (pwm freq higher).

Imagecraft compiler user

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

s_mack wrote:
OK, I got it now.

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

s_mack wrote:
I've no idea what you're going on about with your "Secret Service" talk. If you're presumption is that I have something to hide... well, that's one more presumption that's way off base. Not every question requires a complete background to answer. This one certainly didn't and neither did the OP's.

Don't you get sick of reading people's entire code and schematics and life story just to answer a "how do I" question?

Yes. Of course I do.

My point was that "5 minutes of your time composing a question wisely" gets an accurate and speedy response.

Describing a problem in clear English may often prompt you to spot the solution. It certainly helps others to give a sensible answer. Otherwise you just get speculation.

Yes. You may even get suggestions for a better approach in the first place. You will probably resent this, but a third party will often benefit.

David.

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

david.prentice wrote:
My point was that "5 minutes of your time composing a question wisely" gets an accurate and speedy response.
Agreed. I just think that's what I did (at least regarding the 400Hz, which sparked this discussion in my view)

david.prentice wrote:
Describing a problem in clear English may often prompt you to spot the solution. It certainly helps others to give a sensible answer. Otherwise you just get speculation.
That kind of excludes ESL gents like the OP, who really got a lot of flack because his English wasn't perfect. A bit unfair, really. But I get your point.

david.prentice wrote:
Yes. You may even get suggestions for a better approach in the first place. You will probably resent this, but a third party will often benefit.
I don't "resent" it... its annoying is all, constantly having to justify the "why" behind the question. However, the last bit of that statement makes sense. I hadn't thought about it from the 3rd party point of view. Still... if my question was, "how do I set a PWM frequency of 400Hz and arbitrary/variable duty cycle" and the answer is "why do you want 400Hz?"... how does that help a 3rd party? My issue - as I've stated before - is people's constant need to guess/presume/know the "why" behind a question rather than the focusing on the "what" and "how". I'd be totally fine if my question were met with "is 400Hz critical? You can achieve 397.5Hz via prescalers" (or whatever).

Anyway... this discussion probably should have ended a long time ago :) There has to be limit to the total number of characters available on the Internet. And I'm using more than my share.

- Steven

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

IMO it's not about someone having to justify things. At least that is not why I asked in this thread. It is all about the evolution of threads we see here quite often:

We get the minimal Q but as answers and follow ups get in, it is evident that the person asking is on the wrong track and we've all wasted time. You could have started out "I am using LED driver so-and-so which needs a 400 Hz PWM signal. ..." and all would have been well.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

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

Bottom line: The more info you supply in the original question the more likelihood there is of a solution to the problem. Even quote details you don't think are relevant - they may be.

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

Programming help by forum messages might be worse than computer support through international longdistance calls through translators. Seen those 'humorous' support transcriptions where the back and forth gets off track and hilarity ensues? Never seen a mouse. Cant tell if the computer is on or off. Never pressed the start button before. You think a couple of these guys that think they have seen EVERY gremlin that could possibly surface during the last couple of decades don't have a LOOOONG list of possible problems to check for when someone asks how to init their uart? Here's proof that there is a Devil that is allowed to mess with us: Test the product thoroughly three days before the selloff demo. Works great. Test the product thoroughly two days before the selloff. Works great. Test the product the day before the selloff. Works great. Run the demo the evening before the morning of the selloff. Demo computer wont boot. Demo wont run. Dev system with only copy of source code has a blue screen.

Imagecraft compiler user

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

Quote:
Never seen a mouse.

Well, I thought that would be "Never seen an Enter key", Bob... :wink:

Quote:
Dev system with only copy of source code

Person responsible for this is up for capital punishment.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

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

The Friendly Freak was walking his bulldog 'Mega' (image below) down the access road along the freeway in his neighborhood. A delivery truck came down the road (image below), and caught his eye as the hood ornament was the spitting image of Mega.

The truck pulled to a stop when abreast. Stenciled on the side was "PWM Delivery" along with the company slogan "You'll be amazed at our exact frequency".

"Excuse me", said the driver of the Mack. "Do you know where the palace of King Samperi is located?"

The Friendly Freak looked across the freeway and pointed to the turrets of the palace poking into the sky a short distance away. "You can see it there", he said. "You'd best ..."

The driver cut him off. "I just asked where it was; I don't need any extra chit chat." He put the truck into gear and roared off.

"Sheesh", thought the Freak. "I was just going to tell him to turn around in the big parking lot ahead and go back to the underpass behind. The underpasses ahead are closed for construction and the access road dead-ends in a small cul-de-sac".

Sure enough, some time later back came the Mack. The driver again stopped and berated our hero for not advising him of the road situation and ranted about the difficulty of turning around.

Before the truck took off angrily, Mega lifted his leg on the chromed front wheel. "Good dog" said the Friendly Freak.

[Author's note: Just as with University of Georgia mascots http://en.wikipedia.org/wiki/Uga... , 'Mega' is actually the eighth in a long line all going by the same name, so technically it is 'Mega8' for short, and 'ATMega8-16PU' on the AKC documents.

Also in the household is the fourth in a line of purse dogs, 'Tiny4'. ]

Attachment(s): 

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

JohanEkdahl wrote:
Quote:
Never seen a mouse.

Well, I thought that would be "Never seen an Enter key", Bob... :wink:

That, is funny!!! :wink:

"I may make you feel but I can't make you think" - Jethro Tull - Thick As A Brick

"void transmigratus(void) {transmigratus();} // recursio infinitus" - larryvc

"It's much more practical to rely on the processing powers of the real debugger, i.e. the one between the keyboard and chair." - JW wek3

"When you arise in the morning think of what a privilege it is to be alive: to breathe, to think, to enjoy, to love." -  Marcus Aurelius

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

Yuk
Yuk
Yuk

Imagecraft compiler user

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

Hello guys,,,,

 

I am following this post and sharing my issue with you all...looking for some solution....Thanks in advance.

 

well, I am able to generate pwm signal (20kHz) on Atmega8, while set ICR1 as TOP and OCR1A as its duty. But later I want to convert this pwm signal of 4ms period while keeping the ICR1 value same. I follow this configuration to generate 20kHz pwm signal.

TCNT1 = 0x00FF;

ICR1 = 0x00C7;

OCR1A = 100;

 

Please suggest the changes to achieve 4ms pwm, (keeping ICR1 same).

 

Thanks..

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

Aks wrote:
achieve 4ms pwm, (keeping ICR1 same).

Impossible with an AVR8 timer1 or equivalent.  20kHz => 250Hz is 1/80.  There are no timer prescalers that are /80

 

As with Mr. Mack at the top of the thread you hijacked, you haven't given us any reasons for the requirement of not adjusting ICR1.  But re-reading the thread from 2012, Mr. Mack taught me to not ask questions like "Why must ICR1 remain unchanged?"

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

Hello Mr theusch,

 

Thanks for your reply~

 

well, here is the explanation about my requirement.....

 

I am getting PWM(20kHz) as the output of MCU; while configured  ICR1 and OCR1A, OCR1B, TCCR1A, TCCR1B, TCNT1, TIMSK, TIFR..

 

Now, this PWM is applied to MOTOR and motor is running. In parallel, when motor is running, we have photo interrupt is enable which is directed the motor output pulse (Period: 4ms), which is applied to external interrupt pin of MCU.

 

So, I am looking for the solution to generate 4ms pulse after applying PWM (50us) to Motor.

 

Please suggest. Thanks.

 

 

 

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

Aks wrote:
Please suggest.

1)  Use another timer.

2)  Count 80 times the 50us period of the 20kHz, using overflow.  Realize that that apparently simple task may take up to 50% of your AVR's processor power and would be subject to jitter if other interrupt sources enabled.

 

I fail to see how this relates to

Aks wrote:
later I want to convert this pwm signal of 4ms period while keeping the ICR1 value same.
Are the two signals being generated at the same time or not?

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

Hello,

 

Thanks for your reply~

 

1) I cant use another timer as I am already using OC1A/OC1B for generating PWM (forward/reverse).

 When the motor is running, then only interrupt signal is generated else NO. Generated same time when motor runs. I am trying to use it as an External Interrupt.

 

Please suggest~

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

Aks wrote:
1) I cant use another timer as I am already using OC1A/OC1B for generating PWM (forward/reverse).

??? Timer0?  Timer2?  What are the accuracy requirements of the 4ms period?

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

I am not using other timer bcoz, the motor n drivers are already configured using PB0~PB4 and external interrupt pulse is at PD3.

 

I didnt understand the "accuracy requirement"? Please clear.

 

Thanks

 

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

Aks wrote:
I am not using other timer bcoz,

That makes absolutely no sense.  A 4ms interrupt interval for a timer is not a big burden on the system, and in an appropriate ISR any pin could be set or cleared.

 

If you give a complete picture of the situation, instead of the vague question in your first post in this thread, then suggestions can be made.

 

What does the external interrupt pin have to do with generating a pulse every 4ms?

 

Re accuracy:  How long is the pulse?  How close must it be to exactly 4ms?

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

Pages