//Set up the leds and buttons. You might want to copy this from previous exercises.
//Set up the led and button on the Curiosiry Nano. You might want to copy this from previous exercises.
/*We will be using timer TCA0 in Split (not Single) mode. We use Split mode to output
waveforms on WO4 and WO5, see Figure 19-13.
waveforms on WO5, see Figure 19-13.
It is highly recommended that you read chapter 19.3.3.4 and 19.3.3.6 in the megaAVR® 0-series.
There you will find a sub-chapter on the single-slope PWM we will be using.
*/
...
...
@@ -33,7 +30,7 @@ int main(void)
//Set the mode of the timer to split slope PWM
//We have to override the normal pin opperation so the PWM is pushed directly to the pin
//Hint: WO4 and WO5 are connected to leds. We need to override them to get the PWM out.
//Hint: WO5 is connected to leds. We need to override them to get the PWM out.
//See Datasheet to ATmega4809 for pins.
...
...
@@ -46,18 +43,19 @@ int main(void)
//Set the period to 0xff bit. (What frequency does this give?)
//We can now control the PWM duty cycle by simply writing values to the CMP0 and CMP1 registers.
TCA0.SPLIT.HCMP1=0x00;//Max brightness (Leds are inverted)
TCA0.SPLIT.HCMP2=0xff;//Min brightness (Leds are inverted)
//We can now control the PWM duty cycle by simply writing values to the HCMP2 register.
//By commenting in one of the two lines below, you will get max or min brightness, any value 0x00-0xff (0-255) can be set to get a different brightness level. Try to set different values. Are leds linear in their brightness vs duty cycle?
//TCA0.SPLIT.HCMP2 = 0x00; //Max brightness (Leds are inverted)
//TCA0.SPLIT.HCMP2 = 0xff; //Min brightness (Leds are inverted)
//Set Duty cycle of WO4 to 0x7f to see it twinkle.
//Set Duty cycle of WO5 to 0x7f to see it twinkle.