fix percentage error in ex02

This commit is contained in:
hugo LAMY
2025-03-06 13:11:13 +01:00
parent ea43423716
commit 29687bfdf5

View File

@@ -64,6 +64,7 @@
#define TIME_MS(ms) (((F_CPU / PRESCALE_VALUE) * ms) / 1000)
#define PERIOD 1000
#define DUTY_CYCLE 10
#define PERCENT(percent, period) (((float)percent / 100) * period)
// END MACROS
@@ -83,7 +84,7 @@ int main() {
ICR1 = TIME_MS(PERIOD);
// 16.9.3 : set the duty cycle to DUTY_CYCLE% of the time -> OC1A (alternate function of PORTB1, aka LED2) is cleared when TCNT1 (the counter value) equals OCR1A
OCR1A = TIME_MS(DUTY_CYCLE);
OCR1A = TIME_MS(PERCENT(DUTY_CYCLE, PERIOD));
// start the timer with the prescaler
TCCR1B |= (PRESCALE_SET);