dazedandconfused
New Member
Having just finished an eight week university project using the PICAXE (they're just so easy to use it feels like cheating), I am trying to use my aquired knowledge to create something closer to my heart - a b*tchin' synthesiser.
The idea is to use the PWMOUT command to create musical scales, with the data for the PWM stored in EEPROM (Or a table depending on which turns out to simplify the code).
Here is what I am working with so far: A 10k pot on pin 4 using readadc10 to give me plenty of resolution for changing notes. This is then split by an if statement to match it to a note, which is read from EEPROM into two variables - period and duty.
This looks real messy to me, especially as I am only using 11 pitches at the moment, I'd rather use a different technique for when I'm using 4 octaves. Would it work if I split the program into parallel tasks - one constantly checking to see if the ADC has increased, using a difference instead of thresholds. eg
This obviously won't work for negative values, which I don't quite comprehend how to work in PICAXE, unless some has divised a way to use twos complement.
Second problem: When the pitch values change too much, the PWMDIV changes, which is hard to change. Can I store the PWMDIV in a variable? This is being extremely hopeful, mayb ASCII in a word var?
Of course, if someone could help me with getting a negative pitch solution for the second code snippet, another threshold could be used for switching between subroutines that use different PWMDIV.
Apologies for the mess, this idea is still forming in my head.
PS. What is pretty cool about the current coding is that due to the ADC fluctuating due to circuit noise, you can set the note in between notes where it creates a sort of random grimey mess.
EDIT: I tried this, and it works with a few adjustments:
The only problem with this is it makes terrible use of the pot, it reaches the frequency limits before the pot is near the edges, and does the same back which just makes it frustrating. To get this to work i would need something more like a rotary encode moving the pointer in the EEPROM.
Any suggestions to replace the large IF statement?
The idea is to use the PWMOUT command to create musical scales, with the data for the PWM stored in EEPROM (Or a table depending on which turns out to simplify the code).
Here is what I am working with so far: A 10k pot on pin 4 using readadc10 to give me plenty of resolution for changing notes. This is then split by an if statement to match it to a note, which is read from EEPROM into two variables - period and duty.
Code:
eeprom 0,(238, 222, 224,195, 212, 170, 199, 146, 188, 124, 178, 102, 168, 83, 158, 64, 149, 45, 141, 29, 133, 13)
symbol pot1=4
symbol freq1=w0
symbol period=b2
symbol duty=w2
main:
readadc10 pot1,freq1
if freq1<93 then
read 0,period
read 1,duty
elseif freq1<186 then
read 2,period
read 3,duty
elseif freq1<279 then
read 4,period
read 5,duty
elseif freq1<372 then
read 6,period
read 7,duty
elseif freq1<465 then
read 8,period
read 9,duty
elseif freq1<558 then
read 10,period
read 11,duty
elseif freq1<651 then
read 12,period
read 13,duty
elseif freq1<743 then
read 14,period
read 15,duty
elseif freq1<836 then
read 16,period
read 17,duty
elseif freq1<929 then
read 18,period
read 19,duty
elseif freq1>929 then
read 20,period
read 21,duty
endif
duty=duty+255
pwmout pwmdiv16, 2, period, duty
goto main
end
Code:
readadc 4, b0
pauseus (whatever the smallest increment I can use is)
readadc 4, b1
if b0>b1 then
b2=b0-b1
elseif b1>b0
b2=b1-b0
endif
if b2>threshold then
goto increase pitch
Second problem: When the pitch values change too much, the PWMDIV changes, which is hard to change. Can I store the PWMDIV in a variable? This is being extremely hopeful, mayb ASCII in a word var?
Of course, if someone could help me with getting a negative pitch solution for the second code snippet, another threshold could be used for switching between subroutines that use different PWMDIV.
Apologies for the mess, this idea is still forming in my head.
PS. What is pretty cool about the current coding is that due to the ADC fluctuating due to circuit noise, you can set the note in between notes where it creates a sort of random grimey mess.
EDIT: I tried this, and it works with a few adjustments:
Code:
readadc pot1,adc1
pauseus 5000
readadc pot1,adc2
if adc1>adc2 then
rd=rd-2 min 0 max 22
elseif adc1<adc2 then
rd=rd+2 max 22
endif
Any suggestions to replace the large IF statement?
Last edited: