Compare commits

...

27 Commits

Author SHA1 Message Date
Benny Liu 123e620f50 Modify trigger receive function.
Turn on PULSE_MODE.
Use "struct" to express channel.
2021-05-24 16:20:25 +08:00
Benny Liu b5a7720c24 Modify LED notification. 2021-05-21 15:26:15 +08:00
Benny Liu 152937ca32 Disable all output after reset() 2021-05-07 17:39:57 +08:00
Benny Liu 3c85fbef6f Work mode LED for TRIG01. 2021-05-07 16:28:49 +08:00
Benny Liu 4ff8f044c4 Check TW1508 function ok. 2021-05-03 18:01:13 +08:00
Benny Liu 22a2095cd7 Add update TRIG01 pin output value. 2021-05-03 14:57:29 +08:00
Benny Liu 9c10e4ba53 Add set channel select LED notification. 2021-04-26 17:24:44 +08:00
Benny Liu 0529f84511 Charging notification LED 2021-04-23 17:09:57 +08:00
Benny Liu da63ff03d3 Add refresh TRIG01 LED function. 2021-04-23 13:25:27 +08:00
Benny Liu 141dcb70a3 full scale range for TW1508: 0x0000 ~ 0x03FF 2021-03-22 16:24:34 +08:00
Benny Liu 8625222e36 Switch to LOAD0 before remove_elite_pin(). 2021-03-22 14:41:07 +08:00
Benny Liu 498652836c Switch to LOAD0 before remove_elite_pin(). No pin overwrite issue. 2021-03-19 17:56:47 +08:00
Benny Liu dbfd4364e3 Latch LOADA & LOADB no no. 2021-03-15 18:22:08 +08:00
Benny Liu bd049e4fec Use headstage.h ADC_TEST to test TRIG01, TW1508 control still not working.
TW1508reset() --> turnoff itself
2021-03-12 18:17:22 +08:00
Benny Liu f20b6634ae Merge remote-tracking branch 'origin/Elite_TRIG01_development' into Elite_TRIG01_development 2021-02-26 17:43:11 +08:00
Benny Liu b59472ad2d Add TRIG01 LED functions. 2021-02-26 17:29:59 +08:00
Benny Liu a75b3ba58f Add TRIG02 LED functions. 2021-02-26 17:19:20 +08:00
Benny Liu 8c3d8f46df Update TRIG01 ADC command 2021-02-22 15:29:52 +08:00
Benny Liu ca29a325f1 Use GPIO control TW1508, yes yes. 2021-02-20 18:50:00 +08:00
Benny Liu 61aee1a3e6 Use GPIO to control TW1508. 2021-02-18 14:33:25 +08:00
Benny Liu 162b528385 Add file TRIG.h 2021-02-17 14:40:17 +08:00
Benny Liu b6e30d25f5 Modify trigger callback function. 2021-02-17 12:08:30 +08:00
Benny Liu db8d7bf0af 5V output pin FLT callback function 2021-02-08 17:58:53 +08:00
Benny Liu 48d770b271 trigger callback 2021-02-08 17:49:47 +08:00
Benny Liu 88d1fc0a5e Add trigger sensing pin. 2021-02-08 17:03:11 +08:00
Benny Liu 9769d38897 Update Elite TRIG01 pin. Add trigger sensing pin. 2021-02-08 16:43:37 +08:00
Benny Liu 8be3c30b23 Update Elite TRIG01 pin 2021-02-08 14:17:22 +08:00
16 changed files with 1009 additions and 245 deletions
@@ -144,10 +144,10 @@ static void PIN15_setOutputValue (uint32_t latch_num, uint32_t pin_num, bool hig
// PIN_setOutputValue(&ZM_rst, D1, LH.LATCH0[1]);
// PIN_setOutputValue(&ZM_rst, D2, LH.LATCH0[2]);
// PIN_setOutputValue(&ZM_rst, D3, LH.LATCH0[3]);
PIN_setOutputValue(pin_handle, D4, LH.LATCH0[4]);
PIN_setOutputValue(pin_handle, D5, LH.LATCH0[5]);
PIN_setOutputValue(pin_handle, D6, LH.LATCH0[6]);
PIN_setOutputValue(pin_handle, D7, LH.LATCH0[7]);
// PIN_setOutputValue(pin_handle, D4, LH.LATCH0[4]);
// PIN_setOutputValue(pin_handle, D5, LH.LATCH0[5]);
// PIN_setOutputValue(pin_handle, D6, LH.LATCH0[6]);
// PIN_setOutputValue(pin_handle, D7, LH.LATCH0[7]);
break;
}
case LOAD1: {
@@ -176,9 +176,10 @@ static void PIN15_setOutputValue (uint32_t latch_num, uint32_t pin_num, bool hig
break;
}
}
PIN_setOutputValue(&ZM_rst, latch_num, 1); // Turn on latch
latch_setOutputValue(latch_num, 1); // Turn on latch
// CPUdelay(10);
PIN_setOutputValue(&ZM_rst, latch_num, 0); // Turn off latch
// latch_setOutputValue(latch_num, 0); // Turn off latch
latch_setOutputValue(LOAD0, 1); // set latch at LOAD0 for SPI transfer
remove_elite_pin();
ELITE15_SPI_HOLD();
}
@@ -195,52 +196,88 @@ static void Init_Elite15_PIN () {
PIN_setOutputValue(pin_handle, D5, 0);
PIN_setOutputValue(pin_handle, D6, 0);
PIN_setOutputValue(pin_handle, D7, 0);
PIN_setOutputValue(pin_handle, LOAD0, 0);
PIN_setOutputValue(pin_handle, LOAD1, 1);
PIN_setOutputValue(pin_handle, LOAD2, 1);
latch_setOutputValue(LOAD0, 1);
latch_setOutputValue(LOAD1, 1);
latch_setOutputValue(LOAD2, 1);
CPUdelay(10);
PIN_setOutputValue(pin_handle, LOAD1, 0);
PIN_setOutputValue(pin_handle, LOAD2, 0);
PIN_setOutputValue(pin_handle, D0, 0);
PIN_setOutputValue(pin_handle, D1, 0);
PIN_setOutputValue(pin_handle, D2, 0);
PIN_setOutputValue(pin_handle, D3, 0);
PIN_setOutputValue(pin_handle, D4, 1);
PIN_setOutputValue(pin_handle, D5, 1);
PIN_setOutputValue(pin_handle, D6, 1);
PIN_setOutputValue(pin_handle, D7, 1);
CPUdelay(10);
PIN_setOutputValue(pin_handle, LOAD0, 1);
PIN_setOutputValue(pin_handle, LOAD0, 0);
latch_setOutputValue(LOAD2, 0);
remove_elite_pin();
// InitLH();
// add_elite_pin();
//
// PIN_setOutputValue(pin_handle, LOAD0, 1);
// PIN_setOutputValue(pin_handle, LOAD1, 1);
// PIN_setOutputValue(pin_handle, LOAD2, 1);
// CPUdelay(10);
// PIN_setOutputValue(pin_handle, D0, 0);
// PIN_setOutputValue(pin_handle, D1, 0);
// PIN_setOutputValue(pin_handle, D2, 0);
// PIN_setOutputValue(pin_handle, D3, 0);
// PIN_setOutputValue(pin_handle, D4, 0);
// PIN_setOutputValue(pin_handle, D5, 0);
// PIN_setOutputValue(pin_handle, D6, 0);
// PIN_setOutputValue(pin_handle, D7, 0);
// CPUdelay(10);
// PIN_setOutputValue(pin_handle, LOAD0, 0);
// PIN_setOutputValue(pin_handle, LOAD1, 0);
// PIN_setOutputValue(pin_handle, LOAD2, 0);
//
// remove_elite_pin();
}
static void latch_setOutputValue (uint32_t latch_num, bool highlow) {
// decode latch value for Elite trigger board
if (highlow) {
switch (latch_num) {
case LOAD0: {
PIN_setOutputValue(pin_handle, LOADB, 0);
PIN_setOutputValue(pin_handle, LOADA, 0);
break;
}
case LOAD1: {
PIN_setOutputValue(pin_handle, LOADB, 0);
PIN_setOutputValue(pin_handle, LOADA, 1);
break;
}
case LOAD2: {
PIN_setOutputValue(pin_handle, LOADB, 1);
PIN_setOutputValue(pin_handle, LOADA, 0);
break;
}
default: {
break;
}
}
} else { // All latch turn off
PIN_setOutputValue(pin_handle, LOADB, 1);
PIN_setOutputValue(pin_handle, LOADA, 1);
// PIN_setPortOutputValue(pin_handle, ((1<<LOADA)|(1<<LOADB)));
}
}
static void PIN15_setOutputValue_refresh() {
ELITE15_SPI_CLOSE();
add_elite_pin();
PIN_setOutputValue(pin_handle, D0, LH.LATCH1[0]);
PIN_setOutputValue(pin_handle, D1, LH.LATCH1[1]);
PIN_setOutputValue(pin_handle, D2, LH.LATCH1[2]);
PIN_setOutputValue(pin_handle, D3, LH.LATCH1[3]);
PIN_setOutputValue(pin_handle, D4, LH.LATCH1[4]);
PIN_setOutputValue(pin_handle, D5, LH.LATCH1[5]);
PIN_setOutputValue(pin_handle, D6, LH.LATCH1[6]);
PIN_setOutputValue(pin_handle, D7, LH.LATCH1[7]);
latch_setOutputValue(LOAD1, 1); // Turn on latch
latch_setOutputValue(LOAD0, 1); // set latch at LOAD0 for SPI transfer
PIN_setOutputValue(pin_handle, D0, LH.LATCH2[0]);
PIN_setOutputValue(pin_handle, D1, LH.LATCH2[1]);
PIN_setOutputValue(pin_handle, D2, LH.LATCH2[2]);
PIN_setOutputValue(pin_handle, D3, LH.LATCH2[3]);
PIN_setOutputValue(pin_handle, D4, LH.LATCH2[4]);
PIN_setOutputValue(pin_handle, D5, LH.LATCH2[5]);
PIN_setOutputValue(pin_handle, D6, LH.LATCH2[6]);
PIN_setOutputValue(pin_handle, D7, LH.LATCH2[7]);
latch_setOutputValue(LOAD2, 1); // Turn on latch
latch_setOutputValue(LOAD0, 1); // set latch at LOAD0 for SPI transfer
remove_elite_pin();
ELITE15_SPI_HOLD();
}
static void disable_trig_output() {
update_latch_status(DO_PR_0 , 0);
update_latch_status(DO_MOS_0 , 0);
update_latch_status(AO_MOS_0 , 0);
update_latch_status(AO_MOS_2 , 0);
update_latch_status(AO_MOS_3 , 0);
update_latch_status(AO_MOS_1 , 0);
update_latch_status(DO_MOS_1 , 0);
update_latch_status(DO_PR_1 , 0);
update_latch_status(OUT_5V_EN_0, 1);
update_latch_status(OUT_5V_EN_1, 1);
PIN15_setOutputValue_refresh();
}
#endif
@@ -13,12 +13,24 @@
#define CMD_DAC_MEASURE 0xE5
#define CMD_BATTERY_MEASURE 0xF1
// Elite TRIG01 ADC command
#define CMD_DOUT_5V_IMON_0 0xC5
#define CMD_DOUT_5V_IMON_1 0xD5
//#define CMD_DAC_MEASURE 0xE5 // ADC AIN2 left floating
#define CMD_BATTERY_MEASURE 0xF1
// controller command, these are command from control box
#define ADC_CH_CURRENT 0x00
#define ADC_CH_VOLT 0x01
#define ADC_CH_DAC 0x02
#define ADC_CH_BAT 0x03
#define Aout_CH_0 0x00
#define Aout_CH_1 0x01
#define Aout_CH_2 0x02
#define Aout_CH_3 0x03
static void ADC_write(uint8_t ADCin) {
/*
* This function can only define [15]~[8] through ADCin
@@ -82,82 +94,82 @@ static void CAL_ADC_write(uint8_t ADCin) {
/* Gain Control for Vin & Iin */
static void IinADCGainControl(uint8_t IinADCLevel){
if(IinADCLevel == 0){
// ADC gain level = 0, using 3M resister
PIN15_setOutputValue(Turnon_I_LARGE, 0);
PIN15_setOutputValue(Turnon_I_MID, 0);
PIN15_setOutputValue(Turnon_I_SMALL, 0);
}
else if(IinADCLevel == 1){
// ADC gain level = 1, using 100K resister
PIN15_setOutputValue(Turnon_I_LARGE, 0);
PIN15_setOutputValue(Turnon_I_MID, 0);
PIN15_setOutputValue(Turnon_I_SMALL, 1);
}
else if(IinADCLevel == 2){
// ADC gain level = 2, using 3K resister
PIN15_setOutputValue(Turnon_I_LARGE, 0);
PIN15_setOutputValue(Turnon_I_MID, 1);
PIN15_setOutputValue(Turnon_I_SMALL, 0);
}
else if(IinADCLevel == 3){
// ADC gain level = 3, using 100R resistor
PIN15_setOutputValue(Turnon_I_LARGE, 1);
PIN15_setOutputValue(Turnon_I_MID, 0);
PIN15_setOutputValue(Turnon_I_SMALL, 0);
}
else if(IinADCLevel == 4){
// ADC gain level = 3, auto gain (using 100R resister)
PIN15_setOutputValue(Turnon_I_LARGE, 1);
PIN15_setOutputValue(Turnon_I_MID, 0);
PIN15_setOutputValue(Turnon_I_SMALL, 0);
}
else{
// default using 100R resister
PIN15_setOutputValue(Turnon_I_LARGE, 1);
PIN15_setOutputValue(Turnon_I_MID, 0);
PIN15_setOutputValue(Turnon_I_SMALL, 0);
}
if(IinADCLevel == 0 || IinADCLevel == 1 || IinADCLevel == 2 || IinADCLevel == 3){
lastIinADCGainLevel = IinADCLevel;
}else{
lastIinADCGainLevel = 3;
}
// if(IinADCLevel == 0){
// // ADC gain level = 0, using 3M resister
// PIN15_setOutputValue(Turnon_I_LARGE, 0);
// PIN15_setOutputValue(Turnon_I_MID, 0);
// PIN15_setOutputValue(Turnon_I_SMALL, 0);
// }
// else if(IinADCLevel == 1){
// // ADC gain level = 1, using 100K resister
// PIN15_setOutputValue(Turnon_I_LARGE, 0);
// PIN15_setOutputValue(Turnon_I_MID, 0);
// PIN15_setOutputValue(Turnon_I_SMALL, 1);
// }
// else if(IinADCLevel == 2){
// // ADC gain level = 2, using 3K resister
// PIN15_setOutputValue(Turnon_I_LARGE, 0);
// PIN15_setOutputValue(Turnon_I_MID, 1);
// PIN15_setOutputValue(Turnon_I_SMALL, 0);
// }
// else if(IinADCLevel == 3){
// // ADC gain level = 3, using 100R resistor
// PIN15_setOutputValue(Turnon_I_LARGE, 1);
// PIN15_setOutputValue(Turnon_I_MID, 0);
// PIN15_setOutputValue(Turnon_I_SMALL, 0);
// }
// else if(IinADCLevel == 4){
// // ADC gain level = 3, auto gain (using 100R resister)
// PIN15_setOutputValue(Turnon_I_LARGE, 1);
// PIN15_setOutputValue(Turnon_I_MID, 0);
// PIN15_setOutputValue(Turnon_I_SMALL, 0);
// }
// else{
// // default using 100R resister
// PIN15_setOutputValue(Turnon_I_LARGE, 1);
// PIN15_setOutputValue(Turnon_I_MID, 0);
// PIN15_setOutputValue(Turnon_I_SMALL, 0);
// }
//
// if(IinADCLevel == 0 || IinADCLevel == 1 || IinADCLevel == 2 || IinADCLevel == 3){
// lastIinADCGainLevel = IinADCLevel;
// }else{
// lastIinADCGainLevel = 3;
// }
}
static void VinADCGainControl(uint8_t VinADCLevel){
if(VinADCLevel == 0){
// Vin ADC gain level = 0, using 1M resister
PIN15_setOutputValue(Turnon_V_SMALL, 0);
PIN15_setOutputValue(Turnon_V_MID, 0);
}
else if(VinADCLevel == 1){
// Vin ADC gain level = 1, using 30K resister
PIN15_setOutputValue(Turnon_V_SMALL, 0);
PIN15_setOutputValue(Turnon_V_MID, 1);
}
else if(VinADCLevel == 2){
// Vin ADC gain level = 2, using 1K resister
PIN15_setOutputValue(Turnon_V_SMALL, 1);
PIN15_setOutputValue(Turnon_V_MID, 0);
}
else if(VinADCLevel == 3){
// Vin ADC gain level = 3, auto gain (using 1K resister)
PIN15_setOutputValue(Turnon_V_SMALL, 1);
PIN15_setOutputValue(Turnon_V_MID, 0);
}
else{
// default using 1K resister
PIN15_setOutputValue(Turnon_V_SMALL, 1);
PIN15_setOutputValue(Turnon_V_MID, 0);
}
if(VinADCLevel == 0 || VinADCLevel == 1 || VinADCLevel == 2){
lastVinADCGainLevel = VinADCLevel;
}else{
lastVinADCGainLevel = 2;
}
// if(VinADCLevel == 0){
// // Vin ADC gain level = 0, using 1M resister
// PIN15_setOutputValue(Turnon_V_SMALL, 0);
// PIN15_setOutputValue(Turnon_V_MID, 0);
// }
// else if(VinADCLevel == 1){
// // Vin ADC gain level = 1, using 30K resister
// PIN15_setOutputValue(Turnon_V_SMALL, 0);
// PIN15_setOutputValue(Turnon_V_MID, 1);
// }
// else if(VinADCLevel == 2){
// // Vin ADC gain level = 2, using 1K resister
// PIN15_setOutputValue(Turnon_V_SMALL, 1);
// PIN15_setOutputValue(Turnon_V_MID, 0);
// }
// else if(VinADCLevel == 3){
// // Vin ADC gain level = 3, auto gain (using 1K resister)
// PIN15_setOutputValue(Turnon_V_SMALL, 1);
// PIN15_setOutputValue(Turnon_V_MID, 0);
// }
// else{
// // default using 1K resister
// PIN15_setOutputValue(Turnon_V_SMALL, 1);
// PIN15_setOutputValue(Turnon_V_MID, 0);
// }
//
// if(VinADCLevel == 0 || VinADCLevel == 1 || VinADCLevel == 2){
// lastVinADCGainLevel = VinADCLevel;
// }else{
// lastVinADCGainLevel = 2;
// }
}
static void ADCChannelSelect(uint8_t ADCChannel){
@@ -603,4 +615,97 @@ static uint16_t ADC_CURRENT_AVG_calibration (uint8_t ADC_channel) {
return ADCValueAVG_RAW;
}
/* use GPIO to control TW1508 */
static void GPIO_SPI_write(uint8_t GPIO_channel, uint16_t GPIOin) {
/*
Iout = 1.25/680 * ([9:7] +1)/8 * [6:0]
*/
static uint32_t TW_CH_0 [2] = {TW_SCKI_0};
static uint32_t TW_CH_1 [2] = {TW_SCKI_1};
static uint32_t TW_CH_2 [2] = {TW_SCKI_2};
static uint32_t TW_CH_3 [2] = {TW_SCKI_3};
uint32_t CLK_CH[2] = {0};
spi_GPIO_txbuf = 0;
static bool trans_valid = false;
switch (GPIO_channel) {
case Aout_CH_0: {
CLK_CH[0] = TW_CH_0[0];
CLK_CH[1] = TW_CH_0[1];
trans_valid = true;
break;
}
case Aout_CH_1: {
CLK_CH[0] = TW_CH_1[0];
CLK_CH[1] = TW_CH_1[1];
trans_valid = true;
break;
}
case Aout_CH_2: {
CLK_CH[0] = TW_CH_2[0];
CLK_CH[1] = TW_CH_2[1];
trans_valid = true;
break;
}
case Aout_CH_3: {
CLK_CH[0] = TW_CH_3[0];
CLK_CH[1] = TW_CH_3[1];
trans_valid = true;
break;
}
default: {
trans_valid = false;
break;
}
}
/* GPIOin = 0x0000 ~ 0x03FF */
spi_GPIO_txbuf = GPIOin;
if (trans_valid) {
GPIO_SPI_transfer(CLK_CH, spi_GPIO_txbuf);
trans_valid = false;
}
}
static void AoutChannelSelect(uint8_t Aout_channel, bool on_off) {
switch (Aout_channel) {
case Aout_CH_0: {
PIN15_setOutputValue(AO_MOS_0, on_off);
break;
}
case Aout_CH_1: {
PIN15_setOutputValue(AO_MOS_1, on_off);
break;
}
case Aout_CH_2: {
PIN15_setOutputValue(AO_MOS_2, on_off);
break;
}
case Aout_CH_3: {
PIN15_setOutputValue(AO_MOS_3, on_off);
break;
}
case 0xFF :{ // output all off or on
PIN15_setOutputValue(AO_MOS_0, on_off);
PIN15_setOutputValue(AO_MOS_1, on_off);
PIN15_setOutputValue(AO_MOS_2, on_off);
PIN15_setOutputValue(AO_MOS_3, on_off);
}
default: {
break;
}
}
}
static void TW1508reset() {
GPIO_SPI_write(Aout_CH_0, 0x0000);
GPIO_SPI_write(Aout_CH_1, 0x0000);
GPIO_SPI_write(Aout_CH_2, 0x0000);
GPIO_SPI_write(Aout_CH_3, 0x0000);
}
#endif
@@ -51,7 +51,7 @@ static uint16_t DAC_outputV(uint16_t voltLV) {
spi_DACtxbuf[1] = v1;
spi_DACtxbuf[2] = v2;
DAC_SPI(SPI_DAC_SIZE, spi_DACtxbuf, spi_rxbuf);
// DAC_SPI(SPI_DAC_SIZE, spi_DACtxbuf, spi_rxbuf);
return voltLV;
}
@@ -59,19 +59,19 @@ static uint16_t DAC_outputV(uint16_t voltLV) {
static void VoutGainControl(uint8_t VOUTLevel){
if(VOUTLevel == 0){
// VOUT gain level = 0, using 240K resister
PIN15_setOutputValue(Turon_VOUT_SMALL, 0);
// PIN15_setOutputValue(Turon_VOUT_SMALL, 0);
}
else if(VOUTLevel == 1){
// VOUT gain level = 1, using 15K resister
PIN15_setOutputValue(Turon_VOUT_SMALL, 1);
// PIN15_setOutputValue(Turon_VOUT_SMALL, 1);
}
else if(VOUTLevel == 2){
// VOUT gain level = 2, using 15K resister
PIN15_setOutputValue(Turon_VOUT_SMALL, 1);
// PIN15_setOutputValue(Turon_VOUT_SMALL, 1);
}
else{
// default using 15K resister
PIN15_setOutputValue(Turon_VOUT_SMALL, 1);
// PIN15_setOutputValue(Turon_VOUT_SMALL, 1);
}
}
@@ -8,6 +8,13 @@
#define VOUT_DAC 0x02
#define HIGH_Z 0x03
/** TRIG01 AOUT, DOUT, PROUT **/
#define AOUT_ADC 0x00
#define DOUT_ADC 0x01
#define PR_DAC 0x02
#define LEDtest 0x03
#define OUT_5V_EN 0x04
/** ADC Iin gain level **/
#define I_GAIN_3M 0x00 // largest gain
#define I_GAIN_100K 0x01
@@ -96,6 +103,22 @@ struct HEADSTAGE_INSTRUCTION {
uint8_t AdcChannel;
/** TRIG chan **/
bool tri_pr0;
bool tri_d0;
bool tri_a0;
bool tri_a2;
bool tri_a3;
bool tri_a1;
bool tri_d1;
bool tri_pr1;
bool output_5v_en0;
bool output_5v_en1;
/** trigger mode enable **/
bool trig0_en;
bool trig1_en;
} INSTRUCTION = {0};
/*********************************************************************
@@ -155,5 +178,16 @@ static void InitEliteInstruction(){
INSTRUCTION.sti_v7 = DAC_ZERO;
INSTRUCTION.sti_loop = 1;
INSTRUCTION.sti_cy = 0;
INSTRUCTION.tri_pr0 = 0;
INSTRUCTION.tri_pr1 = 0;
INSTRUCTION.tri_a0 = 0;
INSTRUCTION.tri_a1 = 0;
INSTRUCTION.tri_a2 = 0;
INSTRUCTION.tri_a3 = 0;
INSTRUCTION.tri_d0 = 0;
INSTRUCTION.tri_d1 = 0;
INSTRUCTION.output_5v_en0 = 1; // 1 => disable
INSTRUCTION.output_5v_en1 = 1; // 1 => disable
}
#endif
@@ -68,7 +68,7 @@ static void EliteKeyPress(uint8_t key) {
static void TurnOn10V() {
If10Von = true;
PIN15_setOutputValue(enable_10v, 1);
// PIN15_setOutputValue(enable_10v, 1);
CPUdelay(8000);
}
@@ -5,7 +5,20 @@
#define DARKLED 0xE1
#define LIGHTLED 0xE8
/* Channels for TRIG01 LED notation */
#define LED_PR0 0x00
#define LED_D0 0x01
#define LED_A0 0x02
#define LED_A2 0x03
#define LED_A3 0x04
#define LED_A1 0x05
#define LED_D1 0x06
#define LED_PR1 0x07
static void WorkModeLED();
static void update_LED_status (uint8_t chan, uint8_t bright, uint8_t red, uint8_t green, uint8_t blue);
static void SET_LED_CHAN(bool *chan_en, uint16_t modeStatus);
static void refresh_LED();
static void LED_color(uint8_t bright, uint8_t red, uint8_t green, uint8_t blue) {
spi_LEDtxbuf[0] = 0x0000;
@@ -94,12 +107,87 @@ static void Elite_led_color(uint16_t color){
}
}
static void Elite_chan_led_color(uint16_t color, uint8_t chan) {
switch (color) {
case COLOR_RED: {
update_LED_status(chan, DARKLED, 0xFF, 0x00, 0x00);
break;
}
case COLOR_ORANGE: {
update_LED_status(chan, DARKLED, 0xFF, 0x58, 0x09);
break;
}
case COLOR_YELLOW: {
update_LED_status(chan, DARKLED, 0xFF, 0x80, 0x00);
break;
}
case COLOR_GREEN: {
update_LED_status(chan, DARKLED, 0x00, 0xFA, 0x00);
break;
}
case COLOR_YELLOWGREEN: {
update_LED_status(chan, DARKLED, 0x64, 0xA6, 0x00);
break;
}
case COLOR_BLUE: {
update_LED_status(chan, DARKLED, 0x00, 0x00, 0xAA);
break;
}
case COLOR_CYAN: {
update_LED_status(chan, DARKLED, 0x00, 0x40, 0x40);
break;
}
case COLOR_MAGENTA: {
update_LED_status(chan, DARKLED, 0xFF, 0x00, 0x80);
break;
}
case COLOR_PURPLE: {
update_LED_status(chan, DARKLED, 0xFF, 0x00, 0xFF);
break;
}
case COLOR_WHITE: {
update_LED_status(chan, DARKLED, 0xCA, 0xFF, 0xFF);
break;
}
case COLOR_BLACK: {
update_LED_status(chan, 0x00, 0x00, 0x00, 0x00);
break;
}
//dark LED
case COLOR_YELLOW_DARK: {
update_LED_status(chan, DARKLED, 0xFF, 0x80, 0x00);
break;
}
case COLOR_GREEN_DARK: {
update_LED_status(chan, DARKLED, 0x00, 0x33, 0x00);
break;
}
case COLOR_BLUE_DARK: {
update_LED_status(chan, DARKLED, 0x00, 0x00, 0x33);
break;
}
case COLOR_CYAN_DARK: {
update_LED_status(chan, DARKLED, 0x00, 0x10, 0x10);
break;
}
case COLOR_PURPLE_DARK: {
update_LED_status(chan, DARKLED, 0x55, 0x00, 0x55);
break;
}
default: {
break;
}
// refresh_LED();
}
}
static void ModeLED(uint16_t modeStatus) {
btWaitLedFlag = 0;
noEventLedFlag = 0;
preWorkLedFlag = 0;
workingLedFlag = 0;
postWorkLedFlag = 0;
TRIG01workFlag = 0;
switch (modeStatus) {
case BT_WAIT: {
@@ -127,6 +215,12 @@ static void ModeLED(uint16_t modeStatus) {
Elite_led_color(COLOR_BLUE);
break;
}
case TRIG01_WORK: {
TRIG01workFlag = 1;
WorkModeLED();
refresh_LED();
break;
}
default: {
LEDPowerON();
break;
@@ -150,6 +244,9 @@ static void checkFlafLED() {
else if(postWorkLedFlag == 1){
ModeLED(POST_WORK);
}
else if(TRIG01workFlag == 1){
ModeLED(TRIG01_WORK);
}
}
static void WorkModeLED() {
@@ -162,7 +259,10 @@ static void WorkModeLED() {
case ZT_CURVE:
case VT_CURVE:
case IT_CURVE:
case ADC_TEST:
case ADC_TEST:{
SET_LED_CHAN(TRC.chan_en, WORKING);
break;
}
case CYCLIC_VOLTAMMETRY:
case LINEAR_SWEEP_VOLTAMMETRY:
case CONSTANT_VSCAN:{
@@ -198,4 +298,130 @@ static void WorkModeLED() {
}
}
static void LED_channel_write(uint8_t chan, uint8_t bright, uint8_t red, uint8_t green, uint8_t blue) {
update_LED_status(chan, bright, red, green, blue);
refresh_LED();
}
static void update_LED_status (uint8_t chan, uint8_t bright, uint8_t red, uint8_t green, uint8_t blue) {
switch(chan) {
case LED_PR0: {
LED.LED_buf[2] = 0xE000 | ((uint16_t)bright << 8) | blue;
LED.LED_buf[3] = ((uint16_t)green << 8) | red;
break;
}
case LED_D0: {
LED.LED_buf[4] = 0xE000 | ((uint16_t)bright << 8) | blue;
LED.LED_buf[5] = ((uint16_t)green << 8) | red;
break;
}
case LED_A0: {
LED.LED_buf[6] = 0xE000 | ((uint16_t)bright << 8) | blue;
LED.LED_buf[7] = ((uint16_t)green << 8) | red;
break;
}
case LED_A2: {
LED.LED_buf[8] = 0xE000 | ((uint16_t)bright << 8) | blue;
LED.LED_buf[9] = ((uint16_t)green << 8) | red;
break;
}
case LED_A3: {
LED.LED_buf[10] = 0xE000 | ((uint16_t)bright << 8) | blue;
LED.LED_buf[11] = ((uint16_t)green << 8) | red;
break;
}
case LED_A1: {
LED.LED_buf[12] = 0xE000 | ((uint16_t)bright << 8) | blue;
LED.LED_buf[13] = ((uint16_t)green << 8) | red;
break;
}
case LED_D1: {
LED.LED_buf[14] = 0xE000 | ((uint16_t)bright << 8) | blue;
LED.LED_buf[15] = ((uint16_t)green << 8) | red;
break;
}
case LED_PR1: {
LED.LED_buf[16] = 0xE000 | ((uint16_t)bright << 8) | blue;
LED.LED_buf[17] = ((uint16_t)green << 8) | red;
break;
}
default: {
break;
}
}
}
static void refresh_LED() {
spi_LEDtxbuf[0] = 0x0000;
spi_LEDtxbuf[1] = 0x0000;
for (int i = 2; i < SPI_LED_SIZE - 2; i += 2) {
spi_LEDtxbuf[i] = LED.LED_buf[i];
spi_LEDtxbuf[i+1] = LED.LED_buf[i+1];
}
spi_LEDtxbuf[SPI_LED_SIZE - 2] = 0xffff;
spi_LEDtxbuf[SPI_LED_SIZE - 1] = 0xffff;
LED_SPI(SPI_LED_SIZE, spi_LEDtxbuf, spi_LEDrxbuf);
}
static void TRIG_LED_Init() {
spi_LEDtxbuf[0] = 0x0000;
spi_LEDtxbuf[1] = 0x0000;
for (int i = 2; i < SPI_LED_SIZE - 2; i += 2) {
spi_LEDtxbuf[i] = 0xE000;
spi_LEDtxbuf[i+1] = 0x0000;
}
spi_LEDtxbuf[SPI_LED_SIZE - 2] = 0xffff;
spi_LEDtxbuf[SPI_LED_SIZE - 1] = 0xffff;
LED_SPI(SPI_LED_SIZE, spi_LEDtxbuf, spi_LEDrxbuf);
}
static void SET_LED_CHAN(bool *chan_en, uint16_t modeStatus){
uint8_t ledcolor = 0;
switch(modeStatus) {
case NO_EVENT:{
ledcolor = COLOR_GREEN;
break;
}
case WORKING:{
ledcolor = COLOR_CYAN;
break;
}
default:{
ledcolor = COLOR_GREEN;
break;
}
}
uint8_t trig_chan = 0;
for (int i=0; i<TRIG_CHAN_COUNT-2; i++) {
trig_chan = (uint8_t) (i);
if(TRC.chan_en[i]) {
Elite_chan_led_color(ledcolor, trig_chan);
} else {
Elite_chan_led_color(COLOR_BLACK, trig_chan);
}
}
if(!TRC.chan_en[8]) {
Elite_chan_led_color(COLOR_PURPLE_DARK, LED_D0);
} else if(TRC.chan_en[1]) {
Elite_chan_led_color(ledcolor, LED_D0);
} else {
Elite_chan_led_color(COLOR_BLACK, LED_D0); // determine DOUT on or off
}
if(!TRC.chan_en[9]) {
Elite_chan_led_color(COLOR_PURPLE_DARK, LED_D1);
} else if(TRC.chan_en[6]) {
Elite_chan_led_color(ledcolor, LED_D1);
} else {
Elite_chan_led_color(COLOR_BLACK, LED_D1);
}
refresh_LED();
}
#endif
@@ -0,0 +1,14 @@
#ifndef ELITE_LED_INIT
#define ELITE_LED_INIT
static void InitLED() {
for (int i = 2; i < SPI_LED_SIZE - 2; i += 2) {
LED.LED_buf[i] = 0xE000;
LED.LED_buf[i+1] = 0x0000;
}
}
#endif
@@ -10,10 +10,12 @@ static void reset() {
InitCT();
InitGPT();
PIN15_setOutputValue(HIGH_Z_MODE, 1); // 0 => open high_z mode
InitLED();
InitTrigChan();
VinADCGainControl(VIN_GAIN_AUTO);
IinADCGainControl(I_GAIN_AUTO);
disable_trig_output();
INSTRUCTION.VoutGainLevel = VOUT_GAIN_15K;
VoutGainControl(INSTRUCTION.VoutGainLevel);
@@ -22,6 +24,7 @@ static void reset() {
initINSBuf();
initDATBuf();
for (int i = 0; i < SPI_LED_SIZE; i++) {
spi_LEDtxbuf[i] = 0;
spi_LEDrxbuf[i] = 0;
@@ -48,7 +51,7 @@ static void Eliteinterrupt() {
InitCT();
InitGPT();
PIN15_setOutputValue(HIGH_Z_MODE, 1); // 0 => open high_z mode
// PIN15_setOutputValue(HIGH_Z_MODE, 1); // 0 => open high_z mode
INSTRUCTION.VoutGainLevel = VOUT_GAIN_15K;
VoutGainControl(INSTRUCTION.VoutGainLevel);
@@ -15,9 +15,10 @@
#include "Elite_PIN.h"
/* application use SPI parameters and buffers */
#define SPI_LED_SIZE 28
#define SPI_DAC_SIZE 3
#define SPI_ADC_SIZE 4
#define SPI_LED_SIZE LED_BUFF_SIZE
#define SPI_DAC_SIZE 3
#define SPI_ADC_SIZE 4
#define SPI_GPIO_BUFF_SIZE 10
static uint16_t spi_LEDtxbuf[SPI_LED_SIZE] = {0};
static uint16_t spi_LEDrxbuf[SPI_LED_SIZE] = {0};
@@ -28,6 +29,9 @@ static uint8_t spi_rxbuf[SPI_DAC_SIZE] = {0};
static uint8_t spi_ADC_txbuf[SPI_ADC_SIZE] = {0};
static uint8_t spi_ADC_rxbuf[SPI_ADC_SIZE] = {0};
static uint16_t spi_GPIO_txbuf = 0;
static uint16_t SPI_GPIO[SPI_GPIO_BUFF_SIZE] = {0};
/* system use SPI parameters */
static SPI_Handle spiHandle0 = NULL; // SPI0 = LED
static SPI_Handle spiHandle1 = NULL; // SPI1 = ADC +DAC
@@ -66,8 +70,8 @@ static void LED_SPI(uint8_t length, uint16_t *spi_txbuf, uint16_t *spi_rxbuf) {
static void ADC_SPI(uint8_t length, uint8_t *spi_txbuf, uint8_t *spi_rxbuf) {
// PIN15_setOutputValue(ADC_CS, 0); // ADC_CS LOW
PIN_setOutputValue(pin_handle, LOAD0, 1);
PIN_setOutputValue(pin_handle, D6, 0); // ADC_CS LOW
latch_setOutputValue(LOAD0, 1);
// PIN_setOutputValue(pin_handle, D6, 0); // ADC_CS LOW
ADC_DAC_transaction.count = length;
ADC_DAC_transaction.txBuf = spi_txbuf;
@@ -75,38 +79,38 @@ static void ADC_SPI(uint8_t length, uint8_t *spi_txbuf, uint8_t *spi_rxbuf) {
SPI_transfer(spiHandle1, &ADC_DAC_transaction);
PIN_setOutputValue(pin_handle, D6, 1); // ADC_CS HOGH
update_latch_status (ADC_CS, 1);
// PIN_setOutputValue(pin_handle, D6, 1); // ADC_CS HOGH
// update_latch_status (ADC_CS, 1);
// PIN15_setOutputValue(ADC_CS, 1); // ADC_CS HIGH
}
static void DAC_SPI(uint8_t length, uint8_t *spi_txbuf, uint8_t *spi_rxbuf) {
// PIN15_setOutputValue(DAC_CS, 0); // DAC_CS LOW
PIN_setOutputValue(pin_handle, LOAD0, 1);
PIN_setOutputValue(pin_handle, D7, 0); // DAC_CS LOW
ADC_DAC_transaction.count = length;
ADC_DAC_transaction.txBuf = spi_txbuf;
ADC_DAC_transaction.rxBuf = spi_rxbuf;
SPI_transfer(spiHandle1, &ADC_DAC_transaction);
PIN_setOutputValue(pin_handle, D7, 1); // DAC_CS HOGH
update_latch_status (DAC_CS, 1);
// PIN_setOutputValue(pin_handle, LOAD0, 1);
// PIN_setOutputValue(pin_handle, D7, 0); // DAC_CS LOW
//
// ADC_DAC_transaction.count = length;
// ADC_DAC_transaction.txBuf = spi_txbuf;
// ADC_DAC_transaction.rxBuf = spi_rxbuf;
//
// SPI_transfer(spiHandle1, &ADC_DAC_transaction);
//
// PIN_setOutputValue(pin_handle, D7, 1); // DAC_CS HOGH
// update_latch_status (DAC_CS, 1);
// PIN15_setOutputValue(DAC_CS, 1); // DAC_CS HIGH
}
static void ELITE15_SPI_HOLD() {
static void ELITE15_SPI_HOLD() {
Elite_SPI_init();
PIN_setOutputValue(pin_handle, LOAD0, 1);
PIN_setOutputValue(pin_handle, LOAD1, 0);
PIN_setOutputValue(pin_handle, LOAD2, 0);
// PIN_setOutputValue(pin_handle, LOADA, 0); // Turn on LATCH0
// PIN_setOutputValue(pin_handle, LOADB, 0);
PIN_setPortOutputValue(pin_handle, 0); // stay at LOAD0
}
static void ELITE15_SPI_CLOSE() {
PIN_setOutputValue(pin_handle, LOAD0, 0);
PIN_setOutputValue(pin_handle, LOAD1, 0);
PIN_setOutputValue(pin_handle, LOAD2, 0);
// PIN_setOutputValue(pin_handle, LOADB, 1); // Turn off all LATCH
// PIN_setOutputValue(pin_handle, LOADA, 1);
PIN_setPortOutputValue(pin_handle, 0); // stay at LOAD0
SPI_close(spiHandle0);
SPI_close(spiHandle1);
@@ -115,8 +119,8 @@ static void ELITE15_SPI_CLOSE() {
/* Elite1.5 Calibration SPI */
static void CAL_ADC_SPI(uint8_t length, uint8_t *spi_txbuf, uint8_t *spi_rxbuf) {
// PIN15_setOutputValue(ADC_CS, 0); // ADC_CS LOW
PIN_setOutputValue(pin_handle, LOAD0, 1);
PIN_setOutputValue(pin_handle, D6, 0); // ADC_CS LOW
latch_setOutputValue(LOAD0, 1);
// PIN_setOutputValue(pin_handle, D6, 0); // ADC_CS LOW
ADC_DAC_transaction.count = length;
ADC_DAC_transaction.txBuf = spi_txbuf;
@@ -124,9 +128,47 @@ static void CAL_ADC_SPI(uint8_t length, uint8_t *spi_txbuf, uint8_t *spi_rxbuf)
SPI_transfer(spiHandle1, &ADC_DAC_transaction);
PIN_setOutputValue(pin_handle, D6, 1); // ADC_CS HOGH
update_latch_status (ADC_CS, 1);
// PIN_setOutputValue(pin_handle, D6, 1); // ADC_CS HIGH
// update_latch_status (ADC_CS, 1);
// PIN15_setOutputValue(ADC_CS, 1); // ADC_CS HIGH
}
static void GPIO_SPI_transfer(uint32_t *GPIO_CLK_CH, uint16_t spi_GPIO_txbuf) {
for (int i=0; i<SPI_GPIO_BUFF_SIZE; i++) {
SPI_GPIO[i] = 0;
}
SPI_GPIO[0] = (spi_GPIO_txbuf & 0b0000000000000001); // MOSI
SPI_GPIO[1] = (spi_GPIO_txbuf & 0b0000000000000010);
SPI_GPIO[2] = (spi_GPIO_txbuf & 0b0000000000000100);
SPI_GPIO[3] = (spi_GPIO_txbuf & 0b0000000000001000);
SPI_GPIO[4] = (spi_GPIO_txbuf & 0b0000000000010000);
SPI_GPIO[5] = (spi_GPIO_txbuf & 0b0000000000100000);
SPI_GPIO[6] = (spi_GPIO_txbuf & 0b0000000001000000);
SPI_GPIO[7] = (spi_GPIO_txbuf & 0b0000000010000000);
SPI_GPIO[8] = (spi_GPIO_txbuf & 0b0000000100000000);
SPI_GPIO[9] = (spi_GPIO_txbuf & 0b0000001000000000);
ELITE15_SPI_CLOSE();
PIN_setPortOutputValue(pin_handle, 0); // Turn on LATCH0
add_elite_pin();
for (int i=9; i>=0; i--) {
PIN_setOutputValue(pin_handle, GPIO_CLK_CH[1], 0); // generate clk signal
PIN_setOutputValue(pin_handle, D3, SPI_GPIO[i]); // data transfer at rising edge, MOSI = D3
PIN_setOutputValue(pin_handle, GPIO_CLK_CH[1], 1); // generate clk signal
}
PIN_setOutputValue(pin_handle, GPIO_CLK_CH[1], 0);
update_latch_status (GPIO_CLK_CH[0], GPIO_CLK_CH[1], 0);
PIN_setOutputValue(pin_handle, D3, 0);
update_latch_status (ADC_SPI_MOSI, 0);
// PIN_setPortOutputValue(pin_handle, 0); // set all LATCH0 pin to LOW
remove_elite_pin();
ELITE15_SPI_HOLD();
}
#endif // ELITE_SPI
@@ -26,28 +26,35 @@
#define D6 IOID_9
#define D7 IOID_10
#define LOAD0 IOID_13
#define LOAD1 IOID_12
#define LOAD2 IOID_11
#define LOADB IOID_12
#define LOADA IOID_11
#define ADC_CS LOAD0, D6
#define DAC_CS LOAD0, D7
#define ADC_DAC_SPI_MOSI LOAD0, D3
#define ADC_DAC_SPI_CLK LOAD0, D2
#define TW_SCKI_2 LOAD0, D6
#define TW_SCKI_3 LOAD0, D7
#define ADC_SPI_MOSI LOAD0, D3
#define ADC_SPI_CLK LOAD0, D2
#define LED_MOSI LOAD0, D1
#define LED_CLK LOAD0, D0
#define MEM_HOLD LOAD0, D4
#define MEM_CS LOAD0, D5
#define TW_SCKI_0 LOAD0, D4
#define TW_SCKI_1 LOAD0, D5
#define Turnon_I_MID LOAD2, D0
#define Turnon_I_SMALL LOAD2, D4
#define Turnon_I_LARGE LOAD2, D1
#define Turnon_V_SMALL LOAD2, D2
#define Turnon_V_MID LOAD2, D3
#define Turon_VOUT_SMALL LOAD2, D7
#define BAT_CHAR LOAD1, D0
#define BAT_OK LOAD1, D1
#define PULLUP_3V_0 LOAD1, D2
#define PULLUP_3V_1 LOAD1, D3
#define shutdown_6994 LOAD1, D4
#define OUT_5V_EN_0 LOAD1, D5
#define enable_5v LOAD1, D6
#define OUT_5V_EN_1 LOAD1, D7
//#define Turnon10K Turnon_I_MID
//#define Turnon200R Turnon_I_LARGE
#define DO_MOS_0 LOAD2, D0
#define DO_MOS_1 LOAD2, D1
#define AO_MOS_0 LOAD2, D2
#define AO_MOS_1 LOAD2, D3
#define AO_MOS_2 LOAD2, D4
#define AO_MOS_3 LOAD2, D5
#define DO_PR_0 LOAD2, D6
#define DO_PR_1 LOAD2, D7
/* I2C */
#ifdef ELITE_VERSION_1_4
@@ -55,11 +62,14 @@
#define Board_I2C0_SDA0 PIN_UNASSIGNED
#endif
#define shutdown_6994 LOAD2, D6
#define switch_on IOID_14
#define HIGH_Z_MODE LOAD2, D5
#define enable_10v LOAD1, D5
#define enable_5v LOAD1, D6
#define FLT IOID_13
#define TRIG_0 IOID_0
#define TRIG_1 IOID_2
#define LOAD0 0x00000000
#define LOAD1 0x00000001
#define LOAD2 0x00000002
PIN_Handle pin_handle;
static PIN_State ZM_rst;
@@ -69,16 +79,19 @@ const PIN_Config BLE_IO[] = {
// D1 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
// D2 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
// D3 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
D4 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
D5 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
D6 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
D7 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
// D4 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
// D5 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
// D6 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
// D7 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
LOAD0 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
LOAD1 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
LOAD2 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
LOADA | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
LOADB | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
switch_on | PIN_INPUT_EN | PIN_PULLDOWN, // to sense switch
switch_on | PIN_GPIO_OUTPUT_DIS | PIN_INPUT_EN | PIN_PULLDOWN, // to sense switch
TRIG_0 | PIN_GPIO_OUTPUT_DIS | PIN_INPUT_EN | PIN_PULLDOWN,
TRIG_1 | PIN_GPIO_OUTPUT_DIS | PIN_INPUT_EN | PIN_PULLDOWN,
FLT | PIN_GPIO_OUTPUT_DIS | PIN_INPUT_EN | PIN_PULLDOWN,
PIN_TERMINATE
};
@@ -93,15 +106,29 @@ static void add_elite_pin() {
D2 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL);
PIN_add(pin_handle,
D3 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL);
PIN_add(pin_handle,
D4 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL);
PIN_add(pin_handle,
D5 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL);
PIN_add(pin_handle,
D6 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL);
PIN_add(pin_handle,
D7 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL);
// if(elite15_status != PIN_SUCCESS) {
// LED_color(DARKLED, 0x0F, 0x0F, 0x0F);
// }
}
static void trig_callback(PIN_Handle handle, PIN_Id pinId);
static void remove_elite_pin() {
PIN_close(pin_handle);
pin_handle = PIN_open(&ZM_rst, BLE_IO);
PIN_registerIntCb(pin_handle, trig_callback);
PIN_setInterrupt(pin_handle, TRIG_0 | PIN_IRQ_NEGEDGE);
PIN_setInterrupt(pin_handle, TRIG_1 | PIN_IRQ_NEGEDGE);
PIN_setInterrupt(pin_handle, FLT | PIN_IRQ_NEGEDGE);
}
/*!
@@ -0,0 +1,107 @@
#ifndef ELITETRIG
#define ELITETRIG
static bool trig0_event_wait = false;
static bool trig1_event_wait = false;
static void set_output_enable(bool *out_chan);
static void InitTrigChan () {
for(int i=0; i<TRIG_CHAN_COUNT; i++) {
TRC.chan_en[i] = 0;
}
}
static void trig_en_check( ) {
if (INSTRUCTION.trig0_en) {
trig0_event_wait = true;
INSTRUCTION.trig0_en = 0;
} else if (INSTRUCTION.trig1_en) {
trig1_event_wait = true;
INSTRUCTION.trig1_en = 0;
}
}
static void FLT_sense( ) {
bool FLT_value = true;
FLT_value = PIN_getInputValue(FLT);
if(!FLT_value) { // if FLT = LOW, disable all output
// PIN15_setOutputValue(OUT_5V_EN_0, 1);
// PIN15_setOutputValue(OUT_5V_EN_1, 1);
// set_output_enable(allDisable);
} else {
PIN15_setOutputValue_refresh();
}
}
static void trig_sense( ) {
if (Trig_receive) {
Trig_receive = false;
if (trig0_event) {
trig0_event = false;
trig0_event_wait = true;
} else if (trig1_event) {
trig1_event = false;
trig1_event_wait = true;
} else if (FLT_event) {
FLT_event = false;
FLT_sense();
}
}
if (trig0_event_wait && trig1_event_wait) { // both channel are triggered
trig0_event_wait = false;
trig1_event_wait = false;
if(TRIG_TrigEnable && INSTRUCTION.eliteFxn == PULSE_MODE) {
trig_PeriodicEvent = true;
}
}
}
static void trig_callback(PIN_Handle handle, PIN_Id pinId) {
if(TRIG_TrigEnable && INSTRUCTION.eliteFxn == PULSE_MODE) {
// trig_PeriodicEvent = true;
Trig_receive = true;
}
// PIN15_setOutputValue(MEGA_G_LED, 1);
// PIN15_setOutputValue(MEGA_G_LED, 1);
switch (pinId) {
case TRIG_0: {
trig0_event = true;
break;
}
case TRIG_1: {
trig1_event = true;
break;
}
case FLT:{
FLT_event = true;
break;
}
default: {
break;
}
}
}
static void set_output_enable(bool *out_chan) {
update_latch_status(DO_PR_0 , out_chan[0]);
update_latch_status(DO_MOS_0 , out_chan[1]);
update_latch_status(AO_MOS_0 , out_chan[2]);
update_latch_status(AO_MOS_2 , out_chan[3]);
update_latch_status(AO_MOS_3 , out_chan[4]);
update_latch_status(AO_MOS_1 , out_chan[5]);
update_latch_status(DO_MOS_1 , out_chan[6]);
update_latch_status(DO_PR_1 , out_chan[7]);
update_latch_status(OUT_5V_EN_0, out_chan[8]);
update_latch_status(OUT_5V_EN_1, out_chan[9]);
PIN15_setOutputValue_refresh();
}
#endif
@@ -84,8 +84,14 @@ static void measureBat(){
uint16_t bat = ((uint16_t)(NotifyVoltBat[2]) << 8 & 0xFF00 ) |
((uint16_t)(NotifyVoltBat[3]) & 0x00FF);
if( bat < 768 && bat > 20){
if( bat < 768 && bat > 20){ // 768 = 3V
PIN15_setOutputValue(enable_5v, 0);
} else if (bat < 1070){ // 1075 = 4.2V
PIN15_setOutputValue(BAT_CHAR, 1);
PIN15_setOutputValue(BAT_OK, 0);
} else if (bat >= 1075){
PIN15_setOutputValue(BAT_CHAR, 0);
PIN15_setOutputValue(BAT_OK, 1);
}
}
@@ -18,6 +18,7 @@
#define VIS_DEVICE_SHINY 0x10
#define VIS_SHINY_DIS 0x20
#define VIS_CC_ZERO 0x40
#define VIS_TRIG_EN 0x41
// RIS (real instruction)
#define IV_CURVE 0x10
@@ -27,7 +28,8 @@
#define VT_CURVE 0x50
#define IT_CURVE 0x60
#define SET_SAMPLE_RATE 0x70
#define SET_ADC_DAC_GAIN 0x80
#define SET_ADC_DAC_GAIN 0x80
#define SET_EN_CHAN 0x81
#define DIFFERENTIAL_PULSE_VOLTAMMETRY 0xA0
#define SQUARE_WAVE_VOLTAMMETRY 0xB0
#define CYCLIC_VOLTAMMETRY 0xC0
@@ -95,12 +97,23 @@
#define KEYLED() Elite_led_color(COLOR_YELLOW)
#define BT_WAIT_LED() Elite_led_color(COLOR_YELLOWGREEN)
/* TRIG01 define */
#define PR_0 0x00
#define MOS_D0 0x01
#define MOS_A0 0x02
#define MOS_A2 0x03
#define MOS_A3 0x04
#define MOS_A1 0x05
#define MOS_D1 0x06
#define PR_1 0x07
#define TRIG_CHAN_COUNT 10 // channel count of TRIG01
#define BT_WAIT 0x01
#define NO_EVENT 0x02
#define PRE_WORK 0x03
#define WORKING 0x04
#define POST_WORK 0x05
#define TRIG01_WORK 0x06
#define VALUE_ZERO_TO_ONE(_v) (_v == 0) ? 1 : _v
#endif
@@ -489,6 +489,14 @@ struct _LH{
static void InitLH();
static void Init_Elite15_PIN();
/**
* LED initialize for TRIG01
*/
#define LED_BUFF_SIZE 20 // Elite = 28; TRIG01 = 20
struct _LED{
uint16_t LED_buf[LED_BUFF_SIZE];
} LED= {0};
static void InitLED();
static Clock_Struct periodicClock;
static bool PeriodicEvent = false;
@@ -497,6 +505,23 @@ static bool megaStiEnable = false;
static ICall_Semaphore semaphore;
static uint16_t events;
/**
* Trigger channel initialize
*/
struct _TRC{ // Trigger Channel
bool chan_en[TRIG_CHAN_COUNT];
} TRC= {0};
static void InitTrigChan();
/* Trigger Flag */
static bool trig_PeriodicEvent = false;
static bool TRIG_TrigEnable = false;
static bool Trig_receive = false;
static bool trig0_event = false;
static bool trig1_event = false;
static bool FLT_event = false;
/*=====================================
==== headstage function prototype ====
====================================*/
@@ -576,6 +601,7 @@ static bool noEventLedFlag = 0;
static bool preWorkLedFlag = 0;
static bool workingLedFlag = 0;
static bool postWorkLedFlag = 0;
static bool TRIG01workFlag = 0;
static void update_latch_status (uint32_t latch_num, uint32_t elite_pin, bool highlow);
@@ -585,10 +611,13 @@ static void headstage_battery_volt();
static void EliteADCBattery();
static void VinADCGainControl(uint8_t VinADCLevel);
static void VoutGainControl(uint8_t VOUTLevel);
static void PIN15_setOutputValue (uint32_t latch_num, uint32_t pin_num, bool highlow);
static void latch_setOutputValue (uint32_t latch_num, bool highlow);
static void PIN15_setOutputValue (uint32_t latch_num, uint32_t pin_num, bool highlow);
// Elite key detection & turn on/ shutdown function (peripheral hardware control)
static void Elite_led_color(uint16_t color);
static void Elite_chan_led_color(uint16_t color, uint8_t chan);
static void ModeLED(uint16_t modeStatus);
//static void LED_color(uint8_t bright, uint8_t red, uint8_t green, uint8_t blue);
static bool If10Von = false;
@@ -637,6 +666,7 @@ static void InitEliteFlag();
#include "EliteNotify.h"
#include "EliteFlagCTInit.h"
#include "EliteLatchInit.h"
#include "EliteLEDInit.h"
#include "EliteReset.h"
#include "EliteLED.h"
#include "EliteKeyDetect.h"
@@ -646,6 +676,7 @@ static void InitEliteFlag();
#include "EliteCVCurve.h"
#include "EliteZTCurve.h"
#include "EliteCCCMode.h"
#include "Elite_TRIG.h"
#include "impedance_meter.h"
#include "Elite_version.h"
#include "EliteCV3Mode.h"
@@ -668,7 +699,7 @@ static void update_ZM_instruction(uint8 *ins) {
switch (ins[2]) {
case IV_CURVE: {
ModeLED(WORKING);
PIN15_setOutputValue(HIGH_Z_MODE, 1); // 1 => close high_z mode
// PIN15_setOutputValue(HIGH_Z_MODE, 1); // 1 => close high_z mode
INSTRUCTION.eliteFxn = IV_CURVE;
INSTRUCTION.sampleRate = 15;
INSTRUCTION.Ve1 = ((uint16_t)(ins[3]) << 8) | (uint16_t)(ins[4]);
@@ -697,7 +728,7 @@ static void update_ZM_instruction(uint8 *ins) {
case CV_CURVE: {
ModeLED(WORKING);
PIN15_setOutputValue(HIGH_Z_MODE, 1); // 1 => close high_z mode
// PIN15_setOutputValue(HIGH_Z_MODE, 1); // 1 => close high_z mode
INSTRUCTION.eliteFxn = CV_CURVE;
INSTRUCTION.sampleRate = 15;
INSTRUCTION.Ve1 = ((uint16_t)(ins[3]) << 8) | (uint16_t)(ins[4]);
@@ -726,7 +757,7 @@ static void update_ZM_instruction(uint8 *ins) {
case VOLT_OUTPUT: {
ModeLED(WORKING);
PIN15_setOutputValue(HIGH_Z_MODE, 1); // 1 => close high_z mode
// PIN15_setOutputValue(HIGH_Z_MODE, 1); // 1 => close high_z mode
INSTRUCTION.eliteFxn = VOLT_OUTPUT;
INSTRUCTION.VoltConstant = ( ((uint16_t)(ins[3])) << 8) | (uint16_t)(ins[4]);
@@ -740,7 +771,7 @@ static void update_ZM_instruction(uint8 *ins) {
case ZT_CURVE: {
ModeLED(WORKING);
PIN15_setOutputValue(HIGH_Z_MODE, 1); // 1 => close high_z mode
// PIN15_setOutputValue(HIGH_Z_MODE, 1); // 1 => close high_z mode
INSTRUCTION.eliteFxn = ZT_CURVE;
INSTRUCTION.notifyRate = (uint32_t)INSTRUCTION.sampleRate;
INSTRUCTION.sampleRate = 15;
@@ -778,7 +809,7 @@ static void update_ZM_instruction(uint8 *ins) {
case CONSTANT_CURRENT: {
ModeLED(WORKING);
PIN15_setOutputValue(HIGH_Z_MODE, 1); // 1 => close high_z mode
// PIN15_setOutputValue(HIGH_Z_MODE, 1); // 1 => close high_z mode
INSTRUCTION.eliteFxn = CONSTANT_CURRENT;
INSTRUCTION.sampleRate = 15;
INSTRUCTION.charge = ins[3]; //0:discharge 1:charge
@@ -798,7 +829,7 @@ static void update_ZM_instruction(uint8 *ins) {
}
case CYCLIC_VOLTAMMETRY: {
PIN15_setOutputValue(HIGH_Z_MODE, 1); // 1 => close high_z mode
// PIN15_setOutputValue(HIGH_Z_MODE, 1); // 1 => close high_z mode
if (ins[3] == PARA_1) {
INSTRUCTION.sampleRate = 15;
INSTRUCTION.Vinit = ((int32_t)(ins[4]) << 8) | (int32_t)(ins[5]);
@@ -831,7 +862,7 @@ static void update_ZM_instruction(uint8 *ins) {
case HIGH_CYCLE_CYCLIC_VOLTAMMETRY: {
ModeLED(WORKING);
PIN15_setOutputValue(HIGH_Z_MODE, 1); // 1 => close high_z mode
// PIN15_setOutputValue(HIGH_Z_MODE, 1); // 1 => close high_z mode
INSTRUCTION.eliteFxn = CYCLIC_VOLTAMMETRY;
INSTRUCTION.sampleRate = 15;
INSTRUCTION.Vinit = ((int32_t)(ins[3]) << 8) | (int32_t)(ins[4]);
@@ -860,7 +891,7 @@ static void update_ZM_instruction(uint8 *ins) {
case LINEAR_SWEEP_VOLTAMMETRY: {
ModeLED(WORKING);
PIN15_setOutputValue(HIGH_Z_MODE, 1); // 1 => close high_z mode
// PIN15_setOutputValue(HIGH_Z_MODE, 1); // 1 => close high_z mode
INSTRUCTION.eliteFxn = LINEAR_SWEEP_VOLTAMMETRY;
INSTRUCTION.sampleRate = 15;
INSTRUCTION.Ve1 = ((uint16_t)(ins[3]) << 8) | (uint16_t)(ins[4]);
@@ -885,7 +916,7 @@ static void update_ZM_instruction(uint8 *ins) {
case CONSTANT_VSCAN: {
ModeLED(WORKING);
PIN15_setOutputValue(HIGH_Z_MODE, 1); // 1 => close high_z mode
// PIN15_setOutputValue(HIGH_Z_MODE, 1); // 1 => close high_z mode
INSTRUCTION.eliteFxn = CONSTANT_VSCAN;
INSTRUCTION.sampleRate = 15;
INSTRUCTION.Vinit = ((int32_t)(ins[3]) << 8) | (int32_t)(ins[4]);
@@ -1017,11 +1048,11 @@ static void update_ZM_instruction(uint8 *ins) {
case HIGH_Z : {
switch(ins[4]) {
case 0x00 : {
PIN15_setOutputValue(HIGH_Z_MODE, 0); // 0 => open high_z mode
// PIN15_setOutputValue(HIGH_Z_MODE, 0); // 0 => open high_z mode
break;
}
case 0x01 : {
PIN15_setOutputValue(HIGH_Z_MODE, 1); // 1 => close high_z mode
// PIN15_setOutputValue(HIGH_Z_MODE, 1); // 1 => close high_z mode
break;
}
default : {
@@ -1037,65 +1068,160 @@ static void update_ZM_instruction(uint8 *ins) {
break;
}
case ADC_TEST: {
case SET_EN_CHAN: { // 0x81
InitTrigChan();
INSTRUCTION.tri_pr0 = (bool) ((ins[3] & 0xF0) >> 4);
INSTRUCTION.tri_d0 = (bool) (ins[3] & 0x0F);
INSTRUCTION.tri_a0 = (bool) ((ins[4] & 0xF0) >> 4);
INSTRUCTION.tri_a2 = (bool) (ins[4] & 0x0F);
INSTRUCTION.tri_a3 = (bool) ((ins[5] & 0xF0) >> 4);
INSTRUCTION.tri_a1 = (bool) (ins[5] & 0x0F);
INSTRUCTION.tri_d1 = (bool) ((ins[6] & 0xF0) >> 4);
INSTRUCTION.tri_pr1 = (bool) (ins[6] & 0x0F);
INSTRUCTION.output_5v_en0 = (bool) ((ins[7] & 0xF0) >> 4);
INSTRUCTION.output_5v_en1 = (bool) (ins[7] & 0x0F);;
if(!INSTRUCTION.output_5v_en0) { // if 5V enable, auto disable DOUT
INSTRUCTION.tri_d0 = 0;
}
if(!INSTRUCTION.output_5v_en1) {
INSTRUCTION.tri_d1 = 0;
}
TRC.chan_en[0] = INSTRUCTION.tri_pr0;
TRC.chan_en[1] = INSTRUCTION.tri_d0;
TRC.chan_en[2] = INSTRUCTION.tri_a0;
TRC.chan_en[3] = INSTRUCTION.tri_a2;
TRC.chan_en[4] = INSTRUCTION.tri_a3;
TRC.chan_en[5] = INSTRUCTION.tri_a1;
TRC.chan_en[6] = INSTRUCTION.tri_d1;
TRC.chan_en[7] = INSTRUCTION.tri_pr1;
TRC.chan_en[8] = INSTRUCTION.output_5v_en0;
TRC.chan_en[9] = INSTRUCTION.output_5v_en1;
SET_LED_CHAN(TRC.chan_en, NO_EVENT);
// set_output_enable(TRC.chan_en);
break;
}
case ADC_TEST: { // 0x91
INSTRUCTION.eliteFxn = ADC_TEST;
set_output_enable(TRC.chan_en);
// int32_t ADCRealValue = 0;
uint8_t CIS_buf[9] = {0};
uint16_t ADCValueAVG_RAW = 0;
uint8_t ADC_input = 0;
bool AVG_done = 0;
uint16_t TW1508in = 0;
TW1508in = (((uint16_t) (ins[5])) << 8 ) | ((uint16_t) (ins[6]));
// ModeLED(TRIG01_WORK);
switch(ins[3]) {
case IIN_ADC :{ // 0x00
IinADCGainControl(ins[4]);
AVG_done = 1;
ADC_input = CMD_CURRENT_MEASURE;
case AOUT_ADC :{ // 0x00
ModeLED(TRIG01_WORK);
if(ins[4] == 0xFF) {
TW1508reset();
}
else {
GPIO_SPI_write(ins[4], TW1508in); // GPIOin = 0x0000 ~ 0x03FF
}
break;
}
case VIN_ADC :{ // 0x01
VinADCGainControl(ins[4]);
AVG_done = 1;
ADC_input = CMD_VOLT_MEASURE;
break;
}
case VOUT_DAC :{ // 0x02
VoutGainControl(ins[4]);
AVG_done = 0;
break;
}
case HIGH_Z :{ // 0x03
switch(ins[4]) {
case DOUT_ADC :{ // 0x01
switch (ins[4]) {
case 0x00 :{
PIN15_setOutputValue(HIGH_Z_MODE, 0); // 0 => open high_z mode
PIN15_setOutputValue(DO_MOS_0, 0);
break;
}
case 0x01 :{
PIN15_setOutputValue(HIGH_Z_MODE, 1); // 1 => close high_z mode
PIN15_setOutputValue(DO_MOS_0, 1);
break;
}
case 0x10 :{
PIN15_setOutputValue(DO_MOS_1, 0);
break;
}
case 0x11 :{
PIN15_setOutputValue(DO_MOS_1, 1);
break;
}
default :{
PIN15_setOutputValue(DO_MOS_0, 0);
PIN15_setOutputValue(DO_MOS_0, 0);
break;
}
}
break;
}
case PR_DAC :{ // 0x02
switch (ins[4]) {
case 0x00 :{
PIN15_setOutputValue(DO_PR_0, 0);
break;
}
case 0x01 :{
PIN15_setOutputValue(DO_PR_0, 1);
break;
}
case 0x10 :{
PIN15_setOutputValue(DO_PR_0, 0);
break;
}
case 0x11 :{
PIN15_setOutputValue(DO_PR_0, 1);
break;
}
default :{
PIN15_setOutputValue(DO_PR_0, 0);
PIN15_setOutputValue(DO_PR_0, 0);
break;
}
}
break;
}
case LEDtest :{ // 0x03
// update_LED_status(0x00,DARKLED, 0xA0, 0x00, 0x00);
// update_LED_status(0x01,DARKLED, 0x90, 0x50, 0x00);
// update_LED_status(0x02,DARKLED, 0x90, 0x90, 0x00);
// update_LED_status(0x03,DARKLED, 0x00, 0xf0, 0x00);
// update_LED_status(0x04,DARKLED, 0x00, 0x00, 0xff);
// update_LED_status(0x05,DARKLED, 0x20, 0x00, 0xf0);
// update_LED_status(0x06,DARKLED, 0x90, 0x00, 0xf0);
// update_LED_status(0x07,DARKLED, 0x20, 0x20, 0xa0);
// refresh_LED();
break;
}
case OUT_5V_EN :{ // 0x04
switch (ins[4]) {
case 0x00 :{
PIN15_setOutputValue(OUT_5V_EN_0, 0); // 0 => enable 5V output
break;
}
case 0x01 :{
PIN15_setOutputValue(OUT_5V_EN_0, 1); // 1 => disable 5V output
break;
}
case 0x10 :{
PIN15_setOutputValue(OUT_5V_EN_1, 0);
break;
}
case 0x11 :{
PIN15_setOutputValue(OUT_5V_EN_1, 1);
break;
}
default :{
PIN15_setOutputValue(OUT_5V_EN_0, 1);
PIN15_setOutputValue(OUT_5V_EN_1, 1);
break;
}
}
AVG_done = 0;
break;
}
default :{
AVG_done = 0;
break;
}
}
if (AVG_done) {
CPUdelay(100);
ADCValueAVG_RAW = ADC_CURRENT_AVG_calibration(ADC_input);
} else {
AVG_done = 0;
for (int i = 1; i < 9; i++) {
CIS_buf[i + 1] = 0x00;
}
}
CIS_buf[0] = chip_ID;
CIS_buf[1] = (uint8_t) ((ADCValueAVG_RAW & 0xFF00) >> 8);
CIS_buf[2] = (uint8_t) (ADCValueAVG_RAW & 0x00FF);
@@ -1129,7 +1255,7 @@ static void update_ZM_instruction(uint8 *ins) {
break;
}
/*
case CALI_DAC_MODE: {
ModeLED(WORKING);
INSTRUCTION.eliteFxn = CALI_DAC_MODE;
@@ -1164,14 +1290,14 @@ static void update_ZM_instruction(uint8 *ins) {
}
break;
}
*/
case PULSE_MODE: {
INSTRUCTION.VoutGainLevel = VOUT_GAIN_240K;
// INSTRUCTION.VoutGainLevel = VOUT_GAIN_240K;
INSTRUCTION.sampleRate = 15;
INSTRUCTION.notifyRate = 100;
INSTRUCTION.VoViSwitch = 0x01;
if (ins[3] == PARA_1) {
PIN15_setOutputValue(HIGH_Z_MODE, 1); // 1 => close high_z mode
// PIN15_setOutputValue(HIGH_Z_MODE, 1); // 1 => close high_z mode // no HIGH_Z for TRIG01
INSTRUCTION.sti_t1 = (int32_t)(ins[4]) << 24 | (int32_t)(ins[5]) << 16 | (int32_t)(ins[6]) << 8 | (int32_t)(ins[7]);
INSTRUCTION.sti_t2 = (int32_t)(ins[8]) << 24 | (int32_t)(ins[9]) << 16 | (int32_t)(ins[10]) << 8 | (int32_t)(ins[11]);
@@ -1179,7 +1305,7 @@ static void update_ZM_instruction(uint8 *ins) {
INSTRUCTION.sti_t4 = (int32_t)(ins[16]) << 24 | (int32_t)(ins[17]) << 16 | (int32_t)(ins[18]) << 8 | (int32_t)(ins[19]);
} else if (ins[3] == PARA_2) {
INSTRUCTION.sti_t5 = (int32_t)(ins[4]) << 24 | (int32_t)(ins[5]) << 16 | (int32_t)(ins[6]) << 8 | (int32_t)(ins[7]);
INSTRUCTION.sti_v1 = 25000; //8~11
INSTRUCTION.sti_v1 = 25000; //8~11
INSTRUCTION.sti_v2 = 50000; //12~15 //41406.43161.
INSTRUCTION.sti_v3 = 25000; //16~19
} else if (ins[3] == PARA_3) {
@@ -1202,11 +1328,12 @@ static void update_ZM_instruction(uint8 *ins) {
megaStiEnable = true;
} else if (ins[3] == PARA_17) {
INSTRUCTION.eliteFxn = PULSE_MODE;
ModeLED(WORKING);
set_output_enable(TRC.chan_en);
// ModeLED(WORKING);
ModeLED(TRIG01_WORK);
}
break;
}
default: {
/** **/
break;
@@ -1280,7 +1407,7 @@ static void update_ZM_instruction(uint8 *ins) {
case VIS_CC_ZERO: {
ModeLED(PRE_WORK);
PIN15_setOutputValue(HIGH_Z_MODE, 1); // 1 => close high_z mode
// PIN15_setOutputValue(HIGH_Z_MODE, 1); // 1 => close high_z mode
INSTRUCTION.eliteFxn = CONSTANT_CURRENT;
INSTRUCTION.sampleRate = 15;
INSTRUCTION.charge = 0x01;
@@ -1293,6 +1420,13 @@ static void update_ZM_instruction(uint8 *ins) {
break;
}
case VIS_TRIG_EN: { // 0x41
INSTRUCTION.trig0_en = (bool) ((ins[2] & 0xF0) >> 4);
INSTRUCTION.trig1_en = (bool) (ins[2] & 0x0F);
trig_en_check();
break;
}
default: {
break;
}
@@ -46,12 +46,18 @@ static void ZM_init() {
// initialize
pin_handle = PIN_open(&ZM_rst, BLE_IO);
InitLED();
InitTrigChan();
Init_Elite15_PIN();
ELITE15_SPI_HOLD();
PIN15_setOutputValue(shutdown_6994, 1); // OFF = 1 => turn off 6994
PIN15_setOutputValue(enable_10v, 0); // enable 10V
PIN15_setOutputValue(HIGH_Z_MODE, 1); // HIGH Z MODE // 1 => close high_z mode
// PIN15_setOutputValue(OUT_5V_EN_0, 1); // disable 5V output // 1 => output disable
// PIN15_setOutputValue(OUT_5V_EN_1, 1);
// PIN15_setOutputValue(DO_MOS_0, 0); // all Dout off
// PIN15_setOutputValue(DO_MOS_1, 0);
// AoutChannelSelect(0xFF, 0); // all Aout off
disable_trig_output(); // all output disable
InitEliteInstruction();
IinADCGainControl(INSTRUCTION.ADCGainLevel);
@@ -59,6 +65,8 @@ static void ZM_init() {
VoutGainControl(INSTRUCTION.VoutGainLevel);
elite_gptimer_open();
TW1508reset();
// TRIG_LED_Init();
// PIN_registerIntCb(pin_handle, switch_on_callback);
// PIN_setInterrupt(pin_handle, switch_on | PIN_IRQ_POSEDGE);
}
@@ -639,6 +639,14 @@ static void SimpleBLEPeripheral_taskFxn(UArg a0, UArg a1) {
} else {
EliteOn = TurnOnElite(key);
}
trig_sense();
if (trig_PeriodicEvent) {
trig_PeriodicEvent = false;
PeriodicEvent = true;
}
}
else { // if there is periodic event
if(InitPeriodicEvent){