From 29687bfdf5bf7e0da34077aa33c131970d9d6c94 Mon Sep 17 00:00:00 2001 From: hugo LAMY Date: Thu, 6 Mar 2025 13:11:13 +0100 Subject: [PATCH] fix percentage error in ex02 --- module01/ex02/main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/module01/ex02/main.c b/module01/ex02/main.c index 77d3636..2ef21a2 100644 --- a/module01/ex02/main.c +++ b/module01/ex02/main.c @@ -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);