Last active
December 12, 2015 07:08
-
-
Save bnewbold/4734568 to your computer and use it in GitHub Desktop.
From http://code.google.com/p/leaflabs/issues/detail?id=7 Reported by Okie "PWM outputs are always zero on 0.0.8 on windows xp on my computer. everything is fine with 0.0.6."
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define AIN1 18 | |
#define AIN2 19 | |
#define AOUT1 6 | |
#define AOUT2 7 | |
#define POT1 16 | |
#define POT2 17 | |
#define SAMPLETIME 10 // in microseconds | |
#define KNOBSAMPLETIME 21 | |
#define SYSTICK_CSR 0xE000E010 | |
void createSample(void); | |
void measureKnobs(void); | |
uint16 comb(int signalin, int tap, int feedback); | |
uint16 knob1 = 0; | |
uint16 knob2 = 0; | |
uint16 signalin = 0; | |
uint16 signalout = 0; | |
int comb_index = 0; | |
uint16 outputbuffer[8192]; | |
void setup(){ | |
pinMode(AIN1, INPUT_ANALOG); | |
pinMode(AIN2, INPUT_ANALOG); | |
pinMode(AOUT1, PWM); | |
pinMode(AOUT2, PWM); | |
pinMode(POT1, INPUT_ANALOG); | |
pinMode(POT2, INPUT_ANALOG); | |
// PWM timers | |
Timer1.setPrescaleFactor(1); | |
Timer1.setOverflow(0x00FF); | |
// timer for I/0 measurement and calculation | |
Timer2.setChannel1Mode(TIMER_OUTPUTCOMPARE); | |
Timer2.setPeriod(SAMPLETIME); // in microseconds | |
Timer2.setCompare1(1); // overflow might be small | |
Timer2.attachCompare1Interrupt(createSample); | |
// timer for reading potentiometers | |
Timer3.setChannel1Mode(TIMER_OUTPUTCOMPARE); | |
Timer3.setPeriod(KNOBSAMPLETIME); // in microseconds | |
Timer3.setCompare1(1); // overflow might be small | |
Timer3.attachCompare1Interrupt(measureKnobs); | |
} | |
void loop(){ | |
} | |
void createSample(void){ | |
pwmWrite(AOUT1, (signalout)%256); | |
pwmWrite(AOUT2, (signalout)/256); | |
signalin = 0; | |
for(int i=0; i<8; i++){ | |
signalin = signalin + analogRead(AIN1) + analogRead(AIN2); | |
} | |
signalout = comb(signalin, knob1, knob2); | |
} | |
void measureKnobs(void){ | |
knob1 = analogRead(POT1); | |
knob2 = analogRead(POT2); | |
knob1 = knob1 + analogRead(POT1); | |
knob2 = knob2 + analogRead(POT2); | |
} | |
uint16 comb(int signalin, int tap, int feedback){ | |
outputbuffer[comb_index%8192] = (8192-feedback)*signalin/8192 + ((feedback-1)%8192)*outputbuffer[(comb_index+tap+1)%8192]/8192; | |
return outputbuffer[(comb_index++)%8192]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment