Would you like to react to this message? Create an account in a few clicks or log in to continue.

You are not connected. Please login or register

SimulIDE 0.4.15-SR9 - Atmega328 TC1 not working in mode 8

2 posters

Go down  Message [Page 1 of 1]

janjos



The ATMega328 OC1A and OC1B pins do not change logic level when using this code:

/**************************************************
(c) JA '2021
based on: https://github.com/thiasotiks/multiphase-buck-converter

last mod.: 04/11/2021
**************************************************/
#define HS1 PB1                   // D9  (OC1A)
#define LS1 PB2                   // D10 (OC1B)

#define MAX_COUNT 255
#define DT 2                        // Dead time (DT / f_cpu = 0.5 us)

#define BAUDRATE    115200   // Baud rate of UART in bps

void setup()
{
 asm volatile ("NOP");
 DDRB |= 1 << PB5;
 PORTB &= ~(1 << PB5);     // Turn off the annoying LED @ pin 13

 asm volatile ("NOP");
 Serial.begin(BAUDRATE);

 asm volatile ("NOP");
 TIMSK1 = 0;               // Disable Timer1 interrupts

 DDRB |= (1 << HS1) | (1 << LS1);
 PORTB &= ~((1 << LS1) | (1 << HS1));

 ICR1 = MAX_COUNT;      
 TCCR1A = 0b00000000;
// PWM, Phase & Frequency Correct (Mode 8 ); Clock Select =
// System clock (No Prescaling) [Ref. Data Sheet, p. 172]
 TCCR1B = 0b00010001;
 OCR1A = 127;
 OCR1B = OCR1A + DT;  // Low side trigger pulse with a dead-time

 TCNT1 = MAX_COUNT; // Advance the phase by 180 deg

// pin D9 (OC1A): Set on Compare Match;
// pin D10 (OC1B): Clear on Compare Match
 TCCR1A |= 0b10110000;

 Serial.println("Ready");
 asm volatile ("NOP");
}

void loop()
{
 asm volatile ("NOP");
}

Successfully compiled using 1.8.13.
The code sets TC1 in mode 8.
The code simulation is OK in TinkerCAD, so I conclude the problem must be in SimulIDE 0.4.15-SR9.
Besides ATMega328 I did not test it in other ATMega MCU's.



Last edited by arcachofo on Fri Dec 24, 2021 2:36 am; edited 1 time in total (Reason for editing : Marked as solved (green color))

arcachofo

arcachofo

Thanks. I will have a look.

Does it work in previous versions?

janjos



Yes, it works in 0.4.13-SR5 and 0.4.14-SR4.
Tested using a PC with Windows 10 PRO 64-bit.

arcachofo likes this post

arcachofo

arcachofo

The problem is related to ICR.
Not sure yet exactly where is the bug.

As a workaround you can set ICR after TCCR, for example:
Code:
...
 TCCR1A = 0b00000000;
// PWM, Phase & Frequency Correct (Mode 8 ); Clock Select =
// System clock (No Prescaling) [Ref. Data Sheet, p. 172]
 TCCR1B = 0b00010001;
 ICR1 = MAX_COUNT;
 OCR1A = 127;
 OCR1B = OCR1A + DT;  // Low side trigger pulse with a dead-time
...

arcachofo

arcachofo

Issue solved at Rev 257.

janjos



I can confirm that the workaround, loading ICR1 only after setting TCCR1A and TCCR1B, solves the issue.
Thank you.

arcachofo likes this post

Sponsored content



Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum