PWM at least...
siljamicke
Posts: 66
Ok, at least a got what i wanted, PWM controlled with my darn good looking slider pot! So far, so good! However, i got the rather unintended pitchbend aswell
I use RCTIME to check my pot in the background. I call it from a routine that runs in the second cog (yes i am aware that running this simple thing in three cogs are somewhat of a waste, but it's only a simple test...) so that the timing of my music playing cog nr. 1 isn't gone, or so i thought. The position of the pot alters the pitch of the tone. Now is this due to the RCTIME running in cog 3, my homebrew debouncer or something else? I'm lost...
I have a 220 Ohm resistor connected to the pin (pin24) and a 100 nF cap. and 10K pot, if that has anything to do with anything, which i doubt though...
I would be most grateful for some tips, and general pointers aswell!
I use RCTIME to check my pot in the background. I call it from a routine that runs in the second cog (yes i am aware that running this simple thing in three cogs are somewhat of a waste, but it's only a simple test...) so that the timing of my music playing cog nr. 1 isn't gone, or so i thought. The position of the pot alters the pitch of the tone. Now is this due to the RCTIME running in cog 3, my homebrew debouncer or something else? I'm lost...
[COLOR="plum"]VAR long readerStack[16] long potValue byte PWM_counter byte PWM_restart[/COLOR] PUB PWMtest cognew (ReadPot(24,1,@potValue),@readerStack) [COLOR="green"]'I start this in a separate cog to avoid timing problems. 'Might this be where i do it all wrong?[/COLOR] dira[16..23]~~ PWM_restart:=255 repeat PWM_counter:=0 outa[23..16]:=%11111111 repeat PWM_counter++ while(PWM_counter < [COLOR="red"]potValue[/COLOR] or PWM_counter > 255) [COLOR="green"] ' The idea is to have ReadPot update potValue through RCTIME transparently to this cog ' so that a recent value is always at hand without disrupting this loop...[/COLOR] outa[16..23]:=%0000000 repeat PWM_counter++ while(PWM_counter < PWM_restart) [COLOR="plum"]OBJ rc :"RCTIME" VAR long potRead long oldPot long potDiff[/COLOR] PUB ReadPot(pin,state,retAddr) rc.start(24,1,@potRead) repeat [COLOR="green"]'Debounce the pot value...[/COLOR] potDiff:= potRead - oldPot if(potDiff<0) potDiff:=-potDiff if(potDiff>2) oldPot:=potRead long[retAddr]:=(oldPot >> 2) -25
I have a 220 Ohm resistor connected to the pin (pin24) and a 100 nF cap. and 10K pot, if that has anything to do with anything, which i doubt though...
I would be most grateful for some tips, and general pointers aswell!
Comments
It's late here in Sweden, so maybe if i try again tomorrow.
Take care!
while(PWM_counter < potValue or PWM_counter > 255)
should be,
while(PWM_counter < potValue)
and the byte bounds checking is done in ReadPot before passing back the value...
How silly Cheers
V
Some of my work
We have not so much snow but still irritating.
You can ask as many questions as You need to have all answers
PWM_counter is able to hold values larger than 255, then if potValue is larger than 255 the 2nd part of the while statement will execute, running more code, making it slower. If the first condition is satisfied, there's no need to run the 2nd part of the statement.
I'll keep that in mind!
To all:
I was only playing around with a pot, in my neverending quest to learn more about this black box o' magic!
However, i wonder about one thing, since i've moved on to new stupid attempts at other things, and had forgotten about my pot-problems (no, not the drug kind), how do i mark a thread as solved? I don't find that button...
I am doing something very similar to your friend...if you are feeling generous would you mind posting that code? My PASM is very poor...I need to work on that.