timer 1 vs timer 3 with pwm

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

hello people.

 

I have been working with this avr code to generate pwm signal with frequency 200 khz and now I need timer 1 in another function (ADC triggering) thats why  I decided to switch to timer 3. and use it to get the pwm.

Thats why I wrote and it simple doesnot work . I am in the lab and I measuring the frequency with an oscilloscope and there is only pwm when the timer is 1 not 3 

 

any help ??

TCCR1A=(1<<COM1A1) | (0<<COM1A0) | (1<<COM1B1) | (1<<COM1B0) | (0<<COM1C1) | (0<<COM1C0) | (0<<WGM11) | (0<<WGM10);
TCCR1B=(0<<ICNC1) | (0<<ICES1) | (1<<WGM13) | (0<<WGM12) | (0<<CS12) | (0<<CS11) | (1<<CS10);
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x28;
OCR1AH=0x00;
OCR1AL=0x12;

 

This topic has a solution.
Last Edited: Wed. Nov 29, 2017 - 06:29 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Which device are you targeting?

David (aka frog_jr)

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

atmega 2560.. i found on the schematic diagram that oc3a is pin 6  pwm

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

Moraa wrote:

atmega 2560.. i found on the schematic diagram that oc3a is pin 6  pwm

since i am testing on teh arduino atmega 2560 board...pin 6 corrsponds to oc3a

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Moraa wrote:
i found on the schematic diagram that oc3a is pin 6 pwm
Does that mean that you solved the problem by changing from the pin for OC1B to the pin for OC3B and that now you are "seeing" the pwm signal?

 

David (aka frog_jr)

Last Edited: Wed. Nov 29, 2017 - 02:59 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

yeah. I have a question now. Is there a way that I increase the frequency of a pwm signal and increase the resolution at the time.or there must be trade off. increasing frequency means decreasing resolution

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

You can increase the frequency in three ways:

  1. Increase system clock speed
  2. Decrease timer prescaler
  3. Decrease timer resolution

 

1 and 2 will not affect the timer's resolution.  3, obviously, will.

 

 

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"Read a lot.  Write a lot."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

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

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

so you mean ehat I can choose N (prescaler of frequency), and TOP (timer maximum value which corresponds to resolution) to alter the frequency..

say I want 50 KHZ frequency then the top could be 160 and the prescaler 1 or the top 20 and the prescaler 8... that is the only way to solve it in case fos =16 mhz,right? no way to get a bigger resolution than but I replace this frequency with an external oscillator right?

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

Right.

 

 

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"Read a lot.  Write a lot."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

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

If you can use a fast PWM mode (e.g. Mode 14), with a prescaler of 1 (assuming 16MHz clock) then your TOP would be 320 for 50KHz PWM.

David (aka frog_jr)