Serial Peripheral Interface
The example I show you then use the communication protocol Serial Peripheral Interface (SPI) using the Proteus program for controlling a digital potentiometer
We will choose the microcontroller of Atmel ATMEGA 328P
In this picture we see how we connect the potentiometers
/*
Digital Pot Control
This example controls an Analog Devices AD5206 digital potentiometer.
The AD5206 has 6 potentiometer channels. Each channel's pins are labeled
A - connect this to voltage A - connect this to the stress
W - this is the pot's wiper, which changes when you set it W - it is wiper of potentiometer, which changes when configure
The AD5206 is SPI-compatible,and to command it, you send two bytes,
one with the channel number (0 - 5) and one with the resistance value for the
channel (0 - 255).
The AD5206 is compatible with SPI, and to command them, you send two bytes,
one channel number (0 - 5) and one with the resistance value for the
channel (0-255).
The circuit:
* All A pins of AD5206 connected to +5V * Todos Unos pasadores de AD5206 conectados a + 5V
* All B pins of AD5206 connected to ground * Todos los pines B de AD5206 conectados a tierra
* An LED and a 220-ohm resisor in series connected from each W pin to ground * Un LED y un resisor 220 ohmios en serie conectado desde cada pasador W a tierra
* CS - to digital pin 10 (SS pin) * CS - al pin digital 10 (pin SS)
* SDI - to digital pin 11 (MOSI pin) * SDI - al pin digital 11 (pin MOSI)
* CLK - to digital pin 13 (SCK pin) * CLK - al pin digital 13 (pin SCK)
// The Bus SPI (Serial Peripheral Interface) is a communications standard, mainly used for
transferring information between integrated circuits in electronic equipment. The bus serial peripheral interface
or SPI bus is a standard for controlling almost any digital electronic device that accepts a serial bit stream
regulated by a clock (synchronous communication).
It includes a clock line, incoming data, outgoing data and chip select pin, which connects or disconnects the operation
the device with which you want to communicate. Thus, this standard allows multiplexing clock lines.
created 20 Febrero 2015
by Ángel
*/
// include the SPI library: // SPI library include:
#include <SPI.h>
// set pin 10 as the slave select for the digital pot:
const int slaveSelectPin = 10;
// const is used to declare a constant field or constant local.
// The constant fields and local variables are not and can not be changed.
// Constants can be numbers, Boolean values, strings or a null reference.
// int variable is an integer data type
// (void setup) initializes and sets the initial values
void setup() {
// set the slaveSelectPin as an output: // Set slaveSelectPin as an outlet:
pinMode (slaveSelectPin, OUTPUT); // Set the pin as an output ss
// initialize SPI: // Initialize SPI:
SPI.begin(); // Initializes the SPI protocol
}
// (void loop)It is doing loops consecutively
void loop() {
// go through the six channels of the digital pot: // Go through the six channels of digital potentiometer:
// (int channel) declares the variable
// = initializes
// ++ increase from 0 to 6
// Initialization happens first and exactly once. Each time through the loop, the condition is tested;
// if true, the increase and the block of statements is executed, then the condition is tested again.
// When the condition becomes false, the loop exits.
for (int channel = 0; channel < 6; channel++) {
// change the resistance on this channel from min to max: // Change the channel resistance from minimum to maximum:
// for = is used to repeat a block of statements enclosed
// increases the level of 0-255
for (int level = 0; level < 255; level++) {
digitalPotWrite(channel, level);
// Write a HIGH or LOW value to a digital pin (potentiometer)
// If configured as an output pinMode (), the voltage is set to the appropriate value:
//5V para HIGH, 0V (tierra) para LOW.
delay(10);
// Pauses the program for the amount of time (in milliseconds) specified as a parameter.
}
// wait a second at the top: // Wait a second at the top:
delay(100);
// change the resistance on this channel from max to min: // Change the channel resistance in the MIN MAX:
for (int level = 0; level < 255; level++) {
digitalPotWrite(channel, 255 - level);
// increases the value down
delay(10);
}
}
}
void digitalPotWrite(int address, int value) {
// take the SS pin low to select the chip: // Take the low value of the SS pin to select the chip:
digitalWrite(slaveSelectPin,LOW);
// send in the address and value via SPI: // Send the address and SPI value through:
SPI.transfer(address);
SPI.transfer(value);
// take the SS pin high to de-select the chip: // Take the high value of the SS pin to deselect the chip:
digitalWrite(slaveSelectPin,HIGH);
}
In these images we see through voltmeters as it changes the resistance value in each of the 6 channels of the potentiometer as time passes
No hay comentarios:
Publicar un comentario