This is a part of the Kinetiszer project.

Dependencies:   inc

Dependents:   kinetisizer

Committer:
Clemo
Date:
Tue Oct 28 12:19:42 2014 +0000
Revision:
0:cb80470434eb
Error & warning free.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Clemo 0:cb80470434eb 1 /*
Clemo 0:cb80470434eb 2 Copyright 2013 Paul Soulsby www.soulsbysynths.com
Clemo 0:cb80470434eb 3 This file is part of Atmegatron.
Clemo 0:cb80470434eb 4
Clemo 0:cb80470434eb 5 Atmegatron is free software: you can redistribute it and/or modify
Clemo 0:cb80470434eb 6 it under the terms of the GNU General Public License as published by
Clemo 0:cb80470434eb 7 the Free Software Foundation, either version 3 of the License, or
Clemo 0:cb80470434eb 8 (at your option) any later version.
Clemo 0:cb80470434eb 9
Clemo 0:cb80470434eb 10 Atmegatron is distributed in the hope that it will be useful,
Clemo 0:cb80470434eb 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
Clemo 0:cb80470434eb 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Clemo 0:cb80470434eb 13 GNU General Public License for more details.
Clemo 0:cb80470434eb 14
Clemo 0:cb80470434eb 15 You should have received a copy of the GNU General Public License
Clemo 0:cb80470434eb 16 along with Atmegatron. If not, see <http://www.gnu.org/licenses/>.
Clemo 0:cb80470434eb 17 */
Clemo 0:cb80470434eb 18
Clemo 0:cb80470434eb 19 //*****Pulse Width Modulation. This sets a portion of the waveform to 0. The amount of the waveform blanked is set by the LFO and LFO amount******
Clemo 0:cb80470434eb 20
Clemo 0:cb80470434eb 21 #include "atmegatron.h"
Clemo 0:cb80470434eb 22
Clemo 0:cb80470434eb 23 //lets and gets
Clemo 0:cb80470434eb 24 byte pwm_lfoamt = 0;
Clemo 0:cb80470434eb 25 //LFO amount - stored as byte 0-31. represents the maximum proportion of waveform that can be blanked.
Clemo 0:cb80470434eb 26 void PWM_Let_LFOAmt(byte newamt)
Clemo 0:cb80470434eb 27 {
Clemo 0:cb80470434eb 28 pwm_lfoamt = newamt;
Clemo 0:cb80470434eb 29 }
Clemo 0:cb80470434eb 30
Clemo 0:cb80470434eb 31
Clemo 0:cb80470434eb 32 byte PWM_Get_LFOAmt(void)
Clemo 0:cb80470434eb 33 {
Clemo 0:cb80470434eb 34 return pwm_lfoamt;
Clemo 0:cb80470434eb 35 }
Clemo 0:cb80470434eb 36
Clemo 0:cb80470434eb 37 //PWM meat
Clemo 0:cb80470434eb 38 void PWM_Process(void)
Clemo 0:cb80470434eb 39 {
Clemo 0:cb80470434eb 40 byte i;
Clemo 0:cb80470434eb 41 long curindex, maxindex;
Clemo 0:cb80470434eb 42 if (pwm_lfoamt > 0) { //pwm on:
Clemo 0:cb80470434eb 43 maxindex = (WAVE_LEN - pwm_lfoamt); //intermediate value - min possible index to start blanking
Clemo 0:cb80470434eb 44 curindex = ((127 - LFO_Get_Level()) * (long)pwm_lfoamt * 8225 >> 21) + maxindex; //then multiply by lfo level (8225 >> 21 is a way of doing / 255, without using a slow divide)
Clemo 0:cb80470434eb 45 for(i=curindex;i<WAVE_LEN;i++){ //blank the relevant part of the waveform
Clemo 0:cb80470434eb 46 Wave_Let_Process(i, 0);
Clemo 0:cb80470434eb 47 }
Clemo 0:cb80470434eb 48 }
Clemo 0:cb80470434eb 49 }