Contention between OCR1A and OCR1B on PWM

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

I just discovered the two peripherals ie ocr1a and ocr1b of timer1 cannot just be used simultaneously to output pwm on their respective pins of avr.
The datasheet doesn't specify this not simulation reveals the problem.

I discovered control value on say ocr1a affects the output on ocr1b.
I have double checked the code, writing to the registers is as per the manufacturer.
Some one with an insight?

Crazy generation

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

1. Which microcontroller.

2. Show us the code.

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

Which chip are you using?

 

Greg Muth

Portland, OR, US

Atmel Studio 7.0 on Windows 10

Xplained/Pro/Mini Boards mostly

 

 

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

Atmega1284P
Please see the attachment,
Sorry I had to use the phone to attach, the file may not be very clear.

Attachment(s): 

Crazy generation

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

Odd...I can make two different duty cycle PWM outputs on Timer 1...

 

'This forum helps those who help themselves.'

 

pragmatic  adjective dealing with things sensibly and realistically in a way that is based on practical rather than theoretical consideration.

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

Derick22 wrote:
I just discovered the two peripherals ie ocr1a and ocr1b of timer1 cannot just be used simultaneously to output pwm on their respective pins of avr. The datasheet doesn't specify this not simulation reveals the problem. I discovered control value on say ocr1a affects the output on ocr1b.

Maybe you could give us some more information about the issue. How does OCR1A affect OCR1B?

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

Code for the above waveform...

 

// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: 2000.000 kHz
// Mode: Ph. correct PWM top=0x03FF
// OC1A output: Non-Inverted PWM
// OC1B output: Non-Inverted PWM
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer Period: 1.023 ms
// Output Pulse(s):
// OC1A Period: 1.023 ms Width: 0.512 ms
// OC1B Period: 1.023 ms Width: 0.102 ms
// Timer1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=(1<<COM1A1) | (0<<COM1A0) | (1<<COM1B1) | (0<<COM1B0) | (1<<WGM11) | (1<<WGM10);
TCCR1B=(0<<ICNC1) | (0<<ICES1) | (0<<WGM13) | (0<<WGM12) | (0<<CS12) | (1<<CS11) | (0<<CS10);
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x02;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x66;

 

'This forum helps those who help themselves.'

 

pragmatic  adjective dealing with things sensibly and realistically in a way that is based on practical rather than theoretical consideration.

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

I notice in your code that you are ORing in your configuration bits.

 

Unless you can guarantee the initial state of your control registers that is a REALLY BAD IDEA(tm). On first run always set your registers to a known state. I don't even trust reset values.

'This forum helps those who help themselves.'

 

pragmatic  adjective dealing with things sensibly and realistically in a way that is based on practical rather than theoretical consideration.

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

OCR1A is supposed to dim bulb A and OCR1B bulb B.

At some selected values for each bulb the lamps should go off.

Varying intensity of OCR1A or switching the respective pin as input somehow affects the intensity of OCR1B.

Crazy generation

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

You're going to have to post your code here so we can see what you are doing wrong; the chip certainly works as it should.

 

If I add this code...

 

	while (1)
	{
		for (a=0; a<0x400; a++)
        {
			OCR1AH = (uint8_t)(a>>8);
            OCR1AL = (uint8_t) a;
            delay_ms(1);
        }

	}

 

...to the initialisation above I see a smoothly changing duty cycle on output A and output B stays rock solid at 10% duty cycle.

 

 

What about my comments about how you initialise the registers?

'This forum helps those who help themselves.'

 

pragmatic  adjective dealing with things sensibly and realistically in a way that is based on practical rather than theoretical consideration.

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

Derick22 wrote:
Varying intensity of OCR1A or switching the respective pin as input somehow affects the intensity of OCR1B.

Maybe the issue is outside the MCU? Verify operation of the bulb A with bulb B dismounted and operation of the bulb B with bulb A dismounted.

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

There are some PWM modes in which OCR1A is used to set frequency so it cannot be used to set duty so the A output is unusable. Which of the 0..15 WGM modes are you trying to use?

 

(like others have said - show the code)

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

Let me see if that improves.
Could bad initialization.

Crazy generation

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

clawson wrote:

Which of the 0..15 WGM modes are you trying to use?

 

In the screen shot of the timer initialisation code we see WGM10 and WGM11 being set so I think we can assume mode 3 (which is what I've tested against).

'This forum helps those who help themselves.'

 

pragmatic  adjective dealing with things sensibly and realistically in a way that is based on practical rather than theoretical consideration.

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

Derick22 wrote:
OCR1A is supposed to dim bulb A and OCR1B bulb B.

 

Bulb? Are these actual edison lamps, or LED's?   Could this be a case of missing current limiting resistors?

Please show us your schematic.

 

Jim