Author Topic: Issue with TIMER4 PWM and UART0 on ATmega328PB  (Read 1316 times)

0 Members and 1 Guest are viewing this topic.

Offline djococaudTopic starter

  • Regular Contributor
  • *
  • Posts: 78
  • Country: fr
  • General rule : Simpler is Better
    • Djo Labs
Issue with TIMER4 PWM and UART0 on ATmega328PB
« on: June 14, 2017, 03:39:14 pm »
Hi boys and girls !

I have a problem with the new ATmega328PB and, after reading all the datasheet several times, I kindly request your help !  ^-^

I am using both PWM outputs from the Timer 4 (on PD1 and PD2).
I am also using the UART0 to receive DMX data (receive only on PD0, no TX0 enabled, so PD1 should be left free for OC4A).


Here is the issue :
When I initialize the Timer 4 only, both the PWM outputs are OK on PD1 and PD2.  :-+
(I figured that I need to write PD2 High in order to disable the Modulator and enable ouput OC4B, no problem here)

But when I initialize the Timer4 and I enable the UART0 receiver (RXEN0 only), then PD1 (OC4A) is stuck low.  :--

Does anyone knows why PD1 (OC4A) is held low when RXEN0=1 (TXEN0 is still 0) ?  :-//

Thanks everyone !  ;)



Here is the initialisation code (stripped to the essential)
Code: [Select]

#define TOP_PWM 26666 //16MHz / 26666 = 600Hz


int main(void)
// -------------------------------------------
{
//  I/O
//******** 
DDRD  = _BV(PD1) | _BV(PD2) ;    // PWM ouputs
PORTD = _BV(PD2) ;                                       // (+PD2 to disable Modulator (OCM)

// INIT UART (RX DMX)
//**********************
//- baud rate = 250000 bps
UBRR0H = 0x00;
UBRR0L = 0x07;

UCSR0A = _BV(U2X0);
UCSR0B = _BV(RXEN0)  | _BV(UCSZ02);
UCSR0C = _BV(UCSZ01) | _BV(UCSZ00);
UCSR0B |= _BV(RXCIE0);

// INIT TIMER4 / PWM (OCR4A/B)
//**************************
TCNT4 = TOP_PWM;
TCCR4A = _BV(COM1A1) | _BV(COM4A0) | _BV(COM4B1) | _BV(COM4B0) | _BV(WGM41);      // Fast PWM (mode 14)
TCCR4B = _BV(WGM42)  | _BV(WGM43)  | _BV(CS40);
ICR4=TOP_PWM;   // TOP = 26666 (16Mhz/26666 = 600Hz)

OCR4A = TOP_PWM/2;     //50% PWM for testing
OCR4B = TOP_PWM/2;     //50% PWM for testing


while(1);
}




Here is the datasheet :

http://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-42397-8-bit-AVR-Microcontroller-ATmega328PB_Datasheet.pdf
« Last Edit: June 14, 2017, 03:43:25 pm by djococaud »
 

Offline djococaudTopic starter

  • Regular Contributor
  • *
  • Posts: 78
  • Country: fr
  • General rule : Simpler is Better
    • Djo Labs
Re: Issue with TIMER4 PWM and UART0 on ATmega328PB
« Reply #1 on: June 15, 2017, 12:53:27 pm »
Does anybody has an idea about RX0 messing with OC4A (I can't see why it should)?

Is there a bug in the mega328PB ? Or am I the bug ? (that's possible !  :-DD)
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf