View Full Version : Weird SPI interface: VIH to VIHH for CS?
achilles03
- 28th January 2009, 19:20
I have a dual channel digital pot using an SPI interface (MCP4261):
http://ww1.microchip.com/downloads/en/DeviceDoc/22059b.pdf (http://ww1.microchip.com/downloads/en/DeviceDoc/22059b.pdf)
I'm confused about this SPI interface based on the following reasons:
On page 41 (section 6.1.5), it states that "the CS signal must transition from the inactive state (VIH) to an active state (VIL or VIHH)."
On page 11, it demonstrates this by showning CS going from VIH (a voltage between VIHH and VIL) to VIHH.
Furthermore, on page 9, it states that min schmitt trigger high input threshold (VIH) is .45Vdd (at Vdd = 5V), while VIL is <= .2Vdd.
So does this mean I have to keep CS between 1V and 2.25V (for Vdd=5V) for it to be "inactive"? This is counter to most SPI interfaces I've used (CS is inactive when high, active when low).
Any help or insight is appreciated!
Thanks,
Dave
mister_e
- 28th January 2009, 20:10
As long as you're HIGH level is over the minimum Vih, and your LOW level is under than min Vil, you're not going to have problem.
By their notation on the CS pin, it has to be active when low, unless they wouldn't have place a line over it.
Have a look at Wikipedia for a real-English explanation ;)
http://en.wikipedia.org/wiki/Logic_level
achilles03
- 29th January 2009, 02:54
Ah, I figured out the VIHH thing. It's Vdd + some delta-V used in order to use their "wiperlock" technology. You can only activate it if CS exceeds Vdd.
Regardless, I still can't adjust the resistance of the chip. I'm using the following code with a 16F628:
---------------------------------
cmcon=7
define osc 8
res var byte
CS var porta.2 'CS
CLK var porta.3 'CLK
SI var porta.4 'SI
LED var porta.1 'LED
high CS
high LED
pause 500
low LED
pause 500
high LED
repeatit:
res=24
low CS
shiftout SI,CLK,1,[%00000000\8,res\8]
high CS
pause 100
low CS
shiftout SI,CLK,1,[%00010000\8,res\8]
high CS
pause 200
res=res+128
goto repeatit
end
---------------------------------
I have a 10k pullup resistor on SI, yet no change in resistance.
Any advice or help is appreciated!
Dave
mister_e
- 29th January 2009, 03:04
move res=24 before your repeatit label may help ;)
Maybe not a bad idea to set the clock LOW at the top of your code.
achilles03
- 29th January 2009, 05:34
move res=24 before your repeatit label may help ;)
Maybe not a bad idea to set the clock LOW at the top of your code.
Good catch. :D But even with the res=24 inside the loop, I'm still reading 100k across the wipers and the A terminals, and low resistance across the wipers and the B terminals. I slowed down the clock with a "define shift_pauseus 100", took the res=24 outside the loop, but still can't see any changes in resistance. Here's my adjusted code:
--------------------
cmcon=7
define osc 8
define shift_pauseus 100
res var byte
CS var porta.2 'CS
CLK var porta.3 'CLK
SI var porta.4 'SI
LED var porta.1 'LED
high CS
high LED
pause 500
low LED
pause 500
high LED
res=24
repeatit:
low CS
shiftout SI,CLK,1,[%00000000\8,res\8]
high CS
pause 10
low CS
shiftout SI,CLK,1,[%00010000\8,res\8]
high CS
pause 500
res=res+32
goto repeatit
end
--------------------
I also have 10k resistors between the MCP4261 pins and the 16F628A pins, but that shouldn't affect anything.
WP and SHDN can be left floating, right? Am I correctly formatting the command byte? Aren't the memory locations %0000 and %0001 the correct ones to address?
Thanks for the help!
Dave
mister_e
- 29th January 2009, 06:25
I wouldn't leave a pin floating myself, mainly SHDN. On the other hand, by their specs, they says there's a "Smart Pull-Up" inside... how smart it is... who knows :D
Your code seems to be ok to me, but you still haven't added the LOW CS in there... not sur if this could help though...
PS: Make sure your DEFINEs are all in UPPERCASE.
Do you have a PICKIT 2? in this case you could monitor what happen on CS/CLK/SDI and SDO
Do you have a complete schematic of your thing?
EDIT: Try this one
define OSC 8
cmcon=7
res var byte
Command var WORD
CS var porta.2 'CS
CLK var porta.3 'CLK
SI var porta.4 'SI
LED var porta.1 'LED
high CS
LOW CLK
high LED
pause 500
low LED
pause 500
high LED
res=24
repeatit:
command.highbyte=0 ' Volatile Wiper 0
comand.lowbyte=res
low CS
shiftout SI,CLK,1,[command\16]
high CS
pause 10
Command.HighByte=%00010000 ' Volatile Wiper 1
low CS
shiftout SI,CLK,1,[Command\16]
high CS
pause 500
res=res+32
goto repeatit
achilles03
- 30th January 2009, 01:29
It still wasn't working... until I changed out the 10k resistors with 500 ohms. Apparently the 10k were too high. Maybe there's an internal pull up or down that was low enough to prevent the pin from reaching the required voltage threshold.
What pins should I be worried about protecting anyway? CS, SI, SO, CLK, etc?
Thanks,
Dave
mister_e
- 30th January 2009, 14:24
I also have 10k resistors between the MCP4261 pins and the 16F628A pins, but that shouldn't affect anything.
.
.
.
.
It still wasn't working... until I changed out the 10k resistors with 500 ohms.
Are you saying that your 10K resistor where in serie between the PIC and the MCP chip? :eek:
If so, you just don't need any, connect them directly. The only concern you may have, is the open-collector ones. In this case 10K or lower are nice between 5V and your pin.
achilles03
- 30th January 2009, 15:49
Are you saying that your 10K resistor where in serie between the PIC and the MCP chip? :eek:
If so, you just don't need any, connect them directly. The only concern you may have, is the open-collector ones. In this case 10K or lower are nice between 5V and your pin.
Yeah, I usually put them on to prevent burning out a pin on accident. What pins are considered "open-collector"? Do CS, CLK, and SI typically have internal resistors that limit current flow? What about SO?
Thanks!
Dave
mister_e
- 30th January 2009, 17:25
What you need to worry is your PIC I/O, some could be Open-Collector type, so if you use a open collector I/O as output, you need to add a pull-up resistor on it, unless your pin will never go to the high level unless your device have internal pull-up.
If you want to protect your PIC i/O from short, then use something like ~100-200 Ohm would work. In theory each I/O is capable to drive/sink 25mA... 5V/25mA=200 Ohms. Higher the current limiting + Faster your signal is, higher the chance to screw up your signal shape/edges/amplitude, higher the chance to have issue.
As you don't use Shiftin, you don't need to worry about SO
Powered by vBulletin® Version 4.1.7 Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.