Using a potentiometer to control LED blink rate
wirecutter
Posts: 22
Hello,
I need help with Using a potentiometer to control LED blink rate.
I am using RCTime from the OBEX to get a RCValue variable. here is the code I am using to blink the LED. I have the RCValue set at 300 this is the target when the pot is at center. I am using a 10K pot with a .1uf cap, and on P5.
The question is how do I convert the RCValue given in RCTime (in RCTime foreground demo, that states at ''R = 10K you get 4_000", ''and at R = 4.7K you get 1_800") to work in the "wait" method?
thanks
RCTIME_foreground_DEMO - Archive [Date 2011.02.11 Time 13.02].zip
I need help with Using a potentiometer to control LED blink rate.
I am using RCTime from the OBEX to get a RCValue variable. here is the code I am using to blink the LED. I have the RCValue set at 300 this is the target when the pot is at center. I am using a 10K pot with a .1uf cap, and on P5.
The question is how do I convert the RCValue given in RCTime (in RCTime foreground demo, that states at ''R = 10K you get 4_000", ''and at R = 4.7K you get 1_800") to work in the "wait" method?
_clkmode = xtal1 + pll2x
_xinfreq = 5_000_000
pin = 27
RCValue = 300
high = 1
low = 0
Pub Go
dira[pin]~~
repeat
turnOn_LED
wait
turnOff_LED
wait
Pri turnOn_LED
outa[pin] := high
Pri turnOff_LED
outa[pin] := low
Pri wait
waitCnt((CLKfreq/1000)*RCValue +cnt)
thanks
RCTIME_foreground_DEMO - Archive [Date 2011.02.11 Time 13.02].zip
Comments
from a quick look at what you have coded the principle should work.
But you should use a RC-time backround-code.
The RC-time foreground needs some time to execute the RCTIME-command itself.
I have not done a calculation of the charge and discharge-times but this might be the reason why it does not work.
If measuring the rc-time runs in its own cog you can use the code that you have posted above.
My sugestion is: do a little bit more "homework" to learn about how rctime works and make a first try on your own.
If you just want to blink an LED and do nothing else a propeller-chip is really oversised. Except you are just tinkering around to get more familiar with the propeller and his possabilities.
For just blinking an LED take an NE555-chip and some external components.
best regards
Stefan
This is a sample code that I am using to learn about the waitCnt((CLKfreq/1000)*RCValue +cnt) method.
This operation is part of a on going learning and project.
when I run the code and the primary value of RCValue is 300, and when the RCTime is run to update RCValue, the LED just stays on, I think its because it was running to fast.
But I will need to figure out the math. The only part of the code that was attached in the previous post that will be used in the project is RCTime.spin to get the RCValue variable and will be run in a new cog.
thanks
Perhaps the call to RCTime.RCTime is not returning because your RC circuit is wired incorrectly or you are calling RCTime with the wrong state parameter. Perhaps try printing out the values that RCTime is yielding.
Cylon project - Archive [Date 2011.02.11 Time 19.26].zip
So, try this: waitcnt( 400 + RCValue + cnt )
...and you always put cnt last, so it's the last thing that gets added in, and therefore is as "current" as possible.
Jason
Good Luck
It looks like I got the "waitCnt((CLKfreq/1000)*RCValue +cnt)" working in my project code. Now I just need to incorporate the RCTime_forever method into it to update the RCValue.
I have been studying RCTIME3 and am I correct that P0 is the pin to connect the pot and called "apin" in the DAT section?
Cylon project_wirecutter - Archive.zip
I have the project working, I think, but I am have timing issues using RCTime3. I am watching the values in PST and found the rctime value is over double what I need and is causing the project to go nuts. could someone tell me where I need to look to correct this?
I need rctime to equal 1800 when the pot is set at 5K, currently I see its over 3800.
thanks,
Cylon project.zip
best regards
Stefan
If you want to reduce the value, you can do it a couple ways:
1) In hardware, use a smaller capacitor. It'll hold less charge and won't take as long to discharge.
2) In software, reduce the length of time you charge the cap for. If you don't fully charge it, it'll take less time to discharge.
3) In software, just reduce the number using division. 3800 / 2 = 1900, which is close to what you want, and simple. If you want -exact-, you need to use fixed or floating point math. Fixed point math using 8 bits of precision would look like this:
Result := (rcTimeValue * 121) / 256 ' 121 = 256 / 2.1111
Thanks, JasonDorie , the division worked after I found where to put it in the project.
A big thank you to everyone for the help.
wirecutter