From a1019d11c30c191f5c106676ac88b60eac7c8106 Mon Sep 17 00:00:00 2001 From: Michael Dryden Date: Wed, 3 Oct 2012 01:55:14 -0400 Subject: [PATCH] Finished move to experiment source file. Started programming interface in main. --- DSTAT-temp/src/ads1255.c | 231 +++++++++++++++-------------- DSTAT-temp/src/ads1255.h | 54 +++---- DSTAT-temp/src/config/conf_usb.h | 2 +- DSTAT-temp/src/experiment.c | 243 ++++++++++++++++++++++++++++++- DSTAT-temp/src/experiment.h | 2 + DSTAT-temp/src/main.c | 46 ++++-- DSTAT1.atsuo | Bin 42496 -> 42496 bytes 7 files changed, 422 insertions(+), 156 deletions(-) diff --git a/DSTAT-temp/src/ads1255.c b/DSTAT-temp/src/ads1255.c index 11e8771..739c80b 100644 --- a/DSTAT-temp/src/ads1255.c +++ b/DSTAT-temp/src/ads1255.c @@ -32,20 +32,100 @@ void ads1255_init_pins(void) } - void ads1255_init_module(void) - { - usart_spi_init(&USARTE1); - usart_spi_setup_device(&USARTE1, &spi_device_conf, SPI_MODE_1, 2300000UL, 0); - } + void ads1255_init_module(void){ + usart_spi_init(&USARTE1); + usart_spi_setup_device(&USARTE1, &spi_device_conf, SPI_MODE_1, 2300000UL, 0); + } void ads1255_sync(void){ usart_spi_select_device(&USARTE1, &spi_device_conf); usart_spi_transmit(&USARTE1, ADS_SYNC); usart_spi_deselect_device(&USARTE1, &spi_device_conf); + return; +} + +void ads1255_reg_read(uint8_t address){ + uint8_t command_buffer[2]; + command_buffer[0] = address; + command_buffer[0] |= (1 << 4); + command_buffer[1] = 4; + uint8_t input_buffer[5]; + + usart_spi_select_device(&USARTE1, &spi_device_conf); + +// while (ioport_pin_is_high(IOPORT_CREATE_PIN(PORTD, 5))); + while (arch_ioport_get_pin_level(IOPORT_CREATE_PIN(PORTD, 5))) + + usart_spi_write_packet(&USARTE1, &(command_buffer[0]), 2); + delay_us(6.5); + usart_spi_read_packet(&USARTE1, (uint8_t*) &input_buffer, 5); + usart_spi_deselect_device(&USARTE1, &spi_device_conf); + + for (int i=0;i<5;i++) + printf("ADS1255: Register %u=%.2x\n\r",i+1,input_buffer[i]); return; } +void ads1255_reset(){ + usart_spi_select_device(&USARTE1, &spi_device_conf); +// while (ioport_pin_is_high(IOPORT_CREATE_PIN(PORTD, 5))); + while (arch_ioport_get_pin_level(IOPORT_CREATE_PIN(PORTD, 5))); + usart_spi_transmit(&USARTE1, ADS_RESET); + + #ifdef ADS1255_DBG + printf("ADS1255: Sending RESET\n\r"); + printf("ADS1255: Waiting for calibration\n\r"); + #endif + +// while (ioport_pin_is_high(IOPORT_CREATE_PIN(PORTD, 5))); + while (arch_ioport_get_pin_level(IOPORT_CREATE_PIN(PORTD, 5))); + usart_spi_deselect_device(&USARTE1, &spi_device_conf); + + return; +} + +void ads1255_setup(uint8_t buff, uint8_t rate, uint8_t pga){ + uint8_t command_buffer[6] = {0x50,0x03,buff,0x01,pga,rate}; + + usart_spi_select_device(&USARTE1, &spi_device_conf); + usart_spi_transmit(&USARTE1, ADS_SDATAC); + usart_spi_write_packet(&USARTE1, (uint8_t*)&command_buffer, 6); + usart_spi_transmit(&USARTE1, ADS_SYNC); + usart_spi_transmit(&USARTE1, ADS_SELFCAL); +// while (ioport_pin_is_high(IOPORT_CREATE_PIN(PORTD, 5))); + while (arch_ioport_get_pin_level(IOPORT_CREATE_PIN(PORTD, 5))); + usart_spi_deselect_device(&USARTE1, &spi_device_conf); + + return; +} + +void ads1255_standby(void){ + usart_spi_select_device(&USARTE1, &spi_device_conf); + usart_spi_transmit(&USARTE1, ADS_STANDBY); + usart_spi_deselect_device(&USARTE1, &spi_device_conf); + + return; +} + +void ads1255_wakeup(void){ + usart_spi_select_device(&USARTE1, &spi_device_conf); + usart_spi_transmit(&USARTE1, ADS_WAKEUP); + usart_spi_deselect_device(&USARTE1, &spi_device_conf); + + return; +} + +void ads1255_rdatac(void){ + usart_spi_select_device(&USARTE1, &spi_device_conf); + usart_spi_transmit(&USARTE1, ADS_RDATAC); + +// while (ioport_pin_is_high(IOPORT_CREATE_PIN(PORTD, 5))); + while (arch_ioport_get_pin_level(IOPORT_CREATE_PIN(PORTD, 5))); + usart_spi_deselect_device(&USARTE1, &spi_device_conf); + + return; +} int32_t ads1255_single_read(void){ union{ @@ -54,7 +134,7 @@ int32_t ads1255_single_read(void){ } input_buffer; usart_spi_select_device(&USARTE1, &spi_device_conf); -// while (ioport_pin_is_high(IOPORT_CREATE_PIN(PORTD, 5))); + // while (ioport_pin_is_high(IOPORT_CREATE_PIN(PORTD, 5))); while (arch_ioport_get_pin_level(IOPORT_CREATE_PIN(PORTD, 5))); usart_spi_transmit(&USARTE1, ADS_RDATA); delay_us(6.5); @@ -64,18 +144,18 @@ int32_t ads1255_single_read(void){ usart_put(&USARTE1, CONFIG_USART_SPI_DUMMY); while (usart_rx_is_complete(&USARTE1) == false); input_buffer.uint[i] = usart_get(&USARTE1); - } - while (!usart_tx_is_complete(&USARTE1)); - usart_clear_tx_complete(&USARTE1); + } + while (!usart_tx_is_complete(&USARTE1)); + usart_clear_tx_complete(&USARTE1); - usart_spi_deselect_device(&USARTE1, &spi_device_conf); + usart_spi_deselect_device(&USARTE1, &spi_device_conf); ads1255_standby(); if (input_buffer.uint[2] > 0x7F) - input_buffer.uint[3] = 0xFF; + input_buffer.uint[3] = 0xFF; else - input_buffer.uint[3] = 0x0; + input_buffer.uint[3] = 0x0; #ifdef ADS1255_DBG printf(logstr1, "ADS1255 result=%li\n\r",input_buffer.int32); @@ -85,25 +165,25 @@ int32_t ads1255_single_read(void){ { over_under[buffer_iter] = 1; if (buffer_iter == (ADS_OVER_UNDER_SAMPLES - 1)) - buffer_iter = 0; + buffer_iter = 0; else - buffer_iter++; + buffer_iter++; } else if (input_buffer.int32 < ADS_UNDERCURRENT_THRESHOLD && (input_buffer.int32*-1) < (ADS_UNDERCURRENT_THRESHOLD)) { over_under[buffer_iter] = -1; if (buffer_iter == (ADS_OVER_UNDER_SAMPLES - 1)) - buffer_iter = 0; + buffer_iter = 0; else - buffer_iter++; + buffer_iter++; } else { over_under[buffer_iter] = 0; if (buffer_iter == (ADS_OVER_UNDER_SAMPLES - 1)) - buffer_iter = 0; + buffer_iter = 0; else - buffer_iter++; + buffer_iter++; } return input_buffer.int32; } @@ -121,7 +201,7 @@ int16_t ads1255_read_fast(void){ usart_put(&USARTE1, CONFIG_USART_SPI_DUMMY); while (usart_rx_is_complete(&USARTE1) == false); input_buffer.uint[i] = usart_get(&USARTE1); - } + } while (!usart_tx_is_complete(&USARTE1)); usart_clear_tx_complete(&USARTE1); @@ -149,7 +229,7 @@ int16_t ads1255_read_fast_single(void){ } while (!usart_tx_is_complete(&USARTE1)); usart_clear_tx_complete(&USARTE1); - usart_spi_deselect_device(&USARTE1, &spi_device_conf); + usart_spi_deselect_device(&USARTE1, &spi_device_conf); ads1255_standby(); @@ -174,16 +254,16 @@ int32_t ads1255_read(void){ usart_put(&USARTE1, CONFIG_USART_SPI_DUMMY); while (usart_rx_is_complete(&USARTE1) == false); input_buffer.uint[i] = usart_get(&USARTE1); - } + } while (!usart_tx_is_complete(&USARTE1)); usart_clear_tx_complete(&USARTE1); - usart_spi_deselect_device(&USARTE1, &spi_device_conf); + usart_spi_deselect_device(&USARTE1, &spi_device_conf); if (input_buffer.uint[2] > 0x7F) - input_buffer.uint[3] = 0xFF; + input_buffer.uint[3] = 0xFF; else - input_buffer.uint[3] = 0x0; + input_buffer.uint[3] = 0x0; #ifdef ADS1255_DBG printf("ADS1255 result=%li\n\r", input_buffer.int32); @@ -193,25 +273,25 @@ int32_t ads1255_read(void){ { over_under[buffer_iter] = 1; if (buffer_iter == (ADS_OVER_UNDER_SAMPLES - 1)) - buffer_iter = 0; + buffer_iter = 0; else - buffer_iter++; + buffer_iter++; } else if (input_buffer.int32 < ADS_UNDERCURRENT_THRESHOLD && (input_buffer.int32*-1) < (ADS_UNDERCURRENT_THRESHOLD)) { over_under[buffer_iter] = -1; if (buffer_iter == (ADS_OVER_UNDER_SAMPLES - 1)) - buffer_iter = 0; + buffer_iter = 0; else - buffer_iter++; + buffer_iter++; } else { over_under[buffer_iter] = 0; if (buffer_iter == (ADS_OVER_UNDER_SAMPLES - 1)) - buffer_iter = 0; + buffer_iter = 0; else - buffer_iter++; + buffer_iter++; } return input_buffer.int32; } @@ -234,97 +314,14 @@ int32_t ads1255_read_fast24(void){ } while (!usart_tx_is_complete(&USARTE1)); usart_clear_tx_complete(&USARTE1); - usart_spi_deselect_device(&USARTE1, &spi_device_conf); + usart_spi_deselect_device(&USARTE1, &spi_device_conf); if (input_buffer.uint[2] > 0x7F) - input_buffer.uint[3] = 0xFF; + input_buffer.uint[3] = 0xFF; else - input_buffer.uint[3] = 0x0; - + input_buffer.uint[3] = 0x0; + printf("%x, %x, %x\n\r", input_buffer.uint[2],input_buffer.uint[1], input_buffer.uint[0]); return input_buffer.int32; -} - -void ads1255_reg_read(uint8_t address){ - uint8_t command_buffer[2]; - command_buffer[0] = address; - command_buffer[0] |= (1 << 4); - command_buffer[1] = 4; - uint8_t input_buffer[5]; - - usart_spi_select_device(&USARTE1, &spi_device_conf); - -// while (ioport_pin_is_high(IOPORT_CREATE_PIN(PORTD, 5))); - while (arch_ioport_get_pin_level(IOPORT_CREATE_PIN(PORTD, 5))) - - usart_spi_write_packet(&USARTE1, &(command_buffer[0]), 2); - delay_us(6.5); - usart_spi_read_packet(&USARTE1, (uint8_t*) &input_buffer, 5); - usart_spi_deselect_device(&USARTE1, &spi_device_conf); - - for (int i=0;i<5;i++) - printf("ADS1255: Register %u=%.2x\n\r",i+1,input_buffer[i]); - - return; -} - -void ads1255_reset(){ - usart_spi_select_device(&USARTE1, &spi_device_conf); -// while (ioport_pin_is_high(IOPORT_CREATE_PIN(PORTD, 5))); - while (arch_ioport_get_pin_level(IOPORT_CREATE_PIN(PORTD, 5))); - usart_spi_transmit(&USARTE1, ADS_RESET); - - #ifdef ADS1255_DBG - printf("ADS1255: Sending RESET\n\r"); - printf("ADS1255: Waiting for calibration\n\r"); - #endif - -// while (ioport_pin_is_high(IOPORT_CREATE_PIN(PORTD, 5))); - while (arch_ioport_get_pin_level(IOPORT_CREATE_PIN(PORTD, 5))); - usart_spi_deselect_device(&USARTE1, &spi_device_conf); - - return; -} - -void ads1255_setup(uint8_t buff, uint8_t rate, uint8_t pga){ - uint8_t command_buffer[6] = {0x50,0x03,buff,0x01,pga,rate}; - - usart_spi_select_device(&USARTE1, &spi_device_conf); - usart_spi_transmit(&USARTE1, ADS_SDATAC); - usart_spi_write_packet(&USARTE1, (uint8_t*)&command_buffer, 6); - usart_spi_transmit(&USARTE1, ADS_SYNC); - usart_spi_transmit(&USARTE1, ADS_SELFCAL); -// while (ioport_pin_is_high(IOPORT_CREATE_PIN(PORTD, 5))); - while (arch_ioport_get_pin_level(IOPORT_CREATE_PIN(PORTD, 5))); - usart_spi_deselect_device(&USARTE1, &spi_device_conf); - - return; -} - -void ads1255_standby(void){ - usart_spi_select_device(&USARTE1, &spi_device_conf); - usart_spi_transmit(&USARTE1, ADS_STANDBY); - usart_spi_deselect_device(&USARTE1, &spi_device_conf); - - return; -} - -void ads1255_wakeup(void){ - usart_spi_select_device(&USARTE1, &spi_device_conf); - usart_spi_transmit(&USARTE1, ADS_WAKEUP); - usart_spi_deselect_device(&USARTE1, &spi_device_conf); - - return; -} - -void ads1255_rdatac(void){ - usart_spi_select_device(&USARTE1, &spi_device_conf); - usart_spi_transmit(&USARTE1, ADS_RDATAC); - -// while (ioport_pin_is_high(IOPORT_CREATE_PIN(PORTD, 5))); - while (arch_ioport_get_pin_level(IOPORT_CREATE_PIN(PORTD, 5))); - usart_spi_deselect_device(&USARTE1, &spi_device_conf); - - return; } \ No newline at end of file diff --git a/DSTAT-temp/src/ads1255.h b/DSTAT-temp/src/ads1255.h index c59d13c..103a7f6 100644 --- a/DSTAT-temp/src/ads1255.h +++ b/DSTAT-temp/src/ads1255.h @@ -31,33 +31,33 @@ #define ADS_STANDBY 0xfd #define ADS_RESET 0xfe -#define ADS_DR_2_5 0b00000011 -#define ADS_DR_5 0b00010011 -#define ADS_DR_10 0b00100011 -#define ADS_DR_15 0b00110011 -#define ADS_DR_25 0b01000011 -#define ADS_DR_30 0b01010011 -#define ADS_DR_50 0b01100011 -#define ADS_DR_60 0b01110010 -#define ADS_DR_100 0b10000010 -#define ADS_DR_500 0b10010010 -#define ADS_DR_1000 0b10100001 -#define ADS_DR_2000 0b10110000 -#define ADS_DR_3750 0b11000000 -#define ADS_DR_7500 0b11010000 -#define ADS_DR_15000 0b11100000 -#define ADS_DR_30000 0b11110000 - -#define ADS_PGA_1 0b000 -#define ADS_PGA_2 0b001 -#define ADS_PGA_4 0b010 -#define ADS_PGA_8 0b011 -#define ADS_PGA_16 0b100 -#define ADS_PGA_32 0b101 -#define ADS_PGA_64 0b110 - -#define ADS_BUFF_OFF 0b0000 -#define ADS_BUFF_ON 0b0010 +#define ADS_DR_2_5 0b00000011 //0x03 +#define ADS_DR_5 0b00010011 //0x13 +#define ADS_DR_10 0b00100011 //0x23 +#define ADS_DR_15 0b00110011 //0x33 +#define ADS_DR_25 0b01000011 //0x43 +#define ADS_DR_30 0b01010011 //0x53 +#define ADS_DR_50 0b01100011 //0x63 +#define ADS_DR_60 0b01110010 //0x72 +#define ADS_DR_100 0b10000010 //0x82 +#define ADS_DR_500 0b10010010 //0x92 +#define ADS_DR_1000 0b10100001 //0xA1 +#define ADS_DR_2000 0b10110000 //0xB0 +#define ADS_DR_3750 0b11000000 //0xC0 +#define ADS_DR_7500 0b11010000 //0xD0 +#define ADS_DR_15000 0b11100000 //0xE0 +#define ADS_DR_30000 0b11110000 //0xF0 + +#define ADS_PGA_1 0b000 //0x0 +#define ADS_PGA_2 0b001 //0x1 +#define ADS_PGA_4 0b010 //0x2 +#define ADS_PGA_8 0b011 //0x3 +#define ADS_PGA_16 0b100 //0x4 +#define ADS_PGA_32 0b101 //0x5 +#define ADS_PGA_64 0b110 //0x6 + +#define ADS_BUFF_OFF 0b0000 //0x0 +#define ADS_BUFF_ON 0b0010 //0x2 #define ADS_OVERCURRENT_THRESHOLD 6000000L #define ADS_UNDERCURRENT_THRESHOLD 200000L diff --git a/DSTAT-temp/src/config/conf_usb.h b/DSTAT-temp/src/config/conf_usb.h index 2cbf82c..03219f8 100644 --- a/DSTAT-temp/src/config/conf_usb.h +++ b/DSTAT-temp/src/config/conf_usb.h @@ -66,7 +66,7 @@ //! USB Device string definitions (Optional) #define USB_DEVICE_MANUFACTURE_NAME "Wheeler Lab" #define USB_DEVICE_PRODUCT_NAME "DStat" -// #define USB_DEVICE_SERIAL_NAME "12...EF" +#define USB_DEVICE_SERIAL_NAME "12...EF" /** diff --git a/DSTAT-temp/src/experiment.c b/DSTAT-temp/src/experiment.c index 0ba61e6..25e2074 100644 --- a/DSTAT-temp/src/experiment.c +++ b/DSTAT-temp/src/experiment.c @@ -24,6 +24,8 @@ static void porte_int0_lsv(void); static void tcf0_ovf_callback(void); static void tce1_ovf_callback_lsv(void); static void lsv_cca_callback(void); +static void ca_cca_callback(void); +static void portd_int0_ca(void); //interrupt callback setup typedef void (*port_callback_t) (void); @@ -392,4 +394,243 @@ static void lsv_cca_callback(void){ tc_set_cca_interrupt_level(&TCC1, TC_INT_LVL_OFF); up = 0; return; -} \ No newline at end of file +} + +void chronoamp(uint16_t steps, uint16_t step_dac[], uint16_t step_seconds[]){ + while (RTC.STATUS & RTC_SYNCBUSY_bm); + RTC.PER = 999; + while (RTC.STATUS & RTC_SYNCBUSY_bm); + RTC.CTRL = RTC_PRESCALER_DIV1_gc; + + EVSYS.CH0MUX = EVSYS_CHMUX_RTC_OVF_gc; + + portd_int0_callback = portd_int0_ca; + + tc_enable(&TCC0); + tc_set_cca_interrupt_callback(&TCC0, ca_cca_callback); + + ads1255_rdatac(); + ads1255_wakeup(); + + tc_write_period(&TCC0,0xffff); + tc_write_clock_source(&TCC0, TC_CLKSEL_EVCH0_gc); + tc_set_direction(&TCC0, TC_UP); + tc_enable_cc_channels(&TCC0, TC_CCAEN); + tc_set_cca_interrupt_level(&TCC0, TC_INT_LVL_HI); + TCC0.CNT = 0; + + pot_exp_start(); + + for (uint8_t i = 0; i < steps; ++i) + { + up = 1; + tc_write_cc(&TCC0, TC_CCA, TCC0.CNT+step_seconds[i]-1); + RTC.CNT=0; + max5443_set_voltage1(step_dac[i]); + //PORTE.INTCTRL = PORT_INT0LVL_LO_gc; + PORTD.INTCTRL = PORT_INT0LVL_LO_gc; + while (up !=0); + } + + tc_set_cca_interrupt_level(&TCC0, TC_INT_LVL_OFF); + tc_write_clock_source(&TCC0, TC_CLKSEL_OFF_gc); + tc_disable(&TCC0); + pot_exp_stop(); + ads1255_standby(); + + return; +} + +static void portd_int0_ca(void){ + if (autogainswitch()==0){ + //while (ioport_pin_is_high(IOPORT_CREATE_PIN(PORTE, 3))); + while (ioport_pin_is_high(IOPORT_CREATE_PIN(PORTD, 5))); + if (gain == POT_GAIN_300) + printf("%u, %ld00000\n\r", TCC1.CNT, ads1255_read()); + else if (gain == POT_GAIN_3k) + printf("%u, %ld0000\n\r", TCC1.CNT, ads1255_read()); + else if (gain == POT_GAIN_30k) + printf("%u, %ld000\n\r", TCC1.CNT, ads1255_read()); + else if (gain == POT_GAIN_300k) + printf("%u, %ld00\n\r", TCC1.CNT, ads1255_read()); + else if (gain == POT_GAIN_3M) + printf("%u, %ld0\n\r", TCC1.CNT, ads1255_read()); + else if (gain == POT_GAIN_30M) + printf("%u, %ld\n\r", TCC1.CNT, ads1255_read()); + else + printf("%u, %lu\n\r", TCC1.CNT, ads1255_read()); + } + else{ + //while (ioport_pin_is_high(IOPORT_CREATE_PIN(PORTE, 3))); + while (ioport_pin_is_high(IOPORT_CREATE_PIN(PORTD, 5))); + ads1255_read(); + } +} + +static void ca_cca_callback(void){ + //PORTE.INTCTRL = PORT_INT0LVL_OFF_gc; + PORTD.INTCTRL = PORT_INT0LVL_OFF_gc; + up = 0; + return; +} + +void swv_experiment(int16_t start, int16_t stop, uint16_t step, uint16_t pulse_height, uint16_t frequency){ + //check experiment limits + // if((start-pulse_height)<-1500 || (start+pulse_height)>(1500)|| start == stop || stop<-1500 || (stop+pulse_height)>1500 || step<1 || step>1500 || pulse_height > 1500 || pulse_height < 1) + // { + // printf("ERR: Experiment parameters outside limits\n\r"); + // //return; + // } + + int32_t forward = 0; + int32_t reverse = 0; + int32_t data_buffer; + uint8_t direction; + uint16_t dacindex_start = ceil((start)*(65535/(double)3000))+32767; + uint16_t dacindex_stop = ceil(stop*(65535/(double)3000))+32767; + uint16_t dacindex_step = ceil(step*(65535/(double)3000)); + uint16_t dacindex_pulse_height = ceil(pulse_height*(65535/(double)3000)); + uint16_t dacindex = dacindex_start; + uint32_t period; + int16_t fgain = -1; + int16_t rgain = -1; + + + if (start < stop) + direction = 1; + else + direction = 0; + + tc_enable(&TCF0); + + frequency *= 2; //compensate for half-period triggers + + //calculate time to ADC trigger + period = ceil((1/(double)frequency)*F_CPU); + uint8_t temp_div = ceil((double)period/UINT16_MAX); + + if (temp_div == 1) + tc_write_clock_source(&TCF0,TC_CLKSEL_DIV1_gc); + else if (temp_div == 2){ + tc_write_clock_source(&TCF0,TC_CLKSEL_DIV2_gc); + period /= 2; + } + else if (temp_div <= 4){ + tc_write_clock_source(&TCF0,TC_CLKSEL_DIV4_gc); + period /= 4; + } + else if (temp_div <= 8){ + tc_write_clock_source(&TCF0,TC_CLKSEL_DIV8_gc); + period /= 8; + } + else if (temp_div <= 64){ + tc_write_clock_source(&TCF0,TC_CLKSEL_DIV64_gc); + period /= 64; + } + else if (temp_div <= 256){ + tc_write_clock_source(&TCF0,TC_CLKSEL_DIV256_gc); + period /= 256; + } + else if (temp_div <= 1024){ + tc_write_clock_source(&TCF0,TC_CLKSEL_DIV1024_gc); + period /= 1024; + } + else{ + printf("Frequency/ADC rate is too low\n\r"); + return; + } + + tc_write_period(&TCF0, (uint16_t)period); + + if (direction == 1) + max5443_set_voltage1(dacindex+dacindex_pulse_height); + else + max5443_set_voltage1(dacindex-dacindex_pulse_height); + + ads1255_wakeup(); + ads1255_rdatac(); + ads1255_sync(); + + pot_exp_start(); + TCF0.CNT = 0; + while (!tc_is_overflow(&TCF0)); + ads1255_wakeup(); + TCF0.CNT = 0; + + while ((dacindex <= dacindex_stop && direction == 1) || (dacindex >= dacindex_stop && direction == 0)){ + tc_clear_overflow(&TCF0); + + if (fgain > -1) + //printf("%u, %li, %li\n\r", dacindex, forward*fgain, reverse*rgain); + printf("%u, %li%0*lu, %li%0*lu\n\r", dacindex, fgain, 0, forward, rgain, 0, reverse); + + forward = 0; + reverse = 0; + + while (!tc_is_overflow(&TCF0)){ + autogainswitch(); + if (gain <= POT_GAIN_30M) + fgain = 0; + else + fgain = gain-1; + + + while (ioport_pin_is_low(IOPORT_CREATE_PIN(PORTD, 5))); + while (ioport_pin_is_high(IOPORT_CREATE_PIN(PORTD, 5))); + + // while (ioport_pin_is_low(IOPORT_CREATE_PIN(PORTE, 3))); + // while (ioport_pin_is_high(IOPORT_CREATE_PIN(PORTE, 3))); + // forward = ads1255_read_fast24(); + forward = ads1255_read(); + } + + + if (direction == 1) + max5443_set_voltage1(dacindex-dacindex_pulse_height); + else + max5443_set_voltage1(dacindex+dacindex_pulse_height); + + + tc_clear_overflow(&TCF0); + if (direction == 1) + dacindex += dacindex_step; + else + dacindex -= dacindex_step; + + while (!tc_is_overflow(&TCF0)){ + autogainswitch(); + if (gain <= POT_GAIN_30M) + rgain = 0; + else + rgain = gain-1; + + while (ioport_pin_is_low(IOPORT_CREATE_PIN(PORTD, 5))); + while (ioport_pin_is_high(IOPORT_CREATE_PIN(PORTD, 5))); + + // while (ioport_pin_is_low(IOPORT_CREATE_PIN(PORTE, 3))); + // while (ioport_pin_is_high(IOPORT_CREATE_PIN(PORTE, 3))); + // reverse = ads1255_read_fast24(); + reverse = ads1255_read(); + } + + if (direction == 1) + max5443_set_voltage1(dacindex+dacindex_pulse_height); + else + max5443_set_voltage1(dacindex-dacindex_pulse_height); + + } + + pot_exp_stop(); + tc_write_clock_source(&TCF0, TC_CLKSEL_OFF_gc); + tc_disable(&TCF0); + tc_write_count(&TCF0,0); + ads1255_standby(); + + return; +} + +ISR(PORTD_INT0_vect){ + if (portd_int0_callback) { + portd_int0_callback(); + } +} \ No newline at end of file diff --git a/DSTAT-temp/src/experiment.h b/DSTAT-temp/src/experiment.h index 50c7672..91f7bce 100644 --- a/DSTAT-temp/src/experiment.h +++ b/DSTAT-temp/src/experiment.h @@ -62,5 +62,7 @@ void pot_exp_start(void); void pot_exp_stop(void); void cv_experiment(int16_t v1, int16_t v2, int16_t start, uint8_t scans, uint16_t slope); void lsv_experiment(int16_t start, int16_t stop, uint16_t slope, int8_t first_run); +void chronoamp(uint16_t steps, uint16_t step_dac[], uint16_t step_seconds[]); +void swv_experiment(int16_t start, int16_t stop, uint16_t step, uint16_t pulse_height, uint16_t frequency); #endif /* EXPERIMENT_H_ */ \ No newline at end of file diff --git a/DSTAT-temp/src/main.c b/DSTAT-temp/src/main.c index 5c1ebb3..cfd1170 100644 --- a/DSTAT-temp/src/main.c +++ b/DSTAT-temp/src/main.c @@ -7,6 +7,40 @@ #include "main.h" +//Internal global variables +int16_t p1, p2, p3, p4; +uint16_t u1; +uint8_t p5, o1, o2, o3; +uint16_t step_dac[50], step_seconds[50]; + +//Internal function declarations +int8_t command_handler(char command); + +int8_t command_handler(char command){ + switch (command){ + case 'A': //ADS Buffer/rate/PGA + scanf("%hX%hX%hX",o1,o2,o3); + ads1255_setup(o1, o2, o3); + break; + case 'G': //Gain - start gain, autogain on/off, min gain, max, gain, low/high switch thresholds + break; + case 'L': //LSV + break; + case 'C': //CV + break; + case 'S': //SWV + break; + case 'R': //CA + break; + default: + printf("E"); + return 1; + } + + printf("K"); + return 0; +} + int main(void){ board_init(); @@ -38,20 +72,12 @@ int main(void){ uint16_t input; - // RTC.CTRL = RTC_PRESCALER_OFF_gc; - // while (RTC.STATUS & RTC_SYNCBUSY_bm); - // RTC.CNT = 0; - // RTC.PER = 0xffff; - // RTC.CTRL = RTC_PRESCALER_DIV1_gc; - ads1255_wakeup(); ads1255_rdatac(); - - // max5443_set_voltage1(21845); //1V - // pot_exp_start(); + ads1255_standby(); while (1){ - ads1255_standby(); + printf("Choose Experiment type:\n\r"); printf("Options:0, LSV:1, CV:2, SWV:3, AMP:4, EIS:5\n\r"); diff --git a/DSTAT1.atsuo b/DSTAT1.atsuo index 52f584fcad855065b08fba32ff3ec9296d586451..1a562f2c7c681c9276498dc83dee26512af9cee9 100644 GIT binary patch delta 1962 zcmZ{l3s6*57{|}K++|l?brY1sH^f=bR}R}SR61791#Ig0TtHLB-?nX z8H3CID|?FXS7_+X!OGF~G0r%tq19yBG~zTh=1f*oDQ4PtmT;V@&d%?i^F7Wv-}%mC zz2_zGd1-5i`Tm0k52iE59E521L(O1;ImE0&EvLR;31@E zMe6hNB#BqyP-wgC;*6m{8*eBhODVCC5M#opjWXwwwVD()#4=(zv4W^2HWTW3ZSoNA zK+m#tbTx$!r(FR3Y$MScO zp1;{t$`V*5JLjMMdLh3V8U5uebKlFAXy}gRvtN z01aYL;_-9SAT=Z-lhcN!tAV6$ZSpR1-c9Tw_7eMu{lt4j2O;7)NW4#U5{HPx#1#VP zlaEQiGi*#5Dcxb%pE5SlOkw{)rrU%#TfJ1@CH^Gt5q}Z)i3bED-@~Z^4YC?1!}-*J z?G6b>Wt=!jxSu&d-SpHU4qx-*czjL-yyAo{Rd8!j1XAW)C;wEqE3~jZvjH{5$+%ap zJoLGsMBr*gErvE%z_n-&!YVw_Rwf{j<3?JZ26yu^P~xgWe32Cn7m&I*)}Px&&10BX zG(xqzPikRoiiEo|5jjmd)XnwM*rh0F`WU0;7GR!f2F_JX!2-)D+{$&+I68d0B$l55 z&s~q7%Z<3aGzML{?P{RdE5Vv+qKlG*PnxTB)vS!J)M|#Uxh8C>9L&3deJB!H!yF$4 z1%oRI2`dyOvhP$-qLe@qwT0*qbJ+BpQYR5w0{T)L55vsT$#U>EdrJ%CNkV_6)DbH* zStMi=P9ld8x_;aw=L=n1z6r$(3)%|YIGL08&mvOsRkdE3DfWtrql-JH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