add pwm second channnel
This commit is contained in:
@@ -8,7 +8,8 @@
|
|||||||
#define LED34_SW_DDR DDRA
|
#define LED34_SW_DDR DDRA
|
||||||
#define LED34_SW_PORT PORTA
|
#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_DDR DDRA
|
||||||
#define LED_PWM_PORT PORTA
|
#define LED_PWM_PORT PORTA
|
||||||
|
|
||||||
|
|||||||
37
src/main.c
37
src/main.c
@@ -17,8 +17,8 @@ ButtonKey_t probe_int = {
|
|||||||
.state = IDLE,
|
.state = IDLE,
|
||||||
.last_state = IDLE,
|
.last_state = IDLE,
|
||||||
.active_state = GPIO_PIN_SET,
|
.active_state = GPIO_PIN_SET,
|
||||||
.timer_debounce_on = 10000, // 1000 ms
|
.timer_debounce_on = 10, // 1000 ms
|
||||||
.timer_debounce_off = 10000, // 1 ms
|
.timer_debounce_off = 10, // 1 ms
|
||||||
.buttonReleased = probe_int_off,
|
.buttonReleased = probe_int_off,
|
||||||
.buttonPressed = probe_int_on,
|
.buttonPressed = probe_int_on,
|
||||||
};
|
};
|
||||||
@@ -43,37 +43,14 @@ int main(void)
|
|||||||
LED12_SW_DDR |= (1 << LED12_SW_PIN);
|
LED12_SW_DDR |= (1 << LED12_SW_PIN);
|
||||||
LED34_SW_DDR |= (1 << LED34_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();
|
led_pwm();
|
||||||
timer0_init();
|
timer0_init();
|
||||||
|
|
||||||
sei(); // Enable global interrupts
|
sei(); // Enable global interrupts
|
||||||
|
|
||||||
// uint8_t i = 0;
|
|
||||||
while (1)
|
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++)
|
for (uint8_t i = 0; i < sizeof(inputs) / sizeof(inputs[0]); i++)
|
||||||
{
|
{
|
||||||
buttonHandler(inputs[i]);
|
buttonHandler(inputs[i]);
|
||||||
@@ -84,10 +61,10 @@ int main(void)
|
|||||||
void led_pwm(void)
|
void led_pwm(void)
|
||||||
{
|
{
|
||||||
// Ustaw pin PB1 (OC1A) jako wyjście
|
// 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)
|
// Ustaw Timer1 w trybie Fast PWM, 8-bit (WGM13:0 = 0b0101)
|
||||||
TCCR1A = (1 << COM1A1) | (1 << WGM10); // Clear OC1A on compare match
|
TCCR1A = (1 << COM1A1) | (1 << COM1B1) | (1 << WGM10); // Clear OC1A on compare match
|
||||||
TCCR1B = (1 << WGM12) | (1 << CS11) | (1 << CS10); // Prescaler 64
|
TCCR1B = (1 << WGM12) | (1 << CS11) | (1 << CS10); // Prescaler 64
|
||||||
|
|
||||||
// Ustaw wartość w rejestrze OCR1A (wypełnienie PWM)
|
// Ustaw wartość w rejestrze OCR1A (wypełnienie PWM)
|
||||||
@@ -97,17 +74,17 @@ void led_pwm(void)
|
|||||||
void probe_int_on(ButtonKey_t *key)
|
void probe_int_on(ButtonKey_t *key)
|
||||||
{
|
{
|
||||||
LED12_SW_PORT |= (1 << LED12_SW_PIN);
|
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)
|
void probe_int_off(ButtonKey_t *key)
|
||||||
{
|
{
|
||||||
LED12_SW_PORT &= ~(1 << LED12_SW_PIN);
|
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)
|
void estop_on(ButtonKey_t *key)
|
||||||
{
|
{
|
||||||
TCCR1A &= ~(1 << COM1A1); // Wyłącz PWM
|
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)
|
void estop_off(ButtonKey_t *key)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user