From fd658face824536b7dc7cee41fba06ebea3e97e4 Mon Sep 17 00:00:00 2001 From: bartool Date: Thu, 29 May 2025 21:35:58 +0200 Subject: [PATCH] add pwm second channnel --- src/defs.h | 3 ++- src/main.c | 39 ++++++++------------------------------- 2 files changed, 10 insertions(+), 32 deletions(-) diff --git a/src/defs.h b/src/defs.h index c197beb..66ec89e 100644 --- a/src/defs.h +++ b/src/defs.h @@ -8,7 +8,8 @@ #define LED34_SW_DDR DDRA #define LED34_SW_PORT PORTA -#define LED_PWM_PIN PA6 +#define LED_PWM1_PIN PA6 +#define LED_PWM2_PIN PA5 #define LED_PWM_DDR DDRA #define LED_PWM_PORT PORTA diff --git a/src/main.c b/src/main.c index 6329d06..3d5e8f4 100644 --- a/src/main.c +++ b/src/main.c @@ -17,8 +17,8 @@ ButtonKey_t probe_int = { .state = IDLE, .last_state = IDLE, .active_state = GPIO_PIN_SET, - .timer_debounce_on = 10000, // 1000 ms - .timer_debounce_off = 10000, // 1 ms + .timer_debounce_on = 10, // 1000 ms + .timer_debounce_off = 10, // 1 ms .buttonReleased = probe_int_off, .buttonPressed = probe_int_on, }; @@ -43,37 +43,14 @@ int main(void) LED12_SW_DDR |= (1 << LED12_SW_PIN); LED34_SW_DDR |= (1 << LED34_SW_PIN); - // LED12_SW_PORT |= (1 << LED12_SW_PIN); - // LED34_SW_PORT |= (1 << LED34_SW_PIN); led_pwm(); timer0_init(); sei(); // Enable global interrupts - // uint8_t i = 0; while (1) { - // if (PINA & (1 << PROBE_INT_PIN)) - // { - // LED12_SW_PORT |= (1 << LED12_SW_PIN); - // LED34_SW_PORT |= (1 << LED34_SW_PIN); - // } - // else - // { - // LED12_SW_PORT &= ~(1 << LED12_SW_PIN); - // LED34_SW_PORT &= ~(1 << LED34_SW_PIN); - // } - // if (!(PINA & (1 << ESTOP_IN_PIN))) - // { - // TCCR1A &= ~(1 << COM1A1); // Wyłącz PWM - // LED_PWM_PORT &= ~(1 << LED_PWM_PIN); - // } - // else - // { - // TCCR1A |= (1 << COM1A1); // Włącz PWM - // // LED_PWM_PORT |= (1 << LED_PWM_PIN); - // } for (uint8_t i = 0; i < sizeof(inputs) / sizeof(inputs[0]); i++) { buttonHandler(inputs[i]); @@ -84,11 +61,11 @@ int main(void) void led_pwm(void) { // Ustaw pin PB1 (OC1A) jako wyjście - LED_PWM_DDR |= (1 << LED_PWM_PIN); + LED_PWM_DDR |= (1 << LED_PWM1_PIN) | (1 << LED_PWM2_PIN); // Ustaw Timer1 w trybie Fast PWM, 8-bit (WGM13:0 = 0b0101) - TCCR1A = (1 << COM1A1) | (1 << WGM10); // Clear OC1A on compare match - TCCR1B = (1 << WGM12) | (1 << CS11) | (1 << CS10); // Prescaler 64 + TCCR1A = (1 << COM1A1) | (1 << COM1B1) | (1 << WGM10); // Clear OC1A on compare match + TCCR1B = (1 << WGM12) | (1 << CS11) | (1 << CS10); // Prescaler 64 // Ustaw wartość w rejestrze OCR1A (wypełnienie PWM) OCR1A = 2; // 50% wypełnienia (dla 8-bit: 128/255) @@ -97,17 +74,17 @@ void led_pwm(void) void probe_int_on(ButtonKey_t *key) { LED12_SW_PORT |= (1 << LED12_SW_PIN); - LED34_SW_PORT |= (1 << LED34_SW_PIN); + LED34_SW_PORT &= ~(1 << LED34_SW_PIN); } void probe_int_off(ButtonKey_t *key) { LED12_SW_PORT &= ~(1 << LED12_SW_PIN); - LED34_SW_PORT &= ~(1 << LED34_SW_PIN); + LED34_SW_PORT |= (1 << LED34_SW_PIN); } void estop_on(ButtonKey_t *key) { TCCR1A &= ~(1 << COM1A1); // Wyłącz PWM - LED_PWM_PORT &= ~(1 << LED_PWM_PIN); + LED_PWM_PORT &= ~(1 << LED_PWM1_PIN); } void estop_off(ButtonKey_t *key) {