update macro prescale values

This commit is contained in:
hugogogo
2025-03-07 11:34:17 +01:00
parent 1bb2e880c8
commit 08e1200408
6 changed files with 53 additions and 58 deletions

View File

@@ -51,17 +51,13 @@
// TIME
#define PRESCALE_VALUE 1024 // can be 1, 8, 64, 256, 1024
// table 16-5 : prescale sets
#if (PRESCALE_VALUE == 1)
#define PRESCALE_SET (0<<CS12 | 0<<CS11 | 1<<CS10)
#elif (PRESCALE_VALUE == 8)
#define PRESCALE_SET (0<<CS12 | 1<<CS11 | 0<<CS10)
#elif (PRESCALE_VALUE == 64)
#define PRESCALE_SET (0<<CS12 | 1<<CS11 | 1<<CS10)
#elif (PRESCALE_VALUE == 256)
#define PRESCALE_SET (1<<CS12 | 0<<CS11 | 0<<CS10)
#elif (PRESCALE_VALUE == 1024)
#define PRESCALE_SET (1<<CS12 | 0<<CS11 | 1<<CS10)
#endif
#define PRESCALE_SET(value) \
((value) == 1 ? (0<<CS12 | 0<<CS11 | 1<<CS10) : \
(value) == 8 ? (0<<CS12 | 1<<CS11 | 0<<CS10) : \
(value) == 64 ? (0<<CS12 | 1<<CS11 | 1<<CS10) : \
(value) == 256 ? (1<<CS12 | 0<<CS11 | 0<<CS10) : \
(value) == 1024? (1<<CS12 | 0<<CS11 | 1<<CS10) : \
(0<<CS12 | 0<<CS11 | 0<<CS10))
#define TIME_MS(ms) (((F_CPU / PRESCALE_VALUE) * ms) / 1000)
#define PERIOD 500
@@ -77,7 +73,7 @@ int main() {
OCR1A = TIME_MS(PERIOD); // Table 16-4 : set CTC compare value, the counter is cleared to zero when the counter value (TCNT1) matches the OCR1A register
TCCR1B |= (PRESCALE_SET);
TCCR1B |= (PRESCALE_SET(PRESCALE_VALUE));
while(1);
}