void run() { ADC_SAR_Seq_1_Start(); ADC_SAR_Seq_1_StartConvert(); initPSoCWiFi(SSID,PASS,DevKitIP); for(;;) { struct updateParameters values = getValues(); struct responses received = sendSensorData(values); ID = received.ID; wantedMoisture = received.moisture; wantedRotate = received.rotate; if(wantedMoisture >= values.currentMoisture) { start(); CyDelay(1000); stop(); } rotate(wantedRotate); CyDelay(6000); //10 min delay } }
int main() { // Enable global interrupts CyGlobalIntEnable; // Enable bootloader button // (need to clear pending interrupt first) isr_1_ClearPending(); isr_1_StartEx(isr_bootloader); // Enable analog multiplexer (chooses thermocouple input) AMux_1_Start(); // Enable op-amp (amplifies thermocouple signal) Opamp_1_Start(); // Enable ADC (reads amplified signal) ADC_SAR_Seq_1_Start(); ADC_SAR_Seq_1_StartConvert(); // Enable serial transmission UART_1_Start(); // To avoid a flash on power-on, the relay pin is configured as a // high impedance input initially // Because some guy on the internet says so: // http://www.cypress.com/forum/psoc-4-architecture/low-initial-drive-state-pwm-components Pin_Relays_Write(1); // HIGH to turn PNP transistor OFF Pin_Relays_SetDriveMode(Pin_Relays_DM_STRONG); for(;;) { // Read thermocouples and send over serial // Note that externally (and over serial communication), // 0 is T1, 1 is T2, and 2 is T3 SendTemperature(0, ADC_OFFSET_0, OPAMP_GAIN_FACTOR_0); SendTemperature(1, ADC_OFFSET_1, OPAMP_GAIN_FACTOR_1); SendTemperature(2, ADC_OFFSET_2, OPAMP_GAIN_FACTOR_2); // Newline for easier debugging UART_1_UartPutString("\r\n"); // Wait a bit, processing serial command input in between delays uint8 i; for (i = 0; i < 5; i++) { ReadSerialInput(); CyDelay(100); } // Safety feature: Ensure that the relays do not stay on for more than // ~30 seconds without communication from the serial control program if (relayState) { if (++relayOnCycles >= 60) { UART_1_UartPutString("R=0 (inactivity)\r\n"); SetRelays(0); } } else { relayOnCycles = 0; } } }
/******************************************************************************* * Function Name: ADC_SAR_Seq_1_Wakeup ******************************************************************************** * * Summary: * Restores the component enable state and configuration registers. * This should be called just after awaking from sleep mode. * * Parameters: * None. * * Return: * None. * * Global Variables: * ADC_SAR_Seq_1_backup - used. * *******************************************************************************/ void ADC_SAR_Seq_1_Wakeup(void) { ADC_SAR_Seq_1_SAR_DFT_CTRL_REG &= (uint32)~ADC_SAR_Seq_1_ADFT_OVERRIDE; if(ADC_SAR_Seq_1_backup.enableState != ADC_SAR_Seq_1_DISABLED) { ADC_SAR_Seq_1_Start(); if((ADC_SAR_Seq_1_backup.enableState & ADC_SAR_Seq_1_STARTED) != 0u) { ADC_SAR_Seq_1_StartConvert(); } } }
/******************************************************************************* * Function Name: ADC_SAR_Seq_1_Wakeup ******************************************************************************** * * Summary: * Restores the component enable state and configuration registers. * This should be called just after awaking from sleep mode. * * Parameters: * None. * * Return: * None. * * Global Variables: * ADC_SAR_Seq_1_backup - used. * *******************************************************************************/ void ADC_SAR_Seq_1_Wakeup(void) { ADC_SAR_Seq_1_SAR_DFT_CTRL_REG &= (uint32)~ADC_SAR_Seq_1_ADFT_OVERRIDE; if(ADC_SAR_Seq_1_backup.enableState != ADC_SAR_Seq_1_DISABLED) { /* Enable the SAR internal pump */ if((ADC_SAR_Seq_1_backup.enableState & ADC_SAR_Seq_1_BOOSTPUMP_ENABLED) != 0u) { ADC_SAR_Seq_1_SAR_CTRL_REG |= ADC_SAR_Seq_1_BOOSTPUMP_EN; } ADC_SAR_Seq_1_Enable(); if((ADC_SAR_Seq_1_backup.enableState & ADC_SAR_Seq_1_STARTED) != 0u) { ADC_SAR_Seq_1_StartConvert(); } } }