Once we have PWM set up, controlling the brightness is super easy!
*/
int main(void)
{
sei();
b8: 78 94 sei
LED1_PORT.DIRSET = (1 << LED1); //Datasheet say that we should put pins to PWM as outputs.
ba: e0 e6 ldi r30, 0x60 ; 96
bc: f4 e0 ldi r31, 0x04 ; 4
be: 80 e1 ldi r24, 0x10 ; 16
c0: 81 83 std Z+1, r24 ; 0x01
LED2_PORT.DIRSET = (1 << LED2); //Also, since we put signals out on them, this make sense.
c2: 80 e2 ldi r24, 0x20 ; 32
c4: 81 83 std Z+1, r24 ; 0x01
/**
In dataheet: "http://ww1.microchip.com/downloads/en/DeviceDoc/40002016A.pdf", section 4.1, Multiplexed signals, we see that if we want to use TCA0 with PD4 and PD5,
we need to use portmux to change TCA to Port D. We find that the led is at port D, pin 4 and 5 by looking at datasheets and silk text for PCBs.
TCA0.SPLIT.CTRLD |= (1 << TCA_SPLIT_SPLITM_bp); //Set splitmode to get access to WO4 and WO5
cc: e0 e0 ldi r30, 0x00 ; 0
ce: fa e0 ldi r31, 0x0A ; 10
d0: 83 81 ldd r24, Z+3 ; 0x03
d2: 81 60 ori r24, 0x01 ; 1
d4: 83 83 std Z+3, r24 ; 0x03
TCA0.SPLIT.CTRLA |= (1 << TCA_SPLIT_ENABLE_bp) | (TCA_SPLIT_CLKSEL_DIV1_gc); //Enable the TCA and set prescaler to 1. Try different prescalers and see what happens.
d6: 80 81 ld r24, Z
d8: 81 60 ori r24, 0x01 ; 1
da: 80 83 st Z, r24
TCA0.SPLIT.CTRLB |= (1 << TCA_SPLIT_HCMP1EN_bp) | (1 << TCA_SPLIT_HCMP2EN_bp); //Enable High Compare 1 and 2 to get output on WO4 and WO5. See Figure 19-13 in functional description datasheet.
dc: 81 81 ldd r24, Z+1 ; 0x01
de: 80 66 ori r24, 0x60 ; 96
e0: 81 83 std Z+1, r24 ; 0x01
TCA0.SPLIT.HPER = TOP_PERIOD; // Set period for High compare. See figures in datasheet. But this is the PWM Period.
e2: 85 e5 ldi r24, 0x55 ; 85
e4: 87 a3 std Z+39, r24 ; 0x27
TCA0.SPLIT.HCMP1 = 0x00; //See figures in datasheet. This is the PWM duty cycle.