Added code for switching between 3.3v and 5v signal output #featureadd
- Fixes #67
This commit is contained in:
parent
c521adccd3
commit
12f86c971b
8 changed files with 77 additions and 6 deletions
|
|
@ -11,10 +11,11 @@
|
|||
* PC0 ADC0 (Voltage Reference Check 'A0')
|
||||
* PC1 ADC1 (Sensitivity Adjustment Check 'A1')
|
||||
* PD4 PCINT20 (Error feedback LED 'D4')
|
||||
* PB6 PCINT6 (Voltage Adjustment Resistor 0 'D20')
|
||||
* PB7 PCINT7 (Voltage Adjustment Resistor 1 'D21')
|
||||
* PD5 T1 (Voltage Adjustment Resistor 2 'D5')
|
||||
* PD6 PCINT22 (Voltage Adjustment Resistor 3 'D6')
|
||||
* PB6 PCINT6 (Gain Adjustment Resistor 0 'D20')
|
||||
* PB7 PCINT7 (Gain Adjustment Resistor 1 'D21')
|
||||
* PD5 T1 (Gain Adjustment Resistor 2 'D5')
|
||||
* PD6 PCINT22 (Gain Adjustment Resistor 3 'D6')
|
||||
* PB0 PCINT0 (VCC Adjustment Resistors 'D8')
|
||||
* PB1 OC1A (Comparator VRef PWM Out 'D9')
|
||||
* PD3 OC2B (Voltage Follower VRef PWM Out 'D3')
|
||||
|
||||
|
|
@ -36,6 +37,7 @@ To change trigger active duration: TRG_D [integer for milliseconds]
|
|||
To change gain factor: GAIN_F [integer for gain state - see note*]
|
||||
To change the output logic: LOGIC [0|1] (0 for active low, 1 for active high)
|
||||
To enable piezo plugged detection: PZDET [0|1] (0 for disabled, 1 for enabled)
|
||||
To set the sensor's output voltage: VCCSW [0|1] (0 for 3.3v, 1 for 5v)
|
||||
To change ADC hysteresis value: HYST [integer in millivolts]
|
||||
To change sensor input pullup vRef low threshold: VFOL [integer in millivolts]
|
||||
To change comparator trigger high threshold: VCOMP [integer in millivolts]
|
||||
|
|
@ -128,6 +130,8 @@ void setup() {
|
|||
|
||||
adjustGain();
|
||||
|
||||
adjustVcc();
|
||||
|
||||
digitalWriteFast(TRG_OUT, !LOGIC);
|
||||
}
|
||||
|
||||
|
|
@ -155,6 +159,9 @@ void loop() {
|
|||
// Set the amplification gain factor
|
||||
adjustGain();
|
||||
|
||||
// Set the VCC input switch
|
||||
adjustVcc();
|
||||
|
||||
// Check voltage of first and second stages and compare against thresholds
|
||||
readVin();
|
||||
VComp = analogReadFast(VCOMP_SENSE_PIN);
|
||||
|
|
|
|||
|
|
@ -93,6 +93,16 @@ void updatePzDet(int value)
|
|||
}
|
||||
/*------------------------------------------------*/
|
||||
|
||||
void updateVccSwitch(int value)
|
||||
{
|
||||
if (value >= 0)
|
||||
{
|
||||
VCCSW = value;
|
||||
EEPROM.put(VCCSW_ADDRESS, VCCSW);
|
||||
}
|
||||
}
|
||||
/*------------------------------------------------*/
|
||||
|
||||
void updateConstant(long value)
|
||||
{
|
||||
if (value >= 0)
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ int TRG_DUR = TRG_DUR_DEFAULT;
|
|||
int Hyst = HYST_DEFAULT;
|
||||
int LOGIC = LOGIC_DEFAULT;
|
||||
int PZDET = PZDET_DEFAULT;
|
||||
int VCCSW = VCCSW_DEFAULT;
|
||||
int Debug = 0;
|
||||
long voltMeterConstant = VM_CONST_DEFAULT;
|
||||
|
||||
|
|
@ -26,6 +27,7 @@ void eraseEEPROM() {
|
|||
EEPROM.put(HYST_ADDRESS, Hyst);
|
||||
EEPROM.put(PZDET_ADDRESS, PZDET);
|
||||
EEPROM.put(LOGIC_ADDRESS, LOGIC);
|
||||
EEPROM.put(VCCSW_ADDRESS, VCCSW);
|
||||
EEPROM.put(VM_CONST_ADDRESS, voltMeterConstant);
|
||||
}
|
||||
|
||||
|
|
@ -91,6 +93,13 @@ void restoreConfig() {
|
|||
LOGIC = temp;
|
||||
}
|
||||
|
||||
EEPROM.get(VCCSW_ADDRESS, temp);
|
||||
if (temp < 0 || temp > 1) {
|
||||
erase = true;
|
||||
} else {
|
||||
VCCSW = temp;
|
||||
}
|
||||
|
||||
long longTemp;
|
||||
EEPROM.get(VM_CONST_ADDRESS, longTemp);
|
||||
if (longTemp < 1000000L || longTemp > 1200000L) {
|
||||
|
|
@ -116,6 +125,7 @@ void setDefaultConfig() {
|
|||
Hyst = HYST_DEFAULT;
|
||||
PZDET = PZDET_DEFAULT;
|
||||
LOGIC = LOGIC_DEFAULT;
|
||||
VCCSW = VCCSW_DEFAULT;
|
||||
voltMeterConstant = VM_CONST_DEFAULT;
|
||||
adjustFollow();
|
||||
adjustComp();
|
||||
|
|
|
|||
|
|
@ -39,9 +39,13 @@ extern int LOGIC; // Trigger logic scheme, Active LOW is default
|
|||
#define PZDET_ADDRESS 26
|
||||
extern int PZDET; // Enable or disable piezo connection detection, default is off
|
||||
|
||||
#define VCCSW_DEFAULT 0
|
||||
#define VCCSW_ADDRESS 28
|
||||
extern int VCCSW; // Enable or disable piezo connection detection, default is off
|
||||
|
||||
extern int Debug;
|
||||
|
||||
#define VM_CONST_ADDRESS 28
|
||||
#define VM_CONST_ADDRESS 30
|
||||
#define VM_CONST_DEFAULT 1125300L
|
||||
extern long voltMeterConstant; // For fine tuning input voltage sense
|
||||
|
||||
|
|
|
|||
|
|
@ -192,6 +192,23 @@ void adjustGain()
|
|||
|
||||
/*------------------------------------------------*/
|
||||
|
||||
void adjustVcc()
|
||||
{
|
||||
switch (VCCSW)
|
||||
{
|
||||
case 0:
|
||||
pinMode(VCCSW_PIN, OUTPUT);
|
||||
digitalWriteFast(VCCSW_PIN, LOW);
|
||||
break;
|
||||
case 1:
|
||||
default:
|
||||
pinMode(VCCSW_PIN, INPUT);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*------------------------------------------------*/
|
||||
|
||||
//void checkError () {
|
||||
// if (ERR_STATE == 1) {
|
||||
// digitalWriteFast(ERR_LED, BlinkState);
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ update the voltMeterConstant variable in pP_config.h with the correct value
|
|||
void readVin();
|
||||
void adjustFollow();
|
||||
void adjustComp();
|
||||
void adjustVcc();
|
||||
void calibrateAlert();
|
||||
void adjustGain();
|
||||
//void checkError () {
|
||||
|
|
|
|||
|
|
@ -30,4 +30,5 @@ Default pins (based on Rev.2.x.xPCB layout)
|
|||
#define GADJ_R3 6 // "
|
||||
#define V_FOL_PWM 3 // PWM analog output pin for voltage follower adjustment
|
||||
#define VCOMP_PWM 9 // PWM analog output pin for comparator adjustment
|
||||
#define PZDET_PIN 16 // Digital input pin for detecting piezo connection
|
||||
#define PZDET_PIN 16 // Digital input pin for detecting piezo connection
|
||||
#define VCCSW_PIN 8 // VCC variable regulator switch pin
|
||||
|
|
@ -108,6 +108,21 @@ void serialPrintConfig()
|
|||
|
||||
Serial.print("PZDET ");
|
||||
Serial.println(PZDET);
|
||||
|
||||
Serial.print("VCCSW ");
|
||||
Serial.print(VCCSW);
|
||||
switch (VCCSW)
|
||||
{
|
||||
case 0:
|
||||
Serial.println(" 3.3v");
|
||||
break;
|
||||
case 1:
|
||||
Serial.println(" 5v");
|
||||
break;
|
||||
default:
|
||||
Serial.println(" INVALID");
|
||||
break;
|
||||
}
|
||||
|
||||
Serial.print("VM_CONST ");
|
||||
Serial.println(voltMeterConstant);
|
||||
|
|
@ -182,6 +197,10 @@ void updateParams()
|
|||
{
|
||||
updatePzDet(serialLong);
|
||||
}
|
||||
else if (strcmp(serialMessageIn, "VCCSW") == 0)
|
||||
{
|
||||
updateVccSwitch(serialLong);
|
||||
}
|
||||
else if (strcmp(serialMessageIn, "CONST") == 0)
|
||||
{
|
||||
updateConstant(serialLong);
|
||||
|
|
@ -215,6 +234,8 @@ void updateParams()
|
|||
Serial.println(" (0 for active low, 1 for active high)");
|
||||
Serial.println("To enable piezo plugged detection: PZDET [0|1]");
|
||||
Serial.println(" (0 for disabled, 1 for enabled)");
|
||||
Serial.println("To change the main voltage of the circuit: VCCSW [0|1]")
|
||||
Serial.println(" (0 for 3.3v, 1 for 5v)");
|
||||
Serial.println("To change ADC hysteresis value: HYST [integer in millivolts]");
|
||||
Serial.println("To enable or disable debug output: DEBUG [0|1]");
|
||||
Serial.println("To print current config: CONFIG");
|
||||
|
|
|
|||
Loading…
Reference in a new issue