PWM Timer 2/0 very small problem

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

hello again , so this time i'm trying to figure out why PWM T0 / T2 8bit still generate signal though , i predefined OCR0/2 = 0 ; i'm running simulation on proteus 7 

here is PWM init . thing is this problem is for T0/2 only , PWM T1A/1B don't blink when initializing .

void PWM_init_T2(void)
{
	DDRD  |= (1<<PIND7) ; // initializing PWM PIN on PortB-3 to output

	TCCR2 |= 1<<WGM21 | 1<<WGM20 | 1<<COM21 | 1<<CS20;  // Fast PWM , inverted mode , NO prescaling 

	TCNT2 = 0 ;     // Setting Counter of Timer-2 to 0
	OCR2  = 0 ;     // Compare Match of T2 PWM Channel

	return ;
}

when i loaded the program to the mega32 the led connected to T1A/1B was OFF , but T2 channel OC2 was generating tiny light . but they all respond well when increment is applied to it . so what cause this to happen ?

This topic has a solution.
Last Edited: Tue. Jan 10, 2017 - 08:08 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It would help if you told us which chip you are using - full part number.

 

While you're at it, what tool chain is used  - Studio 7?

 

How is the LED connected - is the LED connected to Vcc or Gnd?

 

 

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

1)  Tell what AVR model you are working with.

1a)  Tell clock speed and fuse settings.

2)  Show a complete test program.

3)  Tell toolchain, version, and optimization settings.

4)  Tell what you are expecting to happen.  Tell what >>is<< happening.

 

NB:  Do you get the same result with a real chip?

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

1-Atmel studio 5 

2-atmega32a , but i also have 16a and the same thing happens

3-connection goes like this , MCu -> LED -> GND

 

i think there is nothing wrong with the connection as OC1A/1B are connected as i showed and the LED are completely OFF 

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

Oh, yes--clean up your program.  You show, presumably, PD7 ans an output.  The comment says otherwise.

 

And depending on PWM mode, you cannot get "full on" and "full off" with the same settings.

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

 

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.

Last Edited: Tue. Jan 10, 2017 - 12:07 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Messiry wrote:
2-atmega32a , but i also have 16a and the same thing happens

But your thread title said "Tiny"...

 

 

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

Isn't this expected behavior?  The clock is still running, and you have it outputting to pin OC2 via the COM21 setting.  Even with OCR2 set to 0 there is one timer tick between reaching the top (when OC2 is set) to wrapping around to 0 (when OC2 is cleared).  If you want the pin to be fully off you have to disable the clock source.

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

theusch wrote:

Oh, yes--clean up your program.  You show, presumably, PD7 ans an output.  The comment says otherwise.

 

And depending on PWM mode, you cannot get "full on" and "full off" with the same settings.

 

actually it's a typo cause i'm lazy an take copy and paste , but it's PIND7 - OC2 PWM channel .

 

the problem :

when i'm connecting pwm channel OC2 or OC1 , they generate very small signal that make the LED very very dimmed .on the other hand the same connection goes for timer 1 OC1A/OC1B channels the LED are completely OFF .

but the good side , when i increment the signal the LED responds very well but it just doesn't reach that Zero level .

i attached a pic but this is simplified , the real application is shown in the second pic

 

Attachment(s): 

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

Rezer wrote:
If you want the pin to be fully off you have to disable the clock source.

you mean to clear COM20 & COM21 ?

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

i meant very small :D , sorry i'll choose my words carefully next time .

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

Messiry wrote:

when i'm connecting pwm channel OC2 or OC1 , they generate very small signal that make the LED very very dimmed .on the other hand the same connection goes for timer 1 OC1A/OC1B channels the LED are completely OFF .

 

There is no OC1...perhaps you mean OC0?  And that's to be expected, OC1A and OC1B are both controlled by a 16 bit timer, while OC0 and OC2 only have 8 bit timers.  Your OC1A/B leds are on for 1/65536th of the time, while OC0 and OC2 are on for 1/256th of the time.

 

Messiry wrote:

you mean to clear COM20 & COM21 ?

 

No, though that would work too since it would essentially disconnect the pin from the timer.  To disable the clock source you set the CS2X bits to 0.

Last Edited: Tue. Jan 10, 2017 - 12:38 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Messiry wrote:

3-connection goes like this , MCu -> LED -> GND

 

Do you have a resistor in series with the LED?

(Screenshot (55).png in post#8 also shows no resistor.)

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

aha , one more question , would prescaling at 1024 help  ??

 

[EDIT] actually it did help . Thanks alot anyways 

Last Edited: Tue. Jan 10, 2017 - 01:01 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Messiry wrote:

i'm running simulation on proteus 7

 

Does Proteus 7 provide an oscilloscope or logic analyzer that can be connected to the uC output pin?

If it does, you can view the signal that's on the pin.