Atmega8a PWM with TCNT1 issue

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

Hello Friends

I've a question about using Atmega8a for fast mode PWM using TCNT1 (16 bit) and hope to answer me with my thanks in advance

I want to set Fast PWM to use TCNT1, OCR1A to hold the  comparing value of the counter and use OC1A as an output, I know how to setup the configuration that i want ,
  

TCCR1A |= (1 <<WGM11 | 1 <<WGM10 );           // Set PWM type (Fast PWM) e

TCCR1B |= (1 <<WGM13 | 1 << WGM12) 

;

but my confusion is

if i used OCR1A to store the comparing value, where can i store the TOP value (period time),which register i can use for storing ?

if i want to make OC1B as output, where can i store the TOP value ?

if i want to use both OC1A and OC1B at the same time, which registers used to store the comparing values (dutty cycle), and which one is used for storing the top values (period)

is it possible to use  a TOP value more than 1024 since TCNT1 is 16 bit ?

White Hearts Can not be forgotten

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

Please see the data sheet.

Mode 14 meets your expectations.
In mode 15, no PWM waveform is available on OC1A.

 

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


kabasan wrote:

Please see the data sheet.

Mode 14 meets your expectations.

In mode 15, no PWM waveform is available on OC1A.

 

 

Hello friend

i don't want to use ICR1 and  i think that you can use the below table to determine which pin is used as an output regardless the PWM mode you are configuring

White Hearts Can not be forgotten

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

Why do you not "want to use ICR1"?

David (aka frog_jr)

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

White Heart wrote:

i don't want to use ICR1

 

If so, there is no advice I can give.
sorry.

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


Did you read & understand this:

 

So in your desired Fast PWM mode (Mode 14) TOP is obtained from ICR1.

So in your desired Fast PWM mode (Mode 15) TOP is obtained from OCR1A.

 

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

Many thanks for you kabasan

White Hearts Can not be forgotten

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

N.Winterbottom wrote:

So in your desired Fast PWM mode (Mode 14) TOP is obtained from ICR1.

So in your desired Fast PWM mode (Mode 15) TOP is obtained from OCR1A.

Yes that's right,

but where can i store the compared value  (dutty cycle) with TCNT1 in each case.

White Hearts Can not be forgotten

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

In Mode 14, set the TOP value in ICR1, set duty for OC1A pin (PB1) in OCR1A and duty for OC1B pin (PB2) in OCR1B.

David (aka frog_jr)

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

The rule is simple.. if an OCR is being used to set TOP then that output channel cannot be used.

 

So if you want to use A and B then you either have to live with a fixed TOP (ie fixed frequency) or you have to pick a mode where TOP is varied by ICR. As long as you aren't using input capture alongside PWM then why would using ICR be a problem?

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

Hello clawson

Thanks for the answer.

 

clawson wrote:
why would using ICR be a problem?

I've no problem using ICR, I just want to learn using PWM efficiently and learn all possible configurations

White Hearts Can not be forgotten

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

White Heart wrote:
I've no problem using ICR,
but previously you said..
White Heart wrote:

Hello friend

i don't want to use ICR1

which I guess is why I, like several posters here, were a bit confused?!

 

The fact is that if you need to vary frequency (not just duty) and you want to maintain A and B you don't really have a choice. The frequency adjustment must be by ICR1.

 

But maybe take a step back and consider exactly why you might need to vary both duty and frequency in the first place. Most PWM only needs duty to be adjustable. 

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

I do agree

clawson wrote:
Most PWM only needs duty to be adjustable.
However, the fixed frequencies may not provide a close enough frequency match so that either ICRx or OCRxA needs to be used to establish the correct frequency.

David (aka frog_jr)