I am trying to incorporate the AD5220 10K Digital Potentiometer into my project. There are 128 steps on this potentiometer which are stepped by "pulsing the CLK pin while CS is active low" I understand the CS low part but do not understand the proper way to pulse the CLK pin. Is there a better way than just writing the CLK pin high then low manually with digitalWrite()? Would that method create a sharp enough pulse to even work?
That should work. I’ve manually bit-banged shift registers that way. You might not even need a delay between writing HIGH/LOW. Worth an experiment.
This datasheet says that the clock pulsewidth only needs to be 25ns. If my maths is right that is a frequency of 20MHz so mjward's suggestion of just clocking it high then low without a delay should work on a 16MHz Arduino.
You could use two PINx instructions in a row to create a pulse at a pin.
PINB |= 1<<5; //toggle the state of digital PIN 13 (on an UNO)
PINB |= 1<<5;
. . .
PINB |= _BV (5);
PINB |= _BV (5);
In setup() start pin 13 out with a HIGH, use a digitalWrite
What is your application? Do you need to quickly go to certain step (resistance) values, track a signal, calibrate, or other?
SPI could work with this. The MOSI output would connect to the potentiometer's CLK. An advantage would be that you could send 1,2,3 or 4 pulses with one byte transfer. Here, the pulse timing is consistent and non-blocking to your code.
I would stay away from just toggling an output with PINx unless you always know the output's initial state (the potentiometer's CLK is negative edge triggered).
I would stay away from just toggling an output with PINx unless you always know the output’s initial state
Agreed, that’s why I mentioned:
“In setup() start pin 13 out with a HIGH, use a digitalWrite”
I should of said LOW