Commit d77b2035 authored by Oystein Smith's avatar Oystein Smith

main.c is the main

parent f0900a3e
/*
* SMD_Omega_Imponator.c
*
* Created: 20.10.2015 17:12:32
* Author: medlem
*/
#include <avr/io.h>
#include <util/delay.h>
#define LED_SET(led_num,led_percent) *led_outputs[led_num] = ((uint16_t)led_percent*(uint16_t)led_percent)
#define LED_MAX 100
#define LED_MIN 0
register16_t* led_outputs[16] = {
&TCC0.CCABUF, &TCC0.CCBBUF, &TCC0.CCCBUF, &TCC0.CCDBUF,
&TCC1.CCABUF, &TCC1.CCBBUF,
&TCD0.CCABUF, &TCD0.CCBBUF, &TCD0.CCCBUF, &TCD0.CCDBUF,
&TCD1.CCABUF, &TCD1.CCBBUF,
&TCE0.CCABUF, &TCE0.CCBBUF, &TCE0.CCCBUF, &TCE0.CCDBUF
};
void init_pwm( void );
int main(void) {
init_pwm();
int i = 0;
int val = 0;
while(1) {
_delay_ms(10);
LED_SET(i, val);
i++;
if (i > 16) {
i = 0;
if (val) {
val = 100;
} else {
val = 0;
}
}
}
}
void init_pwm( void ) {
PORTC.DIRSET = 0b00111111;
PORTD.DIRSET = 0b00111111;
PORTE.DIRSET = 0b00001111;
// Set period
TCC0.PER = 10000UL;
TCC1.PER = 10000UL;
TCD0.PER = 10000UL;
TCD1.PER = 10000UL;
TCE0.PER = 10000UL;
// ???
for (uint8_t i = 0; i < 16; i++) {
*led_outputs[i] = 9999UL;
}
// Set WG mode to single slope
TCC0.CTRLB |= TC_WGMODE_SS_gc;
TCC1.CTRLB |= TC_WGMODE_SS_gc;
TCD0.CTRLB |= TC_WGMODE_SS_gc;
TCD1.CTRLB |= TC_WGMODE_SS_gc;
TCE0.CTRLB |= TC_WGMODE_SS_gc;
// Enable compare channels
TCC0.CTRLB |= ( TC0_CCAEN_bm | TC0_CCBEN_bm | TC0_CCCEN_bm | TC0_CCDEN_bm );
TCC1.CTRLB |= ( TC1_CCAEN_bm | TC1_CCBEN_bm );
TCD0.CTRLB |= ( TC0_CCAEN_bm | TC0_CCBEN_bm | TC0_CCCEN_bm | TC0_CCDEN_bm );
TCD1.CTRLB |= ( TC1_CCAEN_bm | TC1_CCBEN_bm );
TCE0.CTRLB |= ( TC0_CCAEN_bm | TC0_CCBEN_bm | TC0_CCCEN_bm | TC0_CCDEN_bm );
// Start timer
TCC0.CTRLA |= TC_CLKSEL_DIV8_gc;
TCC1.CTRLA |= TC_CLKSEL_DIV8_gc;
TCD0.CTRLA |= TC_CLKSEL_DIV8_gc;
TCD1.CTRLA |= TC_CLKSEL_DIV8_gc;
TCE0.CTRLA |= TC_CLKSEL_DIV64_gc;
}
\ No newline at end of file
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