Smart pins as level shifter?
Alsowolfman
Posts: 65
in Propeller 2
I am hoping to use the smart pins as a digitally controlled level shifter, but reading through the documentation I am kind of lost. The behavior I am looking for is to define an input pin and an output pin with set voltage levels, but then in software have them behave as normal pins where I can read and write to them without worrying about the analog side. Is this possible?
For the output I would want to setup the dac to a voltage initially, but then have the Out command tell the pin whether to drive or not.
for input I want to set the comparator value, then have the in command read high if it is above that value or low if it is below that value.
Confirmation that it is designed to do this would be good enough and I will keep chugging along with the documentation. If someone already has an example they can point me to that would be perfect!
For the output I would want to setup the dac to a voltage initially, but then have the Out command tell the pin whether to drive or not.
for input I want to set the comparator value, then have the in command read high if it is above that value or low if it is below that value.
Confirmation that it is designed to do this would be good enough and I will keep chugging along with the documentation. If someone already has an example they can point me to that would be perfect!
Comments
That said, yep, there is a pin mode that allows the DAC to be switched between two voltages just by toggling that pin's OUT bit. And there is a pin mode that uses the DAC internally to set the comparator threshold. I've not tried to work out if such arrangements are as fast as simple digital I/O though.
As you've already discovered, these are not clearly documented yet ... I did a translation a while back that should help, BIT_DAC and COMP_DAC are the modes you're after - https://forums.parallax.com/discussion/comment/1452036/#Comment_1452036
EDIT: Err, the BIT_DAC mode write-up there is out of date. That one applies to the revA silicon only.
EDIT2: Updated now. Easier than expected.
And it did that, I got working results at low clock rates. However, the higher resistance also increased attenuation so high clock rates still didn't work.
Elsewhere, I have the constants defined as
56 has normal 0 1 behavior while 57 is inverted:
wrpin ##%10110_11110000_10_00000_0,#56
wrpin ##%10110_00001111_10_00000_0,#57
Ok, I got both sides working now and I setup a little self test to evaluate them. Starting from the pasm blink example from the flexgui tool I added 3 more pins. The dac out, the comparator, then a result pin connected to an LED. I shorted the dac pin and the comparator together so that the comparator reads the result from the dac. The code drives the dac high, waits some time and then checks the comparator input pin. If the comparator reads the correct value it turns on the results LED. with this setup I verify that the two modes are working. Setting a comparator value greater than the output dac causes it to consistently fail. I have tried this for several ranges of dac and comparator so I think it is working well.
Evaluating the speed is interesting too. The key code is outh to waitx to testp. I checked for the minimum waitx value to still allow for blinking. the comparator was set to less than 50% to allow it to observe higher speeds.
digital out to digital in waitx=3
dac out digital in waitx=4
digital out comparator in waitx=6
dac out comparator in waitx=7
Then I set the Dac to minimum voltage swing and the comparator to half that and I got a minimum waitx of 9. This mode has 16 voltage levels so that is a swing of 0.22V.
I'm not sure what that really means in terms of speed. there need to be at least 2-4 cycles added to each number for the instructions running. I don't know whether there are additional clock cycles added between the process or and the pins in these modes.
It has quite an impact on external data read overheads, like SPI devices. To get top data rates, you have to lead by a number of clocks before the read data comes back at you.
PS: And the DAC clocking dynamically adds another stage.