115 lines
No EOL
4.7 KiB
C++
115 lines
No EOL
4.7 KiB
C++
#include <Wire.h>
|
|
|
|
//this code sets values in the MAX5387LAUD+ via I2C.
|
|
//it then reads back those values over A1 and A2 inputs
|
|
//The ADC is set to 12 bits for the DUE
|
|
//Channels are scanned in parallel (0 to 255)
|
|
//then alternatively ascending and descending.
|
|
//Output is a CSV over serial at 9600bps.
|
|
|
|
//this test works when testing with board 2
|
|
//Note the MAX5387LAUD+ doesn't support I2C readback.
|
|
|
|
|
|
byte ADCval;
|
|
byte ADCval1;
|
|
byte ADCval2;
|
|
byte ADCval3;
|
|
byte ADCval4;
|
|
byte ADCval5;
|
|
byte ADCval6;
|
|
|
|
void setup() {
|
|
// put your setup code here, to run once:
|
|
pinMode(35, OUTPUT); //setup for the MAX5387 - later set to 0. signal PA0
|
|
pinMode(36, OUTPUT);//setup for the MAX5387 - later set to 0. signal PA1
|
|
pinMode(37, OUTPUT);//setup for the MAX5387 - later set to 0. signal PA2
|
|
pinMode(A1, INPUT); //make sure the input pins are in high impedance mode
|
|
pinMode(A2, INPUT);//make sure the input pins are in high impedance mode
|
|
digitalWrite(35, LOW);//configure the address of the MAX5387 pot
|
|
digitalWrite(36, LOW);//configure the address of the MAX5387 pot
|
|
digitalWrite(37, LOW);//configure the address of the MAX5387 pot
|
|
pinMode(5, INPUT); //set the interrupt pin for trigger as high impedance, probably not required
|
|
|
|
//setup the serial for debug
|
|
Serial.begin(9600);
|
|
//setup the MAX5387 pot
|
|
ADCval1 = byte(0x00);
|
|
ADCval2 = byte(0x00);
|
|
ADCval3 = byte(0xFF);
|
|
ADCval4 = byte(0x00);
|
|
ADCval5 = byte(0x00);
|
|
ADCval6 = byte(0xFF);
|
|
analogReadResolution(12);
|
|
}
|
|
|
|
|
|
void loop() {
|
|
|
|
for (int i=0; i<=0xFF; i++){
|
|
Wire.begin();
|
|
//Serial.print("MAX5387 Address ");
|
|
//Serial.print(0x28, HEX);
|
|
Wire.beginTransmission(byte(0x28)); // transmit to device #112
|
|
Wire.write(byte(B00010011));
|
|
Wire.write(ADCval1);// sets register pointer to echo #1 register (0x02)
|
|
Wire.endTransmission(); // stop transmitting
|
|
Serial.print("Both Channels ++ Setpoint 1:"); //note that this is manually updated by the human!
|
|
Serial.print(ADCval1); //note that this is manually updated by the human!
|
|
Serial.print("; Setpoint 2:"); //note that this is manually updated by the human!
|
|
Serial.print(ADCval1); //note that this is manually updated by the human!
|
|
Serial.print("; A1:"); //note that this is manually updated by the human!
|
|
Serial.print(analogRead(A1));
|
|
Serial.print("; A2:"); //note that this is manually updated by the human!
|
|
Serial.print(analogRead(A2));
|
|
Serial.println(";"); //note that this is manually updated by the human!
|
|
ADCval1++;
|
|
delay(10);
|
|
}
|
|
for (int i=0; i<=0xFF; i++){
|
|
|
|
Wire.beginTransmission(byte(0x28)); // transmit to device #112
|
|
Wire.write(byte(B00010001));
|
|
Wire.write(ADCval3);// sets register pointer to echo #1 register (0x02)
|
|
Wire.endTransmission(); // stop transmitting
|
|
Wire.beginTransmission(byte(0x28)); // transmit to device #112
|
|
Wire.write(byte(B00010010));
|
|
Wire.write(ADCval4);// sets register pointer to echo #1 register (0x02)
|
|
Wire.endTransmission(); // stop transmitting
|
|
Serial.print("Ch1-- Ch2++ Setpoint 1:"); //note that this is manually updated by the human!
|
|
Serial.print(ADCval3); //note that this is manually updated by the human!
|
|
Serial.print("; Setpoint 2:"); //note that this is manually updated by the human!
|
|
Serial.print(ADCval4); //note that this is manually updated by the human!
|
|
Serial.print("; A1:"); //note that this is manually updated by the human!
|
|
Serial.print(analogRead(A1));
|
|
Serial.print("; A2:"); //note that this is manually updated by the human!
|
|
Serial.print(analogRead(A2));
|
|
Serial.println(";"); //note that this is manually updated by the human!
|
|
ADCval3--;
|
|
ADCval4++;
|
|
delay(10);
|
|
}
|
|
for (int i=0; i<=0xFF; i++){
|
|
|
|
Wire.beginTransmission(byte(0x28)); // transmit to device #112
|
|
Wire.write(byte(B00010001));
|
|
Wire.write(ADCval5);// sets register pointer to echo #1 register (0x02)
|
|
Wire.endTransmission(); // stop transmitting
|
|
Wire.beginTransmission(byte(0x28)); // transmit to device #112
|
|
Wire.write(byte(B00010010));
|
|
Wire.write(ADCval6);// sets register pointer to echo #1 register (0x02)
|
|
Wire.endTransmission(); // stop transmitting
|
|
Serial.print("Ch1++ Ch2-- Setpoint 1:"); //note that this is manually updated by the human!
|
|
Serial.print(ADCval5); //note that this is manually updated by the human!
|
|
Serial.print("; Setpoint 2:"); //note that this is manually updated by the human!
|
|
Serial.print(ADCval6); //note that this is manually updated by the human!
|
|
Serial.print("; A1:"); //note that this is manually updated by the human!
|
|
Serial.print(analogRead(A1));
|
|
Serial.print("; A2:"); //note that this is manually updated by the human!
|
|
Serial.print(analogRead(A2));
|
|
Serial.println(";"); //note that this is manually updated by the human!
|
|
ADCval5++;
|
|
ADCval6--;
|
|
delay(10);
|
|
}
|
|
} |