Commit 77c5ed9a authored by johanvaa's avatar johanvaa
Browse files

Update main.c

parent a0533b93
#define F_CPU 3333333UL
......@@ -6,9 +5,7 @@
#include <util/delay.h>
#include <avr/interrupt.h>
#define LED1 4 // port D, connected to WO4
#define LED2 5 // port D, connected to WO5
#define LED0 5 //PORT F, connected to WO5
......@@ -20,10 +17,10 @@
int main(void)
{
//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.
while(1){
/*Have some fun with the leds. Examples:
Have them fade between max and min
Have them fade in a pattern (Heartbeat?)
/*Have some fun with the led. Examples:
Have it fade between max and min
Have it fade in a pattern (Heartbeat?)
Change the brightness based on buttons
*/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment