/******************************************************** * Interrupt Handling for PWM and timer interrupts. * * Designed to pulse width modulated an analog signal. * * by TDB; 28.11.2019 * ********************************************************/ #include #include "pwmWrite.h" #include "mainheader.h" extern pwmWrite OBJECT_NAME; /* --- Interrupt Handler --- */ void TC0_Handler() { TC0 -> TC_CHANNEL[0].TC_SR; // clear and read status register if(sampleNo == NUM_OF_SAMPLES) sampleNo = 0; // continous sample rotation OBJECT_NAME.duty(pwm_pin, signal_TC[sampleNo]); // write new duty cycle with value of sampleNo++; // go to next sample } void TC1_Handler() { TC0 -> TC_CHANNEL[1].TC_SR; // clear and read status register if(sampleNo == NUM_OF_SAMPLES) sampleNo = 0; // continous sample rotation OBJECT_NAME.duty(pwm_pin, signal_TC[sampleNo]); // write new duty cycle with value of sample sampleNo++; // go to next sample } void TC2_Handler() { TC0 -> TC_CHANNEL[2].TC_SR; // clear and read status register if(sampleNo == NUM_OF_SAMPLES) sampleNo = 0; // continous sample rotation OBJECT_NAME.duty(pwm_pin, signal_TC[sampleNo]); // write new duty cycle with value of sample sampleNo++; // go to next sample } /* --- TC3, TC4 and TC5 should never trigger through an pin, they are not wired and solely internal --- */ void TC3_Handler() { TC1 -> TC_CHANNEL[0].TC_SR; // clear and read status register if(sampleNo == NUM_OF_SAMPLES) sampleNo = 0; // continous sample rotation OBJECT_NAME.duty(pwm_pin, signal_TC[sampleNo]); // write new duty cycle with value of sample sampleNo++; // go to next sample } void TC4_Handler() { TC1 -> TC_CHANNEL[1].TC_SR; // clear and read status register if(sampleNo == NUM_OF_SAMPLES) sampleNo = 0; // continous sample rotation OBJECT_NAME.duty(pwm_pin, signal_TC[sampleNo]); // write new duty cycle with value of sample sampleNo++; // go to next sample } void TC5_Handler() { TC1 -> TC_CHANNEL[2].TC_SR; // clear and read status register if(sampleNo == NUM_OF_SAMPLES) sampleNo = 0; // continous sample rotation OBJECT_NAME.duty(pwm_pin, signal_TC[sampleNo]); // write new duty cycle with value of sample sampleNo++; // go to next sample } void TC6_Handler() { TC2 -> TC_CHANNEL[0].TC_SR; // clear and read status register if(sampleNo == NUM_OF_SAMPLES) sampleNo = 0; // continous sample rotation OBJECT_NAME.duty(pwm_pin, signal_TC[sampleNo]); // write new duty cycle with value of sample sampleNo++; // go to next sample } void TC7_Handler() { TC2 -> TC_CHANNEL[1].TC_SR; // clear and read status register if(sampleNo == NUM_OF_SAMPLES) sampleNo = 0; // continous sample rotation OBJECT_NAME.duty(pwm_pin, signal_TC[sampleNo]); // write new duty cycle with value of sample sampleNo++; // go to next sample } void TC8_Handler() { TC2 -> TC_CHANNEL[2].TC_SR; // clear and read status register if(sampleNo == NUM_OF_SAMPLES) sampleNo = 0; // continous sample rotation OBJECT_NAME.duty(pwm_pin, signal_TC[sampleNo]); // write new duty cycle with value of sample sampleNo++; // go to next sample }