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.
/**************************************************
(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))