get hw pwm running
This commit is contained in:
13
main.c
13
main.c
@ -63,7 +63,7 @@ void ledStaticFull(void);
|
||||
int main(void)
|
||||
{
|
||||
// Configure LED pins as outputs
|
||||
VPORTA.DIR = (PA2_SET_MASK | PA3_SET_MASK | PA6_SET_MASK | PA7_SET_MASK);
|
||||
VPORTA.DIR = (PA1_SET_MASK | PA2_SET_MASK | PA3_SET_MASK | PA6_SET_MASK | PA7_SET_MASK);
|
||||
initPWM();
|
||||
|
||||
// Configure PA0 as input with pull-up
|
||||
@ -152,15 +152,10 @@ static inline void switchMode(void)
|
||||
|
||||
void initPWM(void)
|
||||
{
|
||||
// Configure PA2 as output
|
||||
PORTA.DIRSET = PIN2_bm;
|
||||
|
||||
// Remap TCA0 WO0 to alternative pin (PA2)
|
||||
// Check datasheet for correct PORTMUX bit - this is typically:
|
||||
PORTMUX.CTRLC = PORTMUX_TCA00_bm; // or similar bit to route WO0 to PA2
|
||||
// No PORTMUX needed - PA2 is WO2 by default
|
||||
|
||||
// TCA0 in normal mode (single slope PWM)
|
||||
TCA0.SINGLE.CTRLB = TCA_SINGLE_CMP0EN_bm | TCA_SINGLE_WGMODE_SINGLESLOPE_gc;
|
||||
TCA0.SINGLE.CTRLB = TCA_SINGLE_CMP2EN_bm | TCA_SINGLE_WGMODE_SINGLESLOPE_gc;
|
||||
|
||||
// Set period for ~19.5kHz PWM (5MHz / 256 = ~19.5kHz)
|
||||
TCA0.SINGLE.PER = 0xFF;
|
||||
@ -171,7 +166,7 @@ void initPWM(void)
|
||||
|
||||
void setPWM_PA2(uint8_t duty)
|
||||
{
|
||||
TCA0.SINGLE.CMP0 = duty;
|
||||
TCA0.SINGLE.CMP2 = duty;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user