Newer
Older
Michael DM Dryden
committed
if (_dpv_singledir(dacindex_start, dacindex_stop, dacindex_pulse_height, dacindex_step, direction))
goto aborting; //function will return non-zero if abort called over USB
printf("D\n\r"); //signal end of experiment
aborting:
volt_exp_stop();
Michael DM Dryden
committed
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
tc_write_clock_source(&TCF0, TC_CLKSEL_OFF_gc);
tc_disable(&TCF0);
TCF0.CNT = 0;
ads1255_standby();
return;
}
uint8_t _dpv_singledir (uint16_t dacindex, uint16_t dacindex_stop, uint16_t dacindex_pulse_height, uint16_t dacindex_step, uint8_t direction){
/**
* Internal function that performs a single direction sweep for DPV
*
* @param dacindex Starting voltage as dac index
* @param dacindex_stop Stop voltage in dac index.
* @param dacindex_step Step voltage in dac index.
* @param dacindex_pulse_height Pulse amplitude in dac index.
* @param direction Scan direction - 1 for up, 0 for down.
*/
int32_t forward = 0;
int32_t reverse = 0;
uint16_t lastindex = 0;
if (direction == 1)
max5443_set_voltage1(dacindex+dacindex_pulse_height);
else
max5443_set_voltage1(dacindex-dacindex_pulse_height);
while ((dacindex <= dacindex_stop && direction == 1) || (dacindex >= dacindex_stop && direction == 0)){
tc_clear_overflow(&TCF0);
tc_clear_cc_interrupt(&TCF0, TC_CCA);
while (!tc_is_cc_interrupt(&TCF0, TC_CCA)){ //convert continuously until tc CCA match - datum is last collected point
while (ioport_pin_is_low(IOPORT_CREATE_PIN(PORTD, 5))); //wait for next valid datum
while (ioport_pin_is_high(IOPORT_CREATE_PIN(PORTD, 5)));
forward = ads1255_read_fast24();
if (udi_cdc_is_rx_ready()){ //check for abort signal over USB
if (getchar() == 'a')
return 1;
}
}
//switch voltage to baseline
max5443_set_voltage1(dacindex);
while (!tc_is_overflow(&TCF0)){ //wait for tc overflow
while (ioport_pin_is_low(IOPORT_CREATE_PIN(PORTD, 5))); //wait for next valid datum
while (ioport_pin_is_high(IOPORT_CREATE_PIN(PORTD, 5)));
reverse = ads1255_read_fast24();
if (udi_cdc_is_rx_ready()){
if (getchar() == 'a')
return 1;
}
}
lastindex = dacindex;
//increment dacindex
if (direction == 1){
dacindex += dacindex_step;
max5443_set_voltage1(dacindex+dacindex_pulse_height);
}
else{
dacindex -= dacindex_step;
max5443_set_voltage1(dacindex-dacindex_pulse_height);
}
//data output
printf("B\n");
send_data_uint16(lastindex);
send_data_int32(forward);
send_data_int32(reverse);
printf("\n");
}
return 0;
}
Michael DM Dryden
committed
ISR(PORTD_INT0_vect){
if (portd_int0_callback) {
portd_int0_callback();
}