Hi all!
My quistions are:
- How can I be sure, that this function doesnt end up as a infinite loop?(For example if mathTemp is always smaller than "12", AFE dac value always smaller than 1600?)
- What is the "12" value in one of the if statements?
- What is cycle width, and why is it defiened as "8"?
My device doesnt detect any rotation(I think I am struggling to find the correct DAC value), is it possible that this is caused by my capacitor?
Maybe the capacity too big? I included the LC sensor parameters and the generated functions first part(second part is same for channel1).
void TSM_Auto_cal(void) { // constant and variable for TSM calibration #define CYCLE_WIDTH 8 // which is equal to (ESICLK / freq of LC) - 2 #define LC_THRESHOLD_TSM_CAL 1600 #define CH0_FINISH BIT0 #define CH1_FINISH BIT1 int8_t calStatus = 0; int16_t mathTemp; uint16_t i; findDACParams fparams= {0}; int8_t ch0Counter; int16_t dAC0_sum1, dAC0_sum2; int8_t ch1Counter; int16_t dAC1_sum1, dAC1_sum2; /** * This module is used to find the signal level of LC oscillation for * ESICH0, ESICH1, ESICH2 or ESICH3 depending on user selection. * This calibration updates calibration delay: * * -TSM state 3 - 7 for CH0 * -TSM state 13 - 17 for CH1 * -TSM state 23 - 27 for CH2 */ dAC0_sum1 = dAC0_sum2 = 0; fparams.channel0Enabled = true; ch0Counter = 0 ; dAC1_sum1 = dAC1_sum2 = 0; fparams.channel1Enabled = true; // 2 LC sensor system ch1Counter = 0 ; /* START of TSM Auto-calibration */ do{ // Find DAC threshold using 12-BIT successive approximation FindDAC(&fparams); dAC0_sum2 = ESI_getAFE1DACValue(CHANNEL_0_DAC1_UPPER_REGISTER); dAC1_sum2 = ESI_getAFE1DACValue(CHANNEL_1_DAC1_UPPER_REGISTER); // Channel 0 TSM Auto-calibration if(!(calStatus & CH0_FINISH)){ if (dAC0_sum2 > LC_THRESHOLD_TSM_CAL) // LC_THRESHOLD_TSM_CAL = 1600 { if (dAC0_sum2 > dAC0_sum1) { mathTemp = dAC0_sum2 - dAC0_sum1; } else { mathTemp = dAC0_sum1 - dAC0_sum2; } ch0Counter += 1; if (mathTemp > 12) { if (ch0Counter > CYCLE_WIDTH) { for (i= 0; i< ch0Counter / 2 ; i++) { ESI_TSM_setTSMStateDuration(ESI_TSM_STATE_REG_3,ESI_TSM_getTSMStateDuration(ESI_TSM_STATE_REG_3) - 1); } calStatus |= CH0_FINISH; } else { ch0Counter = 0; dAC0_sum1 = dAC0_sum2; } } else { dAC0_sum1 = dAC0_sum2; } } if(!(calStatus&CH0_FINISH)){ // Determine which high frequency state can increment state // duration by 1 if(!(ESI_TSM_getTSMStateDuration(ESI_TSM_STATE_REG_3) == ESI_TSM_STATE_DURATION_MAX)) { ESI_TSM_setTSMStateDuration(ESI_TSM_STATE_REG_3,ESI_TSM_getTSMStateDuration(ESI_TSM_STATE_REG_3) + 1); } else if(!(ESI_TSM_getTSMStateDuration(ESI_TSM_STATE_REG_4) == ESI_TSM_STATE_DURATION_MAX)) { ESI_TSM_setTSMStateDuration(ESI_TSM_STATE_REG_4,ESI_TSM_getTSMStateDuration(ESI_TSM_STATE_REG_4) + 1); } else if(!(ESI_TSM_getTSMStateDuration(ESI_TSM_STATE_REG_5) == ESI_TSM_STATE_DURATION_MAX)) { ESI_TSM_setTSMStateDuration(ESI_TSM_STATE_REG_5,ESI_TSM_getTSMStateDuration(ESI_TSM_STATE_REG_5) + 1); } else if(!(ESI_TSM_getTSMStateDuration(ESI_TSM_STATE_REG_6) == ESI_TSM_STATE_DURATION_MAX)) { ESI_TSM_setTSMStateDuration(ESI_TSM_STATE_REG_6,ESI_TSM_getTSMStateDuration(ESI_TSM_STATE_REG_6) + 1); } else if(!(ESI_TSM_getTSMStateDuration(ESI_TSM_STATE_REG_7) == ESI_TSM_STATE_DURATION_MAX)) { ESI_TSM_setTSMStateDuration(ESI_TSM_STATE_REG_7,ESI_TSM_getTSMStateDuration(ESI_TSM_STATE_REG_7) + 1); } else { // If all high frequency state have been maxed out, // increment ACLK cycle by one and reset repeat cycles for // all high frequency time states ESI_TSM_setTSMStateDuration(ESI_TSM_STATE_REG_2,ESI_TSM_getTSMStateDuration(ESI_TSM_STATE_REG_2) + 1); ESI_TSM_setTSMStateDuration(ESI_TSM_STATE_REG_3, ESI_TSM_STATE_DURATION_MIN); ESI_TSM_setTSMStateDuration(ESI_TSM_STATE_REG_4, ESI_TSM_STATE_DURATION_MIN); ESI_TSM_setTSMStateDuration(ESI_TSM_STATE_REG_5, ESI_TSM_STATE_DURATION_MIN); ESI_TSM_setTSMStateDuration(ESI_TSM_STATE_REG_6, ESI_TSM_STATE_DURATION_MIN); ESI_TSM_setTSMStateDuration(ESI_TSM_STATE_REG_7, ESI_TSM_STATE_DURATION_MIN); dAC0_sum1 = dAC0_sum2 = 0; ch0Counter = 0; } } } }
Any help is appreciated.