Shop OBEX P1 Docs P2 Docs Learn Events
Trying to learn all over again — Parallax Forums

Trying to learn all over again

TCTC Posts: 1,019
edited 2012-09-09 17:10 in Propeller 1
Hello all, it’s been a long time since I’ve been on here, or even messed with the “prop”. Well I’m trying to get back in the feel of things, and I need some help.

I’m trying to start off simple, but it’s not working. I want to control an Analog Devices “AD5220” variable resistor. There are only three pins it uses: Clock, Chip Select, and Up or Down. I’m trying to make it so the prop knows where to put the wiper when I change the wiper value.

For example: let’s say the “AD5220” wiper is sitting at 100, and an object wants the wiper to move to 30, the prop would know the new value is less than the previous setting, it then would move the wiper down to the new location.

I’ve included my code that I have now, I know it’s a little messy; I’m just trying to get back in the feel of things. I do want to make it better, but I need to get it working first.

My mind keeps drawing blanks on what I need to do, or what to look for. I could use any help right now.

Thanks All, TC
  VR_ChipSelect = 16              
  VR_UpDown     = 17
  VR_Clock      = 18

VAR

  byte  ContrastValue
  byte  Contrast
  byte  WiperPos

PUB init
  dira[VR_ChipSelect..VR_Clock] := %111
  outa[VR_ChipSelect..VR_Clock] := %111
  WiperPos := $40

PUB ContrastAddjust
    if Contrast <> WiperPos
      UPorDOWN

PRI UPorDOWN
  if Contrast > ContrastValue
    up
  else
    down             

PUB Up

  ContrastValue := 
  outa[VR_ChipSelect]           := 0
  Delay10
  outa[VR_UpDown]               := 0
  Delay10
  Clock



PUB Down

  outa[VR_ChipSelect]           := 0
  Delay10
  outa[VR_UpDown]               := 1
  Delay10
  Clock

PRI Clock
    repeat ContrastValue
      !outa[VR_Clock]
      Delay25
      !outa[VR_Clock]
      Delay25
      
  outa[VR_ChipSelect..VR_Clock] := %111  


PRI Delay25
  waitcnt(3_200_000 + cnt)

PRI Delay20
  waitcnt(4_000_000 + cnt)

PRI Delay10
  waitcnt(8_000_000 + cnt)

Comments

  • ElectricAyeElectricAye Posts: 4,561
    edited 2012-09-07 19:03
    How does Contrast ever get assigned a value?

    You need the CON block to assign your pins if you're going to do it the way you've written it.

    It might help if you try to compile your code and watch what warning signs pop up. The editor provides you with lots of help.

    I think you might have your Delay values mixed up.

    One simple way of getting your Propeller to "remember" where the wiper is (after power shut down, etc.) is to first run the wiper all the way to one extreme or the other, then clock it into place where you want it. If I remember correctly, you can give the wiper an excessive number of clock pulses, and once it reaches a limit, it will remain at that limit. So, in other words, you can give the wiper clock, say, 300 pulses in the down direction, and then you'll know it's pegged at the zero position to start with. From there, you can count up to whatever position your little heart desires.
  • TCTC Posts: 1,019
    edited 2012-09-08 05:24
    Thank you ElectricEye

    The Contrast value will be changed by another object that I have not got to yet.
    The CON block is there, I just forgot to put it on my post.
    I have compiled my code, and I’m not getting any errors.

    What I’m having trouble with is how to make the prop change the value to what I want it to be. On power up the AD5220 starts at wiper position $40 (the middle). I was going to make it go all the way down plus some, to make sure the wiper is in the correct position.

    Please excuse my vagueness, after my accident it is hard to think sometimes, but I can’t give up.
  • ElectricAyeElectricAye Posts: 4,561
    edited 2012-09-08 08:45
    TC wrote: »
    ...

    Please excuse my vagueness, after my accident it is hard to think sometimes, but I can’t give up.

    Yes, don't give up. You are definitely in the ballpark with your code. My suggestion is to break down the task into even smaller pieces, test each piece by itself along the way, and build upon your program block by block. The code you posted above suggests to me you were trying to bite off more than anyone could chew at one time.

    On power up, I always clocked my AD5220 all the way down to zero just to make sure some transients didn't cause the wiper to bounce off the previous position. I'm not sure that was necessary, but it made me feel better. Of course, you can only do that if your system can afford to have the AD5220 at zero and off your desired position for some fraction of a second on start-up.

    You might get more help in general if you tell people what your entire system is trying to accomplish. People here are usually helpful with code but it helps everyone to know what your actual goal is. There might be other ways to solve your problem, too.

    I'm not sure why you're using the $40 to indicate position. The Propeller is happy to work with plain integers, which might be easier to read later on.

    Have fun.
  • StefanL38StefanL38 Posts: 2,292
    edited 2012-09-08 11:07
    Hi TC,

    I recommend too to code some small pieces and test each piece on its own.
    first piece would be to code a test PRG that does nothing else but the bit-banging to change the wiper-position.

    set chipselect low
    set UP/Down-Pin low (to decrement resistor value towards 0 Ohm (= twords Terminal B GND )
    toggle clock high-low-high for 128 times to make sure wiper is at 0 Ohm

    set UP/Down-Pin High (to increment resistor value towards max Ohm (= twords Terminal B GND )

    toggle clock high-low-high for 20 times.

    then measure voltage at wiper-terminal

    repeating the test with toggle clock high-low-high for 40 times, 64 times, etc.

    if this is working go on coding a method that changes wiper-position to a ceratin value.
    For this you have to have a variable that contains the actual wiper-position

    then the number of clock-toggles is the difference between actual_wiper_pos to new_wiper_pos
    the sign of the difference determines of input Up/down has to be high or low

    best regards
    Stefan
  • TCTC Posts: 1,019
    edited 2012-09-09 16:25
    Thank you ElectricEye and Stefan. I see I was trying to start to big, that is a problem I have to work on. I have trouble seeing the little things, when the big picture is in my head. Just so you know what I plan to do is a project I started a while back, but had to get put on the back burner. I am making a smart power supply, which uses a computer power supply. I want it to tell me the voltage and the current of the 3.3V, 5V, and the 12V rails. I want to start with the display (4x16) that I have laying around, and the AD5220 is the contrast adjustment.

    Thanks
    TC
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2012-09-09 16:54
    TC wrote: »
    Thank you ElectricEye and Stefan. I see I was trying to start to big, that is a problem I have to work on. I have trouble seeing the little things, when the big picture is in my head. Just so you know what I plan to do is a project I started a while back, but had to get put on the back burner. I am making a smart power supply, which uses a computer power supply. I want it to tell me the voltage and the current of the 3.3V, 5V, and the 12V rails. I want to start with the display (4x16) that I have laying around, and the AD5220 is the contrast adjustment.

    Thanks
    TC
    Sorry to throw a spanner in the works but...
    If you simply want software controlled contrast for a standard character LCD and standard temperature then you could just use an RC filter from the Prop to the contrast pin. I use 220 ohms and 0.1uf to filter the output of a counter in duty cycle mode. What you end up with is a voltage from 0 to 3.3V but of course only the lower voltage range is needed. The contrast pin doesn't really NEED a resistance, it needs a voltage. I've used this technique in many many products for many many years.
    pub contrast(n)                 ' 00..$7F
      dira[cont]~~
      ctra := %00110<<26 + cont
      frqa := n<<25
    
  • TCTC Posts: 1,019
    edited 2012-09-09 17:10
    Thank you Peter, I might check that out. I was just planning on using the AD5220 because it has been sitting around, and I need to use it.
Sign In or Register to comment.