Hello Everyone!
I am working on a personal project that needs 12 PWM outputs. When testing it in simulation (I am using Proteus 8) I observed an odd behavior on OCR4B, OCR4C, OCR5B, and OCR4C.
In my code, I take a value from an array and put it in each of the OCR registers I am using. When it comes to the aforementioned registers the value in memory is different from the value in the register.
Below I attached the relevant part of my code and the register/memory values from the simulation.
int main(void){ pwm_init(); for(;;){ pwm_set(); } return (0); } void pwm_init(){ TCCR1A |= _BV(WGM11) | _BV(COM1A1) | _BV(COM1B1) | _BV(COM1C1); TCCR3A |= _BV(WGM31) | _BV(COM3A1) | _BV(COM3B1) | _BV(COM3C1); TCCR4A |= _BV(WGM41) | _BV(COM4A1) | _BV(COM4B1) | _BV(COM4C1); TCCR5A |= _BV(WGM51) | _BV(COM5A1) | _BV(COM5B1) | _BV(COM5C1); TCCR1B |= _BV(WGM13) | _BV(WGM12) | _BV(CS11); TCCR3B |= _BV(WGM33) | _BV(WGM32) | _BV(CS31); TCCR4B |= _BV(WGM43) | _BV(WGM42) | _BV(CS41); TCCR5B |= _BV(WGM53) | _BV(WGM52) | _BV(CS51); ICR1 = 0x0FFF; ICR3 = 0x0FFF; ICR4 = 0x0FFF; ICR5 = 0x0FFF; DDRB |= _BV(DDB5) | _BV(DDB6) | _BV(DDB7); DDRE |= _BV(DDE3) | _BV(DDE4) | _BV(DDE5); DDRH |= _BV(DDH3) | _BV(DDH4) | _BV(DDH5); DDRL |= _BV(DDL3) | _BV(DDL4) | _BV(DDL5); } void pwm_set(){ OCR1A = duty_cycles[0]; OCR1B = duty_cycles[1]; OCR1C = duty_cycles[2]; OCR3A = duty_cycles[3]; OCR3B = duty_cycles[4]; OCR3C = duty_cycles[5]; OCR4A = duty_cycles[6]; OCR4B = duty_cycles[7]; OCR4C = duty_cycles[8]; OCR5A = duty_cycles[9]; OCR5B = duty_cycles[10]; OCR5C = duty_cycles[11]; }
Here there is the memory value for the elements of the duty_cycle array (index 0 is on address 0x0206)
Here there is the value in the registers (OCR1 on line 0x0080, OCR3 on line 0x0090, OCR4 on line 0x00A0, OCR5 on line 0x0120, and it is organized in the format OCRnAL, OCRnAH, OCRnBL, OCRnBH, OCRnCL, OCRnCH)
Could anyone help me find out if I made any mistakes in the code? Or this behavior only happens in a simulation?
Thanks for your help!