Latch LOADA & LOADB no no.

This commit is contained in:
Benny Liu
2021-03-15 18:22:08 +08:00
parent bd049e4fec
commit dbfd4364e3
7 changed files with 43 additions and 55 deletions
@@ -214,28 +214,6 @@ static void Init_Elite15_PIN () {
latch_setOutputValue(LOAD0, 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) {
@@ -260,12 +238,14 @@ static void latch_setOutputValue (uint32_t latch_num, bool highlow) {
default: {
PIN_setOutputValue(pin_handle, LOADA, 1);
PIN_setOutputValue(pin_handle, LOADB, 1);
// PIN_setPortOutputValue(pin_handle, ((1<<LOADA)|(1<<LOADB)));
break;
}
}
} else { // All latch turn off
PIN_setOutputValue(pin_handle, LOADA, 1);
PIN_setOutputValue(pin_handle, LOADA, 1); // pull LOADB before LOADA
PIN_setOutputValue(pin_handle, LOADB, 1);
// PIN_setPortOutputValue(pin_handle, ((1<<LOADA)|(1<<LOADB)));
}
}
@@ -25,11 +25,6 @@
#define ADC_CH_DAC 0x02
#define ADC_CH_BAT 0x03
#define GPIO_CH_0 0x00
#define GPIO_CH_1 0x01
#define GPIO_CH_2 0x02
#define GPIO_CH_3 0x03
#define Aout_CH_0 0x00
#define Aout_CH_1 0x01
#define Aout_CH_2 0x02
@@ -629,8 +624,6 @@ 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};
@@ -638,36 +631,45 @@ static void GPIO_SPI_write(uint8_t GPIO_channel, uint16_t GPIOin) {
uint32_t CLK_CH[2] = {0};
spi_GPIO_txbuf = 0;
bool trans_valid = false;
switch (GPIO_channel) {
case GPIO_CH_0: {
case Aout_CH_0: {
CLK_CH[0] = TW_CH_0[0];
CLK_CH[1] = TW_CH_0[1];
trans_valid = true;
break;
}
case GPIO_CH_1: {
case Aout_CH_1: {
CLK_CH[0] = TW_CH_1[0];
CLK_CH[1] = TW_CH_1[1];
trans_valid = true;
break;
}
case GPIO_CH_2: {
case Aout_CH_2: {
CLK_CH[0] = TW_CH_2[0];
CLK_CH[1] = TW_CH_2[1];
trans_valid = true;
break;
}
case GPIO_CH_3: {
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 ~ 0x0400 */
spi_GPIO_txbuf = GPIOin;
GPIO_SPI_transfer(CLK_CH, spi_GPIO_txbuf);
if (trans_valid) {
GPIO_SPI_transfer(CLK_CH, spi_GPIO_txbuf);
trans_valid = false;
}
}
static void AoutChannelSelect(uint8_t Aout_channel, bool on_off) {
@@ -701,10 +703,10 @@ static void AoutChannelSelect(uint8_t Aout_channel, bool on_off) {
}
static void TW1508reset() {
GPIO_SPI_write(GPIO_CH_0, 0x0000);
GPIO_SPI_write(GPIO_CH_1, 0x0000);
GPIO_SPI_write(GPIO_CH_2, 0x0000);
GPIO_SPI_write(GPIO_CH_3, 0x0000);
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;
}
@@ -103,12 +103,14 @@ static void DAC_SPI(uint8_t length, uint8_t *spi_txbuf, uint8_t *spi_rxbuf) {
static void ELITE15_SPI_HOLD() {
Elite_SPI_init();
PIN_setOutputValue(pin_handle, LOADA, 0); // Turn on LATCH0
PIN_setOutputValue(pin_handle, LOADB, 0);
// PIN_setOutputValue(pin_handle, LOADA, 0); // Turn on LATCH0
// PIN_setOutputValue(pin_handle, LOADB, 0);
PIN_setPortOutputValue(pin_handle, 0);
}
static void ELITE15_SPI_CLOSE() {
PIN_setOutputValue(pin_handle, LOADA, 1); // Turn off all LATCH
PIN_setOutputValue(pin_handle, LOADB, 1);
// PIN_setOutputValue(pin_handle, LOADB, 1); // Turn off all LATCH
// PIN_setOutputValue(pin_handle, LOADA, 1);
PIN_setPortOutputValue(pin_handle, 1);
SPI_close(spiHandle0);
SPI_close(spiHandle1);
@@ -133,7 +135,7 @@ static void CAL_ADC_SPI(uint8_t length, uint8_t *spi_txbuf, uint8_t *spi_rxbuf)
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++){
for (int i=0; i<SPI_GPIO_BUFF_SIZE; i++) {
SPI_GPIO[i] = 0;
}
@@ -149,9 +151,11 @@ static void GPIO_SPI_transfer(uint32_t *GPIO_CLK_CH, uint16_t spi_GPIO_txbuf) {
SPI_GPIO[9] = (spi_GPIO_txbuf & 0b0000001000000000);
ELITE15_SPI_CLOSE();
PIN_setPortOutputValue(pin_handle, 0);
add_elite_pin();
PIN_setOutputValue(pin_handle, LOADA, 0); // Turn on LATCH0
PIN_setOutputValue(pin_handle, LOADB, 0);
// PIN_setOutputValue(pin_handle, LOADA, 0); // Turn on LATCH0
// PIN_setOutputValue(pin_handle, LOADB, 0);
for (int i=SPI_GPIO_BUFF_SIZE-1; i>=0; i--) {
PIN_setOutputValue(pin_handle, GPIO_CLK_CH[1], 0); // generate clk signal
@@ -165,9 +169,10 @@ static void GPIO_SPI_transfer(uint32_t *GPIO_CLK_CH, uint16_t spi_GPIO_txbuf) {
PIN_setOutputValue(pin_handle, D3, 0);
update_latch_status (ADC_SPI_MOSI, 0);
PIN_setOutputValue(pin_handle, LOADA, 1); // Turn off all LATCH
PIN_setOutputValue(pin_handle, LOADB, 1);
// PIN_setOutputValue(pin_handle, LOADB, 1); // Turn off all LATCH
// PIN_setOutputValue(pin_handle, LOADA, 1);
remove_elite_pin();
PIN_setPortOutputValue(pin_handle, 1);
ELITE15_SPI_HOLD();
// PIN15_setOutputValue(ADC_DAC_SPI_MOSI, 0);
@@ -64,4 +64,6 @@ static void trig_callback(PIN_Handle handle, PIN_Id pinId) {
#endif
#endif
@@ -1061,8 +1061,6 @@ static void update_ZM_instruction(uint8 *ins) {
// 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]));
@@ -1072,9 +1070,9 @@ static void update_ZM_instruction(uint8 *ins) {
if(ins[4] == 0xFF) {
TW1508reset();
} else {
AoutChannelSelect(ins[4], 1);
GPIO_SPI_write(ins[4], TW1508in);
AoutChannelSelect(ins[4], 0);
// AoutChannelSelect(ins[4], 1);
PIN15_setOutputValue(AO_MOS_0, 1);
}
break;
}
@@ -61,6 +61,7 @@ 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);