Trying to learn all over again
TC
Posts: 1,019
Hello all, its been a long time since Ive been on here, or even messed with the prop. Well Im trying to get back in the feel of things, and I need some help.
Im trying to start off simple, but its 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. Im trying to make it so the prop knows where to put the wiper when I change the wiper value.
For example: lets 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.
Ive included my code that I have now, I know its a little messy; Im 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
Im trying to start off simple, but its 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. Im trying to make it so the prop knows where to put the wiper when I change the wiper value.
For example: lets 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.
Ive included my code that I have now, I know its a little messy; Im 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)
pdf
674K
Comments
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.
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.
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.
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
Thanks
TC
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.