Files
can-dimmer-hardware/README.md
2026-08-02 11:23:10 +02:00

31 lines
783 B
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
für zephr:
```
#include <zephyr/kernel.h>
#include <zephyr/arch/cpu.h>
static volatile uint16_t target_val = 0;
static uint16_t akku = 0;
// Direct ISR deklarieren minimaler Overhead!
ISR_DIRECT_DECLARE(my_pwm_dither_isr)
{
// 1. Hardware Interrupt-Flag löschen (direkt übers CMSIS-Register)
TIMx->SR = ~TIM_SR_UIF;
// 2. Deine Akku-Rechnung
akku += target_val;
TIMx->CCR1 = (akku >> 6);
akku &= 0x3F; // Behält die letzten 6 Bits: der Rest der Bit-Shift-Division
// 3. Kein Reschedule nötig, da wir keine Zephyr-API in der ISR aufrufen
return 0;
}
void init_pwm_dither(void)
{
// Interrupt in Zephyr registrieren (Priority z.B. 1 oder 2)
IRQ_DIRECT_CONNECT(TIMx_IRQn, 1, my_pwm_dither_isr, 0);
irq_enable(TIMx_IRQn);
}
```