/******************************************************************************* * Function Name: StopWaveDac ******************************************************************************** * * Summary * Turns off the waveform for the specified function generator * * Parameters: * fnGenerator - the index of the function generator to be stopped * * Return: * None. * *******************************************************************************/ void StopWaveDac(int fnGenerator) { if (fnGenerator == 0) { WaveDAC_0_Stop(); } else if (fnGenerator == 1) { WaveDAC_1_Stop(); } }
/******************************************************************************* * Function Name: WaveDAC_1_Sleep ******************************************************************************** * * Summary: * Stops the component and saves its configuration. Should be called * just prior to entering sleep. * * Parameters: * None * * Return: * None * * Global variables: * WaveDAC_1_backup: The structure field 'enableState' is modified * depending on the enable state of the block before entering to sleep mode. * * Reentrant: * No * *******************************************************************************/ void WaveDAC_1_Sleep(void) { /* Save DAC8's enable state */ WaveDAC_1_backup.enableState = (WaveDAC_1_IDAC8_ACT_PWR_EN == (WaveDAC_1_IDAC8_PWRMGR_REG & WaveDAC_1_IDAC8_ACT_PWR_EN)) ? 1u : 0u ; WaveDAC_1_Stop(); WaveDAC_1_SaveConfig(); }
void stopWaveDac(int fnGenerator) { switch (fnGenerator) { case WAVEDAC_LOW_0: case WAVEDAC_HIGH_0: WaveDAC_0_Stop(); break; case WAVEDAC_LOW_1: case WAVEDAC_HIGH_1: WaveDAC_1_Stop(); break; } }
int main() { char freq0Disp[16], freq1Disp[16]; char usbRx[USBUART_BUFFER_SIZE], usbTx[USBUART_BUFFER_SIZE]; /* Initializes the LCD. */ LCD_Start(); LCD_Position(1u,0u); LCD_Position(0u,0u); LCD_PrintString("F1="); WaveDAC_0_Clock_Start(); WaveDAC_1_Clock_Start(); // Needed for WaveDACs to operate concurrently // I think this might be a bug with PSoC WaveDAC_0_Start(); WaveDAC_1_Start(); WaveDAC_0_Stop(); WaveDAC_1_Stop(); USBUART_Start(USBFS_DEVICE, USBUART_5V_OPERATION); USBUART_CDC_Init(); CyGlobalIntEnable; while (1) { if (USBUART_IsConfigurationChanged()) { if (USBUART_GetConfiguration()) { USBUART_CDC_Init(); } } if (USBUART_GetConfiguration()) { if (USBUART_DataIsReady()) { int numArgs; int desiredFreq, newFreq, fnGenerator; char mode[USBUART_BUFFER_SIZE] = {0}; Serial_GetString(usbRx); trimString(usbRx); numArgs = sscanf(usbRx, "%d %s %d", &fnGenerator, mode, &desiredFreq); if (numArgs == 3) { if (!strcmp(mode, "square")) { newFreq = changeFrequency(desiredFreq, SQUARE, fnGenerator); sprintf(usbTx, "fn = %d, mode = %s, newFreq = %d\r\n", fnGenerator, mode, newFreq); } else if (!strcmp(mode, "sine")) { newFreq = changeFrequency(desiredFreq, SINE, fnGenerator); sprintf(usbTx, "fn = %d, mode = %s, newFreq = %d\r\n", fnGenerator, mode, newFreq); } else if (!strcmp(mode, "triangle")) { newFreq = changeFrequency(desiredFreq, TRIANGLE, fnGenerator); sprintf(usbTx, "fn = %d, mode = %s, newFreq = %d\r\n", fnGenerator, mode, newFreq); } else if (!strcmp(mode, "sawtooth")) { newFreq = changeFrequency(desiredFreq, SAWTOOTH, fnGenerator); sprintf(usbTx, "fn = %d, mode = %s, newFreq = %d\r\n", fnGenerator, mode, newFreq); } else if (!strcmp(mode, "dc")) { newFreq = changeFrequency(desiredFreq, DC, fnGenerator); sprintf(usbTx, "fn = %d, mode = %s, newFreq = %d\r\n", fnGenerator, mode, newFreq); } else { sprintf(usbTx, "Invalid mode: %s\r\n", mode); } } else if (numArgs == 2) { if (!strcmp(mode, "off")) { if (fnGenerator == 0) { stopWaveDac(WAVEDAC_LOW_0); } else if (fnGenerator == 1) { stopWaveDac(WAVEDAC_LOW_1); } sprintf(usbTx, "Stopped WaveDAC %d\r\n", fnGenerator); } else { sprintf(usbTx, "Invalid mode: %s\r\n", mode); } } else { sprintf(usbTx, "Invalid command: %s\r\n", usbRx); } Serial_PutString(usbTx); } } } }