Shop OBEX P1 Docs P2 Docs Learn Events
Digital Potentiometer ? — Parallax Forums

Digital Potentiometer ?

MrScuitoMrScuito Posts: 6
edited 2012-01-02 10:03 in BASIC Stamp
I'm very new to BS2 programming I just got the BS2 homework board today to practice the circuit and code on. Anyhow, this is what I'm trying to do. I'm planning on building a LED fixture for my reef tank in the next couple of months and I would like to include a digital pot to simulate dawn to dusk cycle. Once I can (if I can) get it to work on the HWB I will scale it up and make a proper board.

Goal:
Lights begin to come on 8am slowly becoming brighter till 11am hold there till 1pm then slowly dim till off at 8pm then repeat next day and so on

What I have done:
Built digi pot on page 268 of Whats a Microcontroller ran code on that page including LOOP at the end of the code. but it cycles only once and stops. I've played with the code a bit and tried TOGGLE but still no continues cycle.

Is it possible to use the BS2 to accomplish my goal. Great with hardware never been good with software.

can anybody point me to a sample code that would give me a continueous cycle I can prob monkey with timing to get it to take 12hrs to complete cycle if I can get it too cycle.

Comments

  • bsnutbsnut Posts: 521
    edited 2011-12-29 02:38
    Is it possible to use the BS2 to accomplish my goal.
    Yes, it can handle it with no problems. But, do you need all that I/O? The BS1 can handle what you need to do with no problems as well.

    The code that is shown in the Homework board book is basic test code to show how the digital potentiometer works. What you also need to remember is the digital potentiometer is designed to go so many steps in one direction or another.
    can anybody point me to a sample code that would give me a continueous cycle I can prob monkey with timing to get it to take 12hrs to complete cycle if I can get it too cycle.
    I can give you some code if no one does it first.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2011-12-29 07:27
    Digital potentiometers can be very handy in some situations, but they are also very low power devices. You haven't specified one, but take a close look at the PDF sheet of specifications for whatever you might choose. I'd rather use a digital potentiometer to control gain or output of an OpAmp IC than to control something like lighting.

    So if you want to control lighting, that device may not directly be able to handle the power - you might have to put a transistor or some other power amplifying device in between. And if you have to use a transistor, or mosfet; it might just be easier to let the Stamp create a Pulse Width Modulated signal to do all the work.

    Much depends on how many lights you want to use. The potentiometer might work well with just one; but burn up with many.
  • MrScuitoMrScuito Posts: 6
    edited 2011-12-29 07:49
    Yes, it can handle it with no problems. But, do you need all that I/O? The BS1 can handle what you need to do with no problems as well.

    I was able to pick up an unopened BS2 homework board kit at a yard sale for a buck, thats why I'm using it for my test bed

    So if you want to control lighting, that device may not directly be able to handle the power - you might have to put a transistor or some other power amplifying device in between. And if you have to use a transistor, or mosfet; it might just be easier to let the Stamp create a Pulse Width Modulated signal to do all the work.

    I assumed that once the idea was worked out on the HWB and running one 1w led thru the cycle wanted that the idea could then be ramped up on another more permenent board. Ultimately I want to dimm 24 3w HP LEDs
  • ercoerco Posts: 20,256
    edited 2011-12-29 09:12
    MrScuito wrote: »
    I was able to pick up an unopened BS2 homework board kit at a yard sale for a buck, thats why I'm using it for my test bed

    SCORE! Who says a buck doesn't buy much any more?
  • bsnutbsnut Posts: 521
    edited 2011-12-29 23:15
    That's a good deal. Did it come with the book? If it didn't come with the book, you download it from this link
    http://www.parallax.com/Portals/0/Downloads/docs/prod/edu/28123-WAM-v3.0.pdf
    on the Parallax site for free.
  • bsnutbsnut Posts: 521
    edited 2011-12-30 06:26
    Here's is the test code from the What’s a Microcontroller? book (page 277) and the PDF (page 299) to get you started, so you can test the digital potentiometer. It uses the debug terminal to do two things
    1) Set the tap setting from the computer keyboard. Make sure to press enter key after you entered a new tap setting value.
    2) Show the tap setting in the debug terminal for what you entered.
    ' -----[ Title ]-----------------------------------------------------------
    ' What's a Microcontroller - TerminalControlledDigitalPot.bs2
    ' Update digital pot's tap based on Debug Terminal user input.
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    ' -----[ EEPROM Data ]-----------------------------------------------------
    
    
    ' -----[ I/O Definitions ]-------------------------------------------------
    
    UdPin           PIN   5         ' Set values of I/O pins
    ClkPin          PIN   6         ' connected to CLK and U/D
    
    ' -----[ Constants ]-------------------------------------------------------
    
    DelayPulses     CON   10        ' Delay to observe LED fade.
    DelayReader     CON   2000
    
    ' -----[ Variables ]-------------------------------------------------------
    
    counter         VAR   Byte      ' Counter for FOR...NEXT.
    oldTapSetting   VAR   Byte      ' Previous tap setting.
    newTapSetting   VAR   Byte      ' New tap setting.
    
    ' -----[ Initialization ]--------------------------------------------------
    
      oldTapSetting = 0             ' Initialize new and old
      newTapSetting = 0             ' tap settings to zero.
      LOW UdPin                     ' Set U/D pin for Down.
      FOR counter = 0 TO 127        ' Set tap to lowest position.
        PULSOUT 6,5
        PAUSE 1
      NEXT
      PAUSE 1000                    ' Wait 1 s before 1st message
    
    ' -----[ Main Routine ]----------------------------------------------------
    
      DO
        GOSUB Get_New_Tap_Setting   ' User display and get input.
        GOSUB Set_Ud_Pin            ' Set U/D pin for up/down.
        GOSUB Pulse_Clk_pin         ' Deliver pulses.
      LOOP
    
    ' -----[ Subroutines ]-----------------------------------------------------
    Get_New_Tap_Setting:             ' Display instructions and
                                     ' get user input for new
      DEBUG CLS, "Tap setting is: ", ' tap setting value.
      DEC newTapSetting, CR, CR
      DEBUG "Enter new tap", CR, "setting (0 TO 127): "
      DEBUGIN DEC newTapSetting
    RETURN
    
    Set_Ud_Pin:                              ' Examine new and old tap values
                                             ' to decide value of U/D pin.
      IF newTapSetting > oldTapSetting THEN  ' Notify user if values are
        HIGH UdPin                           ' equal.
        oldTapSetting = oldTapSetting + 1    ' Increment for Pulse_Clk_pin.
      ELSEIF newTapSetting < oldTapSetting THEN
        LOW UdPin
        oldTapSetting = oldTapSetting - 1    ' Decrement for Pulse_Clk_pin.
      ELSE
      DEBUG CR, "New and old settings", CR,
                "are the same, try ", CR,
                "again...", CR
      PAUSE DelayReader                      ' Give reader time to view
      ENDIF                                  ' Message.
    RETURN
    
    Pulse_Clk_pin:
    ' Deliver pulses from old to new values. Keep in mind that Set_Ud_Pin
    ' adjusted the value of oldTapSetting toward newTapSetting by one.
    ' This keeps the FOR...NEXT loop from executing one too many times.
      FOR counter = oldTapSetting TO newTapSetting
        PULSOUT ClkPin, 1
        PAUSE DelayPulses
      NEXT
      oldTapSetting = newTapSetting         ' Keep track of new and old
                                            ' tapSetting values.
      RETURN
    
    I also suggest you build the circuit that is shown in the What’s a Microcontroller? book (page 267) and PDF (Page 294) and circuit will be the bases for your design. As you finalize your design, I would suggest you use TIP120 transistor which can handle the LED load that you are planning on.

    I will be working on final program code for you and hope to have it finished no later than Saturday morning.
  • MrScuitoMrScuito Posts: 6
    edited 2011-12-30 09:16
    @ bsnut thanks for your help. The kit did come with the book. I think I missed pg. 277 when I was reading through it. Here is a link to the DIY LED kit I think I will be getting. http://www.aquastyleonline.com/products/Aquarium-24--LEDs--DIY-Dimmable-Kit.html as you can see it comes with analog pots. but I want to replace them with programable digi pots (I dont want to stand next to my tank turning knobs all day!) and being a DIYer or as my wife says a cheapskate I really want to build it myself. I will however gladly accept any ideas on programming or curcit design. I can follow directions very well.
  • damage31damage31 Posts: 21
    edited 2011-12-30 15:38
    Hello- I am familiar with your needs, as I have already built what you aspire to build.

    There are several ways to achieve what you want to do, but something you will want to consider first: What kind of LED drivers are you going to use, and what are their dimming circuit requirements. (EDIT: I see you posted the kit you plan on buying, but i don't see the specs for what the dimming requirement is exactly, all it says is to use a pot...There's more info needed to know what to do- After reading some posts from some other people about this kit, it appears the kit comes with 22ohm pots for dimming, and several users indicate that these drivers are NOT microcontroller compatible.... I would suggest maybe thinking about using the meanwells...)



    Some drivers need a 0-10v analog signal, and others need a 5v Pulse Width Modulation (PWM) signal. Depending on which type of driver you use, you may or may not need the digital pot at all.

    What I found as i looked at the specs on the led drivers dimming circuit for the drivers I was going to use is that they appeared that they would need more current than just about any of the digital pots I could find could handle. (needed ~2ma, and it was hard to find a digital pot that can handle this amount of current)


    One other thing to note is that LED's will not dim to 0% on any driver that I am aware of. Usually, all you can get is down to ~10%-15% as the minimum brightness before the LEDs cut out. And on my tank, that level of brightness is actually fairly bright even on the low end. I wish there was more control, but my particular build is made up of 24 3watt Cree's driven by three Thomas Research Drivers.(two blue 700ma drivers, and one 1050ma driver for the whites) Thomas Research Drivers need 0-10v analog. (same as Meanwells, and a few others)



    So what i settled on initially was to use 3 digital pots + 3 741 op-amps configured with a gain of 2 to be the digital pots buffer on the output, to allow me to get 0-10v out of a 0-5v digital pot signal. This however required me to have 2 different power supplies- a 5v + a +12v (as there is some loss on the op amp from what I could see when prototyping the circuit) + other misc items (resistors, cap's, wires, etc) to make this happen, The chip count really started to increase as i needed to do 3 of these for my build.



    A little while later, as I researched my build, I bumped into a little talked about item - the LTC1257.
    This little beauty had several things going for it:
    #1 it can go up to ~15v.
    #2 it can source up to 2ma of current.
    #3 it is a 12bit ADC which gives 4095 steps of resolution on the output.
    #4 you can daisy chain them together.

    The price however, is a bit steep: ~$8.00 each. ouch. I defrayed this somewhat by asking for 2 samples... and buying one from digikey.

    However, this was considered reasonable for me because of the other circuit parts reduction + lack of complexity in implementing the circuit design using the basic stamp made for an easy trade off in my mind.
  • MrScuitoMrScuito Posts: 6
    edited 2011-12-30 18:58
    @damage31 did you happen to document your LED build? I would love to see how you did yours. I know the meanwells have a 0-10v analog and is sold by the place I am looking at getting my LEDs from for near the same price I may be able to get them instead. I figured for the price of the kit I couldnt go wrong.
  • damage31damage31 Posts: 21
    edited 2011-12-30 20:17
    I have a question thread here somewhere, and I have another one over on nano-reef here .


    The kit you are looking at doesn't seem too shabby overall, but the drivers that you were indicating you were going to use are of unknown origin, and also have no data sheet.

    Which is why I would consider simply altering the LED driver choice, to get something (such as the meanwell D or P drivers) that is more supported out in the communities such as reef central, or nano reef. Meanwell, Buckpucks, Inventronics seem popular. It appears that the Inventronics are very similar to teh Thomas Research drivers in that they have a self supplied dimmer voltage output

    Note: the meanwell D drivers need a 0-10v analog signal, and the P drivers are PWM if i remember correctly. The problem with the meanwells is that they need to be adjusted out of the gate for current and also need an external source for the dimmer voltage. Thats why I went with the Thomas Research Drivers when nanotuners was still around. less fuss and no muss. I like to follow the KISS principle even if it costs a couple bucks more overall.


    There are several ways to get PWM if needed based on the driver choice that you make- but the Stamp is not really one of the best ways (but it can be done), I would consider using external circuits to provide a constant PWM signal, as the stamp doesn't really have a way to constantly output a nice PWM signal all the time like what you will need if you went with a PWM driver. And use the stamp to control the PWM generator if you go that route.
  • bsnutbsnut Posts: 521
    edited 2011-12-31 02:21
    Here's your program. So, let me know how it works when you test it. Since, I did get a chance to test it.
    ' =========================================================================
    '
    '   File......timer_controlled_led_dimmer.bs2
    '   Purpose...
    '   Author....
    '   E-mail....
    '   Started...
    '   Updated...
    '
    '   {$STAMP BS2}
    '   {$PBASIC 2.5}
    '
    ' =========================================================================
    
    
    ' -----[ Program Description ]---------------------------------------------
    'Lights begin to come on 8am slowly becoming brighter till 11am hold there
    'till 1pm then slowly dim till off at 8pm then repeat next day and so on
    
    ' -----[ Revision History ]------------------------------------------------
    
    
    ' -----[ I/O Definitions ]-------------------------------------------------
    
    UdPin           PIN   5         ' Set values of I/O pins
    ClkPin          PIN   6         ' connected to CLK and U/D
    
    
    ' -----[ Constants ]-------------------------------------------------------
    
    IsOn            CON   1         ' for active-high in/out
    IsOff           CON   0
    DelayPulses     CON   10        ' Delay to observe LED fade.
    DelayReader     CON   2000      ' Pause delay setting
    
    
    
    ' -----[ Variables ]-------------------------------------------------------
    
    hours           VAR   Byte      ' Stores hours
    minutes         VAR   Byte      ' Stores minutes
    seconds         VAR   Byte      ' Stores seconds
    counter         VAR   Byte      ' Counter for FOR...NEXT.
    oldTapSetting   VAR   Byte      ' Previous tap setting.
    newTapSetting   VAR   Byte      ' New tap setting.
    
    ' -----[ Initialization ]--------------------------------------------------
    
    Reset:
      oldTapSetting = 0             ' Initialize new and old
      newTapSetting = 0             ' tap settings to zero.
      LOW UdPin                     ' Set U/D pin for Down.
      FOR counter = 0 TO 127        ' Set tap to lowest position.
        PULSOUT 6,5
        PAUSE 1
      NEXT
    
    
    ' -----[ Program Code ]----------------------------------------------------
    
    Main:
      DO
    ' Calculate hours, minutes, seconds
        IF seconds = 60 THEN seconds = 0: minutes = minutes + 1
        IF minutes = 60 THEN minutes = 0: hours = hours + 1
        IF hours = 24 THEN hours = 0
        IF hours = 7 AND seconds = 59 THEN newTapSetting = 1      'starting tap setting
        IF hours = 8 AND seconds = 0 THEN GOSUB Set_Dimming_Direction
        IF hours = 9 AND seconds = 0 THEN GOSUB Set_Dimming_Direction
        IF hours = 10 AND seconds = 0 THEN GOSUB Set_Dimming_Direction
        IF hours = 11 AND seconds = 0 THEN GOSUB Set_Dimming_Direction:
        IF hours = 11 AND seconds = 1 THEN oldTapSetting = 99
        IF hours = 13 AND seconds = 0 THEN GOSUB Set_Dimming_Direction
        IF hours = 14 AND seconds = 0 THEN GOSUB Set_Dimming_Direction
        IF hours = 15 AND seconds = 0 THEN GOSUB Set_Dimming_Direction
        IF hours = 16 AND seconds = 0 THEN GOSUB Set_Dimming_Direction
        IF hours = 17 AND seconds = 0 THEN GOSUB Set_Dimming_Direction
        IF hours = 18 AND seconds = 0 THEN GOSUB Set_Dimming_Direction
        IF hours = 19 AND seconds = 0 THEN GOSUB Set_Dimming_Direction
        IF hours = 20 AND seconds = 0 THEN GOSUB Set_Dimming_Direction
        PAUSE 991                                 ' Pause + overhead ~ 1 second
        seconds = seconds + 1                     ' Increment second counter
    
      LOOP
    
    ' -----[ Subroutines ]-----------------------------------------------------
    
    Set_Dimming_Direction:                   ' Examine new and old tap values
                                             ' to decide value of U/D pin.
      IF newTapSetting > oldTapSetting THEN  ' Notify user if values are
        HIGH UdPin                           ' equal.
        oldTapSetting = oldTapSetting + 25    ' Increment for Pulse_Clk_pin.
      ELSEIF newTapSetting < oldTapSetting THEN
        LOW UdPin
        oldTapSetting = oldTapSetting - 15    ' Decrement for Pulse_Clk_pin.
      ENDIF
    
    Pulse_Clk_pin:
    ' Deliver pulses from old to new values. Keep in mind that Set_Ud_Pin
    ' adjusted the value of oldTapSetting toward newTapSetting by one.
    ' This keeps the FOR...NEXT loop from executing one too many times.
      FOR counter = oldTapSetting TO newTapSetting
        PULSOUT ClkPin, 1
        PAUSE DelayPulses
      NEXT
      oldTapSetting = newTapSetting         ' Keep track of new and old
                                            ' tapSetting values.
      RETURN
    
    
    ' -----[ User Data ]-------------------------------------------------------
    
  • bsnutbsnut Posts: 521
    edited 2011-12-31 07:27
    I noticed that I made minor mistake with your program code. This was the mistake which will cause the program not to increment up the variable "newTapSetting".
    newTapSetting = 1
    
    Which needs to do be like this
    IF hours = 7 AND seconds = 59 THEN newTapSetting = 1
    
  • MrScuitoMrScuito Posts: 6
    edited 2012-01-01 11:42
    I see Code:

    newTapSetting = 0

    but not

    newTapSetting = 1

    and code:

    IF hours = 7 AND seconds = 59 THEN newTapSetting = 1

    is already present so, I'm not sure where to make the change. Sorry I'm only on day 3 of my self teaching lesson in basic. Thanks again for taking the time to help me out.
  • bsnutbsnut Posts: 521
    edited 2012-01-02 09:25
    Take a look at the program code and you noticed that I had edited it. So, therefore you will not need to do nothing except copy and paste into your editor and download it into your basic stamp.
  • MrScuitoMrScuito Posts: 6
    edited 2012-01-02 10:03
    oh ok thanks
Sign In or Register to comment.