Commit eed87fa2 authored by johanvaa's avatar johanvaa
Browse files

Update PWM-LF.c

parent 77c5ed9a
#define F_CPU 20000000UL
......@@ -18,13 +17,11 @@ Example: LED1_PORT.OUTSET = (1 << LED1);
*/
#define LED1 4 //pin
#define LED2 5 //pin
#define LED3 5 //pin
#define LED0 5 //pin
#define LED0_PORT PORTF //port
#define LED1_PORT PORTD //port
#define LED2_PORT PORTD //port
#define LED3_PORT PORTC //port
......@@ -40,26 +37,23 @@ int main(void)
{
sei();
LED1_PORT.DIRSET = (1 << LED1); //Datasheet say that we should put pins to PWM as outputs.
LED2_PORT.DIRSET = (1 << LED2); //Also, since we put signals out on them, this make sense.
LED0_PORT.DIRSET = (1 << LED0); //Datasheet say that we should put pins to PWM as outputs.
/**
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.
we need to use portmux to change TCA to Port F. We find that the led is at port F, and pin 5 by looking at datasheets and silk text for PCBs.
*/
PORTMUX.TCAROUTEA = (0x3 << 0);
PORTMUX.TCAROUTEA = (0x5 << 0);
TCA0.SPLIT.CTRLD |= (1 << TCA_SPLIT_SPLITM_bp); //Set splitmode to get access to WO4 and WO5
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.
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.
TCA0.SPLIT.CTRLB |= (1 << TCA_SPLIT_HCMP2EN_bp); //Enable High 2 to get output on WO5. See Figure 19-13 in functional description datasheet.
TCA0.SPLIT.HPER = TOP_PERIOD; // Set period for High compare. See figures in datasheet. But this is the PWM Period.
TCA0.SPLIT.HCMP1 = 0x00; //See figures in datasheet. This is the PWM duty cycle.
TCA0.SPLIT.HCMP2 = 0x00;
TCA0.SPLIT.HCMP2 = 0x00; //See figures in datasheet. This is the PWM duty cycle.
while(1){
......@@ -72,12 +66,12 @@ int main(void)
*/
for (uint8_t i = 0; i < TOP_PERIOD; i++) {
TCA0.SPLIT.HCMP1 = i;
//TCA0.SPLIT.HCMP1 = i; from when we had 2 leds, will be back in 2022
TCA0.SPLIT.HCMP2 = TOP_PERIOD-i;
_delay_ms(2);
}
for (uint8_t i = TOP_PERIOD; i > 0;i--) {
TCA0.SPLIT.HCMP1 = i;
//TCA0.SPLIT.HCMP1 = i; from when we had 2 leds, will be back in 2022
TCA0.SPLIT.HCMP2 = TOP_PERIOD-i;
_delay_ms(2);
}
......
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