fix percentage error in ex02
This commit is contained in:
@@ -64,6 +64,7 @@
|
|||||||
#define TIME_MS(ms) (((F_CPU / PRESCALE_VALUE) * ms) / 1000)
|
#define TIME_MS(ms) (((F_CPU / PRESCALE_VALUE) * ms) / 1000)
|
||||||
#define PERIOD 1000
|
#define PERIOD 1000
|
||||||
#define DUTY_CYCLE 10
|
#define DUTY_CYCLE 10
|
||||||
|
#define PERCENT(percent, period) (((float)percent / 100) * period)
|
||||||
|
|
||||||
// END MACROS
|
// END MACROS
|
||||||
|
|
||||||
@@ -83,7 +84,7 @@ int main() {
|
|||||||
ICR1 = TIME_MS(PERIOD);
|
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
|
// 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
|
// start the timer with the prescaler
|
||||||
TCCR1B |= (PRESCALE_SET);
|
TCCR1B |= (PRESCALE_SET);
|
||||||
|
|||||||
Reference in New Issue
Block a user