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);