I have seen an issue when configuring Timer 1 for fast PWM operation on an ATmega328P microcontroller. I am using mode 14 with the ICR1 register setting the count TOP value. I load the ICR1 register with 19999 (0x4E1F). However when simulating, the ICR1 register contains the value 19968 (0x4E00). It seems that the low byte is not written to the ICR1L register.
I have tested my code on a microcontroller board and the ICR1 register is configured as expected. My C code is shown below.
int main(void)
{
uint8_t x, ch;
int8_t LED_level = 0, motorLevel = 0;
/* Initializes MCU, drivers and middleware */
atmel_start_init();
/* Place GPIO and peripheral initialisation code here */
PRR &= 0xF7;
PORTB_set_pin_dir(LED, PORT_DIR_OUT);
PORTB_set_pin_dir(MOTOR, PORT_DIR_OUT);
TCCR1A = 0xA2;
ICR1 = 19999; //100Hz PWM, FCPU = 16MHz, N = 8
printf("ICR1: %d\n\r", ICR1);
OCR1A = LED_level * ICR1/10;
OCR1B = motorLevel * ICR1/10;
TCCR1B = 0x1A;
I have tested my code on a microcontroller board and the ICR1 register is configured as expected. My C code is shown below.
int main(void)
{
uint8_t x, ch;
int8_t LED_level = 0, motorLevel = 0;
/* Initializes MCU, drivers and middleware */
atmel_start_init();
/* Place GPIO and peripheral initialisation code here */
PRR &= 0xF7;
PORTB_set_pin_dir(LED, PORT_DIR_OUT);
PORTB_set_pin_dir(MOTOR, PORT_DIR_OUT);
TCCR1A = 0xA2;
ICR1 = 19999; //100Hz PWM, FCPU = 16MHz, N = 8
printf("ICR1: %d\n\r", ICR1);
OCR1A = LED_level * ICR1/10;
OCR1B = motorLevel * ICR1/10;
TCCR1B = 0x1A;
Last edited by Niall on Tue Mar 15, 2022 2:23 pm; edited 1 time in total (Reason for editing : Could not upload code file so I have added to post as text.)