/***************************************************************************//** * @brief Main function. * * @return None. *******************************************************************************/ int main(void) { char receivedCmd[30] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; unsigned char cmd = 0; double param[5] = {0, 0, 0, 0, 0}; char paramNo = 0; char cmdType = -1; char invalidCmd = 0; /*!< Select and initialize the platform. */ if (PLATFORM_Init(XILINX_KC705) < 0) { return -1; } /*!< Initialize the console with selected baud rate for the platform used. */ CONSOLE_Init(UART_BAUDRATE); /*!< Initialize the device. */ DoDeviceInit(); while(1) { /*!< Read the command entered by user through console. */ CONSOLE_GetCommand(receivedCmd); invalidCmd = 0; for(cmd = 0; cmd < cmdNo; cmd++) { paramNo = 0; cmdType = CONSOLE_CheckCommands(receivedCmd, cmdList[cmd].name, \ param, ¶mNo); if(cmdType == UNKNOWN_CMD) { invalidCmd++; } else { cmdFunctions[cmd](param, paramNo); } } /*!< Send feedback to user, if the command entered by user is not a valid one. */ if(invalidCmd == cmdNo) { CONSOLE_Print("Invalid command!\r\n"); } } return 0; }
/***************************************************************************//** * @brief Main function. * * @return None. *******************************************************************************/ void main(void) { char receivedCmd[20]; double param[5]; char cmd = 0; char paramNo = 0; char cmdType = -1; char invalidCmd = 0; /*!< Initialize the console. */ CONSOLE_Init(9600); TIME_DelayMs(10); /*!< Initialize the device. */ DoDeviceInit(); while(1) { /*!< Read the command entered by user through UART. */ CONSOLE_GetCommand(receivedCmd); invalidCmd = 0; for(cmd = 0; cmd < cmdNo; cmd++) { paramNo = 0; cmdType = CONSOLE_CheckCommands(receivedCmd, cmdList[cmd], param, ¶mNo); if(cmdType == UNKNOWN_CMD) { invalidCmd++; } else { cmdFunctions[cmd](param, paramNo); } } /*!< Send feedback to user, if the command entered by user is not a valid one. */ if(invalidCmd == cmdNo) { CONSOLE_Print("Invalid command!\r\n"); } } }
/***************************************************************************//** * @brief Main function. * * @return None. *******************************************************************************/ void main(void) { /*! Variables holding information about the device */ unsigned short temperature = 0; /*!< Last temperature read from the device */ unsigned long startFreq = 0; /*!< Start frequency sweep */ unsigned long incFreq = 0; /*!< Increment frequency */ unsigned short incNum = 0; /*!< Number of increments */ unsigned long calibImped = 0; /*!< Calibration impedance */ double gainFactor = 0; /*!< Stores the value of the gain factor */ double impedance = 0; /*!< Measured impedance */ double currentFreq = 0; /*!< Signal frequency used during a measurement */ /*! Temporary variables */ unsigned char tempString[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; double tempValue = 0; /*! Initialize the UART communication peripheral. */ UART_Init(9600); /*! Initialize the AD5933 device. */ if(AD5933_Init()) { CONSOLE_WriteString("AD5933 OK"); UART_Write(0x0D); } else { CONSOLE_WriteString("AD5933 Error"); UART_Write(0x0D); } while(1) { CONSOLE_GetCommand(receivedCommand); invalidCommand = 0; for(command = 0; command < commandsNumber; command++) { commandType = CONSOLE_CheckCommands(receivedCommand, commandsList[command], (double*)&commandParam); if(commandType == 0) { invalidCommand++; } if((command == 0) && (commandType != 0)) /*!< "help?" command*/ { CONSOLE_WriteString("Available commands:"); UART_Write(0x0D); for(displayCommand = 0; displayCommand < commandsNumber; displayCommand++) { CONSOLE_WriteString(commandsList[displayCommand]); CONSOLE_WriteString(commandsDescription[displayCommand]); UART_Write(0x0D); } } if((command == 1) && (commandType != 0)) /*!< "temperature?" command*/ { /*! Read the temperature from the device */ temperature = AD5933_GetTemperature(); /*! Send the requested value to user */ CONSOLE_WriteString("temperature="); itoa(tempString, temperature, 10); CONSOLE_WriteString(tempString); CONSOLE_WriteString(" degrees Celsius"); UART_Write(0xD); } if((command == 2) && (commandType != 0)) /*!< "startFreq=" command*/ { /*! Check if the parameter is valid */ if( (commandParam >= 0) && (commandParam < MAX_START_FREQ) ) { tempValue = (commandParam / MHZ_4) * POW_2_27; startFreq = (unsigned long)tempValue; } else if(commandParam < 0) { startFreq = 0; } else { startFreq = 0x00FFFFFF; } /* Configure the sweep parameters */ AD5933_ConfigSweep(startFreq, incFreq, incNum); /* Start the sweep operation */ AD5933_StartSweep(); /*! Send feedback to user */ CONSOLE_WriteString(commandsList[command]); tempValue = ((double)startFreq * MHZ_4) / POW_2_27; FloatToString(tempString, tempValue); CONSOLE_WriteString(tempString); CONSOLE_WriteString(" Hz"); UART_Write(0xD); /*! Update the currentFrequrncy */ currentFreq = tempValue; } if((command == 3) && (commandType != 0)) /*!< "incFreq=" command*/ { /*! Check if the parameter is valid */ if( (commandParam >= 0) && (commandParam < MAX_START_FREQ) ) { tempValue = (commandParam / MHZ_4) * POW_2_27; incFreq = (unsigned long)tempValue; } else if(commandParam < 0) { incFreq = 0; } else { incFreq = 0x00FFFFFF; } /* Configure the sweep parameters */ AD5933_ConfigSweep(startFreq, incFreq, incNum); /* Start the sweep operation */ AD5933_StartSweep(); /*! Send feedback to user */ CONSOLE_WriteString(commandsList[command]); tempValue = ((double)incFreq * MHZ_4) / POW_2_27; FloatToString(tempString, tempValue); CONSOLE_WriteString(tempString); CONSOLE_WriteString(" Hz"); UART_Write(0xD); } if((command == 4) && (commandType != 0)) /*!< "incNum=" command*/ { /*! Check if the parameter is valid */ if( (commandParam >= 0) && (commandParam < MAX_INC_NUM) ) { incNum = (unsigned short)commandParam; } else if(commandParam < 0) { incNum = 0; } else { incNum = 0x01FF; } /* Configure the sweep parameters */ AD5933_ConfigSweep(startFreq, incFreq, incNum); /* Start the sweep operation */ AD5933_StartSweep(); /*! Send feedback to user */ CONSOLE_WriteString(commandsList[command]); itoa(tempString, incNum, 10); CONSOLE_WriteString(tempString); UART_Write(0xD); } if((command == 5) && (commandType != 0)) /*!< "sweepParam?" command*/ { /*! Send the requested value to user */ CONSOLE_WriteString(commandsList[2]); tempValue = ((double)startFreq * MHZ_4) / POW_2_27; FloatToString(tempString, tempValue); CONSOLE_WriteString(tempString); CONSOLE_WriteString(" Hz"); UART_Write(0xD); CONSOLE_WriteString(commandsList[3]); tempValue = ((double)incFreq * MHZ_4) / POW_2_27; FloatToString(tempString, tempValue); CONSOLE_WriteString(tempString); CONSOLE_WriteString(" Hz"); UART_Write(0xD); CONSOLE_WriteString(commandsList[4]); itoa(tempString, incNum, 10); CONSOLE_WriteString(tempString); UART_Write(0xD); } if((command == 6) && (commandType != 0)) /*!< "calibImpedance=" command*/ { /*! Check if the parameter is valid */ if( (commandParam >= 1) && (commandParam <= 1000000) ) { calibImped = (unsigned long)commandParam; } else if(commandParam < 1) { calibImped = 1; } else { calibImped = 1000000; } /* Calculate the gain factor for the selected impedance */ gainFactor = AD5933_CalculateGainFactor(calibImped, AD5933_FUNCTION_REPEAT_FREQ); /*! Send feedback to user */ CONSOLE_WriteString("Gain was calculated for Z="); itoa(tempString, calibImped, 10); CONSOLE_WriteString(tempString); CONSOLE_WriteString(" [Ohm]"); UART_Write(0xD); } if((command == 7) && (commandType != 0)) /*!< "impendace?" command*/ { /* Calculates the impedance between the VOUT and VIN pins. */ impedance = AD5933_CalculateImpedance(gainFactor, AD5933_FUNCTION_INC_FREQ); /*! Send the requested value to user */ tempValue = (double)impedance / 1000; FloatToString(tempString, tempValue); CONSOLE_WriteString("impedance="); CONSOLE_WriteString(tempString); CONSOLE_WriteString("[KOhm]"); UART_Write(0xD); /*! Update the currentFrequrncy */ tempValue = ((double)incFreq * MHZ_4) / POW_2_27; currentFreq = currentFreq + tempValue; } if((command == 8) && (commandType != 0)) /*!< "currentFreq?" command*/ { FloatToString(tempString, currentFreq); CONSOLE_WriteString(tempString); CONSOLE_WriteString(" [Hz]"); UART_Write(0xD); } } if(invalidCommand == commandsNumber) { /*! Send feedback to user */ CONSOLE_WriteString("Invalid command"); UART_Write(0x0D); } } }