7
mirror of https://github.com/EEVengers/ThunderScope.git synced 2025-04-03 05:16:33 +00:00

Added Firmware For Test Boards

This commit is contained in:
Aleksa Bjelogrlic 2024-11-08 18:07:58 -08:00
parent e8e8c10208
commit a05c59700e
3 changed files with 359 additions and 0 deletions
Hardware
Altium
Rev5_FE_Test/Rev5_FE_Test
Rev5_FE_Test_Latched/Rev5_FE_Test_Latched
KiCad/HMCAD1520_Impedence_Checker/HMCAD1520_Impedence_Tester

View File

@ -0,0 +1,143 @@
#include <Wire.h>
const int CS = 10;
const int SCLK = 13;
const int SDIO = 11;
const int TERM = 0;
const int CPL = 1;
const int ATTEN = 2;
const bool LATCHING = false;
void setup() {
// initialize serial:
Serial.begin(9600);
pinMode (CS, OUTPUT);
digitalWrite (CS, HIGH);
pinMode (SCLK, OUTPUT);
digitalWrite (SCLK, HIGH);
pinMode (SDIO, OUTPUT);
digitalWrite (SDIO, LOW);
pinMode (TERM, OUTPUT);
digitalWrite (TERM, LOW);
pinMode (CPL, OUTPUT);
digitalWrite (CPL, LOW);
pinMode (ATTEN, OUTPUT);
digitalWrite (ATTEN, LOW);
Wire.begin();
}
void loop() {
// if there's any serial available, read it:
while (Serial.available() > 0) {
String command = Serial.readString();
command.trim();
Serial.println(command);
if (command.indexOf("PGA") != -1){
String preamp_str = command.substring(4, 5);
int preamp = preamp_str.toInt();
String attenuation_str = command.substring(6);
int attenuation = attenuation_str.toInt();
setPGA(preamp,attenuation);
}
else if (command.indexOf("DAC") != -1){
String dac_code_str = command.substring(4);
int dac_code = dac_code_str.toInt();
setDAC(dac_code);
}
else if (command.indexOf("DPOT") != -1){
String dpot_code_str = command.substring(5);
int dpot_code = dpot_code_str.toInt();
setDPOT(dpot_code);
}
else if (command.indexOf("ATTEN") != -1){
String atten_str = command.substring(6);
int atten = atten_str.toInt();
setATTEN(atten);
}
else if (command.indexOf("CPL") != -1){
String cpl_str = command.substring(4);
int cpl = cpl_str.toInt();
setCPL(cpl);
}
else if (command.indexOf("TERM") != -1){
String term_str = command.substring(5);
int term = term_str.toInt();
setTERM(term);
}
else{
Serial.println("Invalid Command");
}
}
}
void setPGA(int preamp, int attenuation){
uint32_t settings = 0x00000400;
if (preamp == 1)
settings |= 0x00000010;
settings |= ((uint32_t) (attenuation/2) & 0x0000000F);
digitalWrite(CS,LOW);
for (int x = 0; x < 24; x++){
digitalWrite(SCLK,LOW);
digitalWrite(SDIO,((settings >> (23-x)) & 0x00000001));
delayMicroseconds(1);
digitalWrite(SCLK,HIGH);
delayMicroseconds(1);
}
digitalWrite(CS,HIGH);
digitalWrite(SDIO,0);
}
void setDAC(int dac_code){
uint16_t command_data = 0x0000;
command_data |= (uint16_t)dac_code & 0x0FFF;
Wire.beginTransmission(0b1100000);
Wire.write(0b01011000);
Wire.write(command_data >> 8);
Wire.write(command_data & 0x00FF);
Wire.endTransmission();
}
void setDPOT(int dpot_code){
uint16_t command_data = 0x0000;
command_data |= 0x06 << 12; //wiper 2
command_data |= (uint16_t)dpot_code & 0x03FF;
Wire.beginTransmission(0b0101110);
Wire.write(0b01011000);
Wire.write(command_data >> 8);
Wire.write(command_data & 0x00FF);
Wire.endTransmission();
}
void setATTEN(int atten){
if (atten == 1)
digitalWrite (ATTEN, HIGH);
else
digitalWrite (ATTEN, LOW);
}
void setCPL(int cpl){
if (cpl == 1)
digitalWrite (CPL, HIGH);
else
digitalWrite (CPL, LOW);
}
void setTERM(int term){
if (term == 1)
digitalWrite (TERM, HIGH);
else
digitalWrite (TERM, LOW);
}

View File

@ -0,0 +1,176 @@
#include <Wire.h>
const int CS = 10;
const int SCLK = 13;
const int SDIO = 11;
const int A = 0;
const int B = 1;
const int G1 = 2;
const int CPL = 3;
const bool LATCHING = false;
void setup() {
// initialize serial:
Serial.begin(9600);
pinMode (CS, OUTPUT);
digitalWrite (CS, HIGH);
pinMode (SCLK, OUTPUT);
digitalWrite (SCLK, HIGH);
pinMode (SDIO, OUTPUT);
digitalWrite (SDIO, LOW);
pinMode (A, OUTPUT);
digitalWrite (A, LOW);
pinMode (B, OUTPUT);
digitalWrite (B, LOW);
pinMode (G1, OUTPUT);
digitalWrite (G1, LOW);
pinMode (CPL, OUTPUT);
digitalWrite (CPL, LOW);
Wire.begin();
}
void loop() {
// if there's any serial available, read it:
while (Serial.available() > 0) {
String command = Serial.readString();
command.trim();
Serial.println(command);
if (command.indexOf("PGA") != -1){
String preamp_str = command.substring(4, 5);
int preamp = preamp_str.toInt();
String attenuation_str = command.substring(6);
int attenuation = attenuation_str.toInt();
setPGA(preamp,attenuation);
}
else if (command.indexOf("DAC") != -1){
String dac_code_str = command.substring(4);
int dac_code = dac_code_str.toInt();
setDAC(dac_code);
}
else if (command.indexOf("DPOT") != -1){
String dpot_code_str = command.substring(5);
int dpot_code = dpot_code_str.toInt();
setDPOT(dpot_code);
}
else if (command.indexOf("ATTEN") != -1){
String atten_str = command.substring(6);
int atten = atten_str.toInt();
setATTEN(atten);
}
else if (command.indexOf("CPL") != -1){
String cpl_str = command.substring(4);
int cpl = cpl_str.toInt();
setCPL(cpl);
}
else if (command.indexOf("TERM") != -1){
String term_str = command.substring(5);
int term = term_str.toInt();
setTERM(term);
}
else{
Serial.println("Invalid Command");
}
}
}
void setPGA(int preamp, int attenuation){
uint32_t settings = 0x00000400;
if (preamp == 1)
settings |= 0x00000010;
settings |= ((uint32_t) (attenuation/2) & 0x0000000F);
digitalWrite(CS,LOW);
for (int x = 0; x < 24; x++){
digitalWrite(SCLK,LOW);
digitalWrite(SDIO,((settings >> (23-x)) & 0x00000001));
delayMicroseconds(1);
digitalWrite(SCLK,HIGH);
delayMicroseconds(1);
}
digitalWrite(CS,HIGH);
digitalWrite(SDIO,0);
}
void setDAC(int dac_code){
uint16_t command_data = 0x0000;
command_data |= (uint16_t)dac_code & 0x0FFF;
Wire.beginTransmission(0b1100000);
Wire.write(0b01011000);
Wire.write(command_data >> 8);
Wire.write(command_data & 0x00FF);
Wire.endTransmission();
}
void setDPOT(int dpot_code){
uint16_t command_data = 0x0000;
command_data |= 0x06 << 12; //wiper 2
command_data |= (uint16_t)dpot_code & 0x03FF;
Wire.beginTransmission(0b0101110);
Wire.write(0b01011000);
Wire.write(command_data >> 8);
Wire.write(command_data & 0x00FF);
Wire.endTransmission();
}
void setATTEN(int atten){
if (atten == 1){
digitalWrite (A, HIGH);
digitalWrite (B, LOW);
digitalWrite (G1, HIGH);
delay(10);
digitalWrite (A, LOW);
digitalWrite (B, LOW);
digitalWrite (G1, LOW);
}
else{
digitalWrite (A, LOW);
digitalWrite (B, LOW);
digitalWrite (G1, HIGH);
delay(10);
digitalWrite (A, LOW);
digitalWrite (B, LOW);
digitalWrite (G1, LOW);
}
}
void setCPL(int cpl){
if (cpl == 1)
digitalWrite (CPL, HIGH);
else
digitalWrite (CPL, LOW);
}
void setTERM(int term){
if (term == 1){
digitalWrite (A, HIGH);
digitalWrite (B, HIGH);
digitalWrite (G1, HIGH);
delay(10);
digitalWrite (A, LOW);
digitalWrite (B, LOW);
digitalWrite (G1, LOW);
}
else{
digitalWrite (A, LOW);
digitalWrite (B, HIGH);
digitalWrite (G1, HIGH);
delay(10);
digitalWrite (A, LOW);
digitalWrite (B, LOW);
digitalWrite (G1, LOW);
}
}

View File

@ -0,0 +1,40 @@
#define SEL0 17
#define SEL1 16
#define SEL2 15
void setup() {
Serial.begin(9600);
pinMode(SEL0, OUTPUT);
pinMode(SEL1, OUTPUT);
pinMode(SEL2, OUTPUT);
digitalWrite(SEL0, LOW);
digitalWrite(SEL1, LOW);
digitalWrite(SEL2, LOW);
}
void loop() {
while (Serial.available() > 0) {
char input = Serial.read();
if (input == '0'){ //AVDD
digitalWrite(SEL0, LOW);
digitalWrite(SEL1, LOW);
digitalWrite(SEL2, LOW);
}
else if (input == '1'){ //AVDD2
digitalWrite(SEL0, LOW);
digitalWrite(SEL1, LOW);
digitalWrite(SEL2, HIGH);
}
else if (input == '2'){ //DVDD
digitalWrite(SEL0, HIGH);
digitalWrite(SEL1, LOW);
digitalWrite(SEL2, LOW);
}
else if (input == '3'){ //OVDD
digitalWrite(SEL0, HIGH);
digitalWrite(SEL1, HIGH);
digitalWrite(SEL2, LOW);
}
Serial.print(input);
}
}