PULSOUT equivalent in SPIN -- translating PBASIC to SPIN
hipparchus
Posts: 9
Hello,
I'm trying to use the propeller chip to control a digital potentiometer to brighten and dim an LED.
I've done this with the BASICStamp but need to use the propeller chip for my project and was trying
to translate the schematic and program to be compatible with the propeller chip. I'm not even sure
if the digital potentiometer works with the propeller, but knowing the capability of these chips, I
would assume so.
Right now I've got almost exactly the same setup as the schematic on page 263 of
http://www.parallax.com/dl/docs/books/edu/wamv2_1.pdf (page 275 of the pdf file) with the
exception of pin 1 of the digital potentiometer being connected to P0 of the propeller chip and pin 2
connected to P1.
The program reads:
My (poor) attempt at making an equivalent program reads:
I've tried playing around with the waitcnt command to get a pulse of 2μs (what PULSOUT <pin>, 1 ends up being),
and eliminating the wait altogether I got quite the fancy strobe light (unfortunately, not what I'm trying to do).
I really feel like I have no idea what I'm doing so perhaps you all can help.
Now, I've only been working with the BASICStamp and Propeller chip for maybe a month,
and I'm pretty inexperienced in the grand scheme of things, so I ask of you to please be
forgiving of any gross misunderstandings I have of the way these parallax products work.
Please help!
Many thanks
Post Edited (hipparchus) : 6/15/2010 10:44:47 PM GMT
I'm trying to use the propeller chip to control a digital potentiometer to brighten and dim an LED.
I've done this with the BASICStamp but need to use the propeller chip for my project and was trying
to translate the schematic and program to be compatible with the propeller chip. I'm not even sure
if the digital potentiometer works with the propeller, but knowing the capability of these chips, I
would assume so.
Right now I've got almost exactly the same setup as the schematic on page 263 of
http://www.parallax.com/dl/docs/books/edu/wamv2_1.pdf (page 275 of the pdf file) with the
exception of pin 1 of the digital potentiometer being connected to P0 of the propeller chip and pin 2
connected to P1.
The program reads:
' What's a Microcontroller - DigitalPotUpDown.bs2 ' Sweep digital pot through values. ' {$STAMP BS2} ' {$PBASIC 2.5} counter VAR Byte DO LOW 5 FOR counter = 0 TO 127 PULSOUT 6, 1 PAUSE 10 NEXT HIGH 5 FOR counter = 0 TO 127 PULSOUT 6, 1 PAUSE 10 NEXT LOOP
My (poor) attempt at making an equivalent program reads:
'Light dimming with digital potentiometer ' CON potClkYel = 0 'potentiometer clock pulse pin for yellow light potDirYel = 1 'potentiometer U/D wiper direction pin for yellow light PUB MAIN dira[noparse][[/noparse]potClkYel] := 1 'make yellow potentiometer control pins outputs dira[noparse][[/noparse]potDirYel] := 1 outa[noparse][[/noparse]potClkYel] := 0 'initialize the clock pulse pin to low repeat outa[noparse][[/noparse]potDirYel] := 0 'U/D wiper receives high signal repeat 128 'pulse 128 times PULSOUT(potClkYel) outa[noparse][[/noparse]potDirYel] := 1 'U/D wiper receives low signal repeat 128 'pulse 128 times PULSOUT(potClkYel) PUB PULSOUT(pin) outa[noparse][[/noparse]pin] := 0 waitcnt(clkfreq*2/1000000) outa[noparse][[/noparse]pin] := 1 waitcnt(clkfreq*2/1000000) outa[noparse][[/noparse]pin] := 0
I've tried playing around with the waitcnt command to get a pulse of 2μs (what PULSOUT <pin>, 1 ends up being),
and eliminating the wait altogether I got quite the fancy strobe light (unfortunately, not what I'm trying to do).
I really feel like I have no idea what I'm doing so perhaps you all can help.
Now, I've only been working with the BASICStamp and Propeller chip for maybe a month,
and I'm pretty inexperienced in the grand scheme of things, so I ask of you to please be
forgiving of any gross misunderstandings I have of the way these parallax products work.
Please help!
Many thanks
Post Edited (hipparchus) : 6/15/2010 10:44:47 PM GMT
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon McPhalen
Hollywood, CA
But yes, to do exactly what you did in BASIC you need PASM speeds, but I think you would be able to get away with JonnyMac's suggestion.
BTW: EVERYTHING is compatible with the Propeller (of course that is an exaggeration), but we have methods to anything from full speed USB v1.1 to digipot ICs!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
April, 2008: when I discovered the answers to all my micro-computational-botherations!
Some of my objects:
MCP3X0X ADC Driver - Programmable Schmitt inputs, frequency reading, and more!
Simple Propeller-based Database - Making life easier and more readable for all your EEPROM storage needs.
String Manipulation Library - Don't allow strings to be the bane of the Propeller, bend them to your will!
Fast Inter-Propeller Comm - Fast communication between two propellers (1.37MB/s @100MHz)!
Jonathan
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
lonesock
Piranha are people too.
Might I suggest a little transitional product. There is an object in the OBEX called BS2 fuctions:
http://obex.parallax.com/objects/30/
It has many of the BS2 command that can be used in Spin applications.
Also there is PropBasic:
http://forums.parallax.com/showthread.php?p=867134
yet another avenue to use Basic style programs to yield PASM (Propeller Assembly Code), to get the fastest code to run on the Propeller.
Both of these might help you make the transition from Stamp to Propeller.
A lot of help here to make the transition.
Jim
works great
Post Edited (p00ndawg) : 6/16/2010 12:24:34 AM GMT
I think I would do something like this:
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon McPhalen
Hollywood, CA
In other words, why not use PWM?
I think I'll be able to figure something out with what you've all offered. I'll probably give that code a try too, dawg.
I originally tried this by using PWM and found it difficult to make the transition smooth from dark to light. I'll probably go back to that and compare methods but for now the main reason to try with the digital pot is to see if I can get it to work! All avenues must be explored.
---
EDIT:
Ahhh, propBASIC works perfectly! Thank you all for the help.
Post Edited (hipparchus) : 6/16/2010 1:37:55 PM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Shawn Lowe
When all else fails.....procrastinate!
If you're just using one or two LEDs you can employ the counters to take care of the PWM for you -- this will run full time and allow smooth transitions (unlike the BS2 and BS2 object PWM which does not run full time). If you want a whole bunch of LEDs you can write a background cog that takes care of it. I recently designed a 16-channel, DMX-controlled LED fixture (for Ethereal FX) that uses the latter strategy.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon McPhalen
Hollywood, CA
I'm using about 5 LEDs, so I'd have probably have to the latter. Unfortunately, I don't think I'm far enough along yet (skill-wise) to do that...
I'll have to do more reading. Thank you, though.
BTW... I explain my implementation of Bit Angle Modulation in this Nuts & Volts article:
-- www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp3.pdf
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon McPhalen
Hollywood, CA
Oh, cool! Thanks. I'll take a look at it and let you know if I end up using that method.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon McPhalen
Hollywood, CA
I should mention im using it in par with an msr1 and two hb25's.
Thanks for the help tho its really appreciated and I actually saw the bug in action. My robot got stuck in forward motion and never stopped.
I tried that as well and the wheels dont move at all with that, it however does move on to other parts of the code.
EDIT:
it does not seem to be recognizing the duration I was previously sending, because it is running the code.
could your code have changed which durations it recognizes? I was sending 1_600 for forward previously.
Post Edited (p00ndawg) : 6/17/2010 6:23:53 PM GMT