setup mod02 ex00 and oneline comments

This commit is contained in:
hugo LAMY
2025-03-06 16:23:18 +01:00
parent 6ec379e1ae
commit ebb578db5f
6 changed files with 86 additions and 28 deletions

View File

@@ -68,16 +68,11 @@
int main() {
MODE_OUTPUT(LED2);
TCCR1B |= (1 << WGM12); // set timer in CTC (Clear Time on Compare) mode
// -> Table 16-4 : use bit WGM12 to set mode ctc
// -> 16.11.2 : bit WGM12 is located in register TCCR1B
TCCR1B |= (1 << WGM12); // Table 16-4 : set timer in CTC (Clear Time on Compare) mode, use bit WGM12, located in register TCCR1B (16.11.2)
TCCR1A |= (1 << COM1A0); // enable timer 1 Compare Output channel A in toggle mode
// -> Table 14-3 : alternate functions for PORTB1 is OC1A (Timer/Counter1 Output Compare Match A Output)
// -> 14.3.1 : OC1A/PCINT1 Port B, Bit 1
TCCR1A |= (1 << COM1A0); // 14.3.1 : set Compare Output with COM1A0, it toggles OC1A on compare match (Table 16-1), OC1A is alternate function for PORTB1 (Table 14-3)
OCR1A = TIME_MS(500); // set CTC compare value
// -> Table 16-4 : the value to reset the timer is the Output Compare Registers OCR1A
OCR1A = TIME_MS(500); // 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);

View File

@@ -72,22 +72,17 @@
int main() {
MODE_OUTPUT(LED2);
// Table 16-4 : set timer in Fast PWM (Pulse With Modulation) mode with TOP = ICR1 (Mode 14)
SET(TCCR1A, WGM11);
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);
// 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)
SET(TCCR1A, COM1A1);
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)
// Table 16-4 : set the period (compare TOP value)
ICR1 = TIME_MS(PERIOD);
ICR1 = TIME_MS(PERIOD); // Table 16-4 : set the period (compare TOP value)
// 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(PERCENT(DUTY_CYCLE, PERIOD));
OCR1A = TIME_MS(PERCENT(DUTY_CYCLE, 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
// start the timer with the prescaler
TCCR1B |= (PRESCALE_SET);
TCCR1B |= (PRESCALE_SET); // start the timer with the prescaler
while(1) {
continue;

View File

@@ -110,22 +110,17 @@ int main() {
MODE_OUTPUT(LED2);
// Table 16-4 : set timer in Fast PWM (Pulse With Modulation) mode with TOP = ICR1 (Mode 14)
SET(TCCR1A, WGM11);
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);
// 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)
SET(TCCR1A, COM1A1);
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)
// Table 16-4 : set the period (compare TOP value)
ICR1 = TIME_MS(PERIOD);
ICR1 = TIME_MS(PERIOD); // Table 16-4 : set the period (compare TOP value)
// 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(PERCENT(DUTY_CYCLE, PERIOD));
OCR1A = TIME_MS(PERCENT(DUTY_CYCLE, 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
// start the timer with the prescaler
TCCR1B |= (PRESCALE_SET);
TCCR1B |= (PRESCALE_SET); // start the timer with the prescaler
while(1) {
on_press(SW1, increment_duty_cycle, &params);