updated prescaler values
This commit is contained in:
@@ -49,17 +49,18 @@
|
||||
#define BUTTON2 (D, SW2)
|
||||
|
||||
// TIME
|
||||
#define PRESCALE_VALUE 1024
|
||||
#define PRESCALE_VALUE 1024 // can be 1, 8, 64, 256, 1024
|
||||
// table 16-5 : prescale sets
|
||||
#if (PRESCALE_VALUE == 1)
|
||||
#define PRESCALE_SET (1 << CS10)
|
||||
#define PRESCALE_SET (0<<CS12 | 0<<CS11 | 1<<CS10)
|
||||
#elif (PRESCALE_VALUE == 8)
|
||||
#define PRESCALE_SET (1 << CS11)
|
||||
#define PRESCALE_SET (0<<CS12 | 1<<CS11 | 0<<CS10)
|
||||
#elif (PRESCALE_VALUE == 64)
|
||||
#define PRESCALE_SET (1 << CS10) | (1 << CS11)
|
||||
#define PRESCALE_SET (0<<CS12 | 1<<CS11 | 1<<CS10)
|
||||
#elif (PRESCALE_VALUE == 256)
|
||||
#define PRESCALE_SET (1 << CS12)
|
||||
#define PRESCALE_SET (1<<CS12 | 0<<CS11 | 0<<CS10)
|
||||
#elif (PRESCALE_VALUE == 1024)
|
||||
#define PRESCALE_SET (1 << CS10) | (1 << CS12)
|
||||
#define PRESCALE_SET (1<<CS12 | 0<<CS11 | 1<<CS10)
|
||||
#endif
|
||||
#define TIME_MS(ms) (((F_CPU / PRESCALE_VALUE) * ms) / 1000)
|
||||
|
||||
@@ -69,7 +70,7 @@ int main() {
|
||||
MODE_OUTPUT(LED2);
|
||||
CLEAR_ELEM(LED2);
|
||||
|
||||
TCCR1B |= (PRESCALE_SET); // 16.4 : set timer with bits CS10-12, in register TCCR1B, table 16-5 : prescale values
|
||||
TCCR1B |= (PRESCALE_SET); // 16.4 : set timer according to prescale value, in register TCCR1B, table 16-5 : prescale sets
|
||||
|
||||
while(1) {
|
||||
if (TCNT1 >= TIME_MS(500)) { // 16.11.4 : read timer with register TCNT1 (read/write allowed), that combines two 8 bits registers
|
||||
|
||||
@@ -49,17 +49,18 @@
|
||||
#define BUTTON2 (D, SW2)
|
||||
|
||||
// TIME
|
||||
#define PRESCALE_VALUE 1024
|
||||
#define PRESCALE_VALUE 1024 // can be 1, 8, 64, 256, 1024
|
||||
// table 16-5 : prescale sets
|
||||
#if (PRESCALE_VALUE == 1)
|
||||
#define PRESCALE_SET (1 << CS10)
|
||||
#define PRESCALE_SET (0<<CS12 | 0<<CS11 | 1<<CS10)
|
||||
#elif (PRESCALE_VALUE == 8)
|
||||
#define PRESCALE_SET (1 << CS11)
|
||||
#define PRESCALE_SET (0<<CS12 | 1<<CS11 | 0<<CS10)
|
||||
#elif (PRESCALE_VALUE == 64)
|
||||
#define PRESCALE_SET (1 << CS10) | (1 << CS11)
|
||||
#define PRESCALE_SET (0<<CS12 | 1<<CS11 | 1<<CS10)
|
||||
#elif (PRESCALE_VALUE == 256)
|
||||
#define PRESCALE_SET (1 << CS12)
|
||||
#define PRESCALE_SET (1<<CS12 | 0<<CS11 | 0<<CS10)
|
||||
#elif (PRESCALE_VALUE == 1024)
|
||||
#define PRESCALE_SET (1 << CS10) | (1 << CS12)
|
||||
#define PRESCALE_SET (1<<CS12 | 0<<CS11 | 1<<CS10)
|
||||
#endif
|
||||
#define TIME_MS(ms) (((F_CPU / PRESCALE_VALUE) * ms) / 1000)
|
||||
#define PERIOD 500
|
||||
|
||||
@@ -49,17 +49,18 @@
|
||||
#define BUTTON2 (D, SW2)
|
||||
|
||||
// TIME
|
||||
#define PRESCALE_VALUE 1024
|
||||
#define PRESCALE_VALUE 1024 // can be 1, 8, 64, 256, 1024
|
||||
// table 16-5 : prescale sets
|
||||
#if (PRESCALE_VALUE == 1)
|
||||
#define PRESCALE_SET (1 << CS10)
|
||||
#define PRESCALE_SET (0<<CS12 | 0<<CS11 | 1<<CS10)
|
||||
#elif (PRESCALE_VALUE == 8)
|
||||
#define PRESCALE_SET (1 << CS11)
|
||||
#define PRESCALE_SET (0<<CS12 | 1<<CS11 | 0<<CS10)
|
||||
#elif (PRESCALE_VALUE == 64)
|
||||
#define PRESCALE_SET (1 << CS10) | (1 << CS11)
|
||||
#define PRESCALE_SET (0<<CS12 | 1<<CS11 | 1<<CS10)
|
||||
#elif (PRESCALE_VALUE == 256)
|
||||
#define PRESCALE_SET (1 << CS12)
|
||||
#define PRESCALE_SET (1<<CS12 | 0<<CS11 | 0<<CS10)
|
||||
#elif (PRESCALE_VALUE == 1024)
|
||||
#define PRESCALE_SET (1 << CS10) | (1 << CS12)
|
||||
#define PRESCALE_SET (1<<CS12 | 0<<CS11 | 1<<CS10)
|
||||
#endif
|
||||
#define TIME_MS(ms) (((F_CPU / PRESCALE_VALUE) * ms) / 1000)
|
||||
#define PERIOD 1000
|
||||
|
||||
@@ -50,22 +50,32 @@
|
||||
#define BUTTON2 (D, SW2)
|
||||
|
||||
// TIME
|
||||
#define PRESCALE_VALUE 1024
|
||||
#define PRESCALE_VALUE 1024 // can be 1, 8, 64, 256, 1024
|
||||
// table 16-5 : prescale sets
|
||||
#if (PRESCALE_VALUE == 1)
|
||||
#define PRESCALE_SET (1 << CS10)
|
||||
#define PRESCALE_SET (0<<CS12 | 0<<CS11 | 1<<CS10)
|
||||
#elif (PRESCALE_VALUE == 8)
|
||||
#define PRESCALE_SET (1 << CS11)
|
||||
#define PRESCALE_SET (0<<CS12 | 1<<CS11 | 0<<CS10)
|
||||
#elif (PRESCALE_VALUE == 64)
|
||||
#define PRESCALE_SET (1 << CS10) | (1 << CS11)
|
||||
#define PRESCALE_SET (0<<CS12 | 1<<CS11 | 1<<CS10)
|
||||
#elif (PRESCALE_VALUE == 256)
|
||||
#define PRESCALE_SET (1 << CS12)
|
||||
#define PRESCALE_SET (1<<CS12 | 0<<CS11 | 0<<CS10)
|
||||
#elif (PRESCALE_VALUE == 1024)
|
||||
#define PRESCALE_SET (1 << CS10) | (1 << CS12)
|
||||
#define PRESCALE_SET (1<<CS12 | 0<<CS11 | 1<<CS10)
|
||||
#endif
|
||||
#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)
|
||||
// Table 16-4 : Waveform Generation Mode Bit Description
|
||||
#define CTC_TOP_OCR1A_IN_TCCR1B (0<<WGM13 | 1<<WGM12)
|
||||
#define CTC_TOP_OCR1A_IN_TCCR1A (0<<WGM11 | 0<<WGM10)
|
||||
#define CTC_TOP_ICR1_IN_TCCR1B (1<<WGM13 | 1<<WGM12)
|
||||
#define CTC_TOP_ICR1_IN_TCCR1A (0<<WGM11 | 0<<WGM10)
|
||||
#define FAST_PWM_TOP_OCR1A_IN_TCCR1B (1<<WGM13 | 1<<WGM12)
|
||||
#define FAST_PWM_TOP_OCR1A_IN_TCCR1A (1<<WGM11 | 1<<WGM10)
|
||||
#define FAST_PWM_TOP_ICR1_IN_TCCR1B (1<<WGM13 | 1<<WGM12)
|
||||
#define FAST_PWM_TOP_ICR1_IN_TCCR1A (1<<WGM11 | 0<<WGM10)
|
||||
|
||||
// END MACROS
|
||||
|
||||
@@ -110,9 +120,8 @@ int main() {
|
||||
|
||||
MODE_OUTPUT(LED2);
|
||||
|
||||
SET(TCCR1A, WGM11); // Table 16-4 : set timer in Fast PWM (Pulse With Modulation) mode with TOP = ICR1 (Mode 14)
|
||||
SET(TCCR1B, WGM12);
|
||||
SET(TCCR1B, WGM13);
|
||||
TCCR1A |= FAST_PWM_TOP_ICR1_IN_TCCR1A; // Table 16-4 : set timer in Fast PWM (Pulse With Modulation) mode with TOP = ICR1 (Mode 14)
|
||||
TCCR1B |= FAST_PWM_TOP_ICR1_IN_TCCR1B;
|
||||
|
||||
SET(TCCR1A, COM1A1); // Table 16-2 : non-inverting mode, the LED will be ON for DUTY_CYCLE% of the time (CLEAR OC1A on compare match, SET OC1A at BOTTOM)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user