Example project for the Rioux Chem control box
Rioux Chem Control Box
This is the example project for the Rioux Chem Control Box. I have posted some youtube videos to guide you through the hardware and software:
Rioux Chem Control Box - Hardware
http://www.youtube.com/watch?v=MoZ92GRYa4s
Rioux Chem Control Box - Software - Part I
http://www.youtube.com/watch?v=_MwaTLL4dyA==
Rioux Chem Control Box - Software - Part II
http://www.youtube.com/watch?v=j_P89izfgoQ
DRIVERS/CHEM_BOX_INTERFACE.h@9:c830667212f4, 2021-11-01 (annotated)
- Committer:
- wavenumber
- Date:
- Mon Nov 01 19:49:13 2021 +0000
- Revision:
- 9:c830667212f4
- Parent:
- 7:de452fceafc1
Fixed Thermocouple sign extend error
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
emh203 | 0:7798270c1f52 | 1 | #include "MODSERIAL.h" |
emh203 | 0:7798270c1f52 | 2 | |
emh203 | 0:7798270c1f52 | 3 | #ifndef CHEM_BOX_INTERFACE |
emh203 | 0:7798270c1f52 | 4 | #define CHEM_BOX_INTERFACE |
emh203 | 0:7798270c1f52 | 5 | |
wavenumber | 3:cb48919cd5e8 | 6 | #define API_VERSION "1.1" |
emh203 | 0:7798270c1f52 | 7 | |
emh203 | 0:7798270c1f52 | 8 | // _____ _ _ ______ __ __ ____ ______ __ _____ _____ |
emh203 | 0:7798270c1f52 | 9 | // / ____| | | | ____| \/ | | _ \ / __ \ \ / / /\ | __ \_ _| |
emh203 | 0:7798270c1f52 | 10 | // | | | |__| | |__ | \ / | | |_) | | | \ V / / \ | |__) || | |
emh203 | 0:7798270c1f52 | 11 | // | | | __ | __| | |\/| | | _ <| | | |> < / /\ \ | ___/ | | |
emh203 | 0:7798270c1f52 | 12 | // | |____| | | | |____| | | | | |_) | |__| / . \ / ____ \| | _| |_ |
emh203 | 0:7798270c1f52 | 13 | // \_____|_| |_|______|_| |_| |____/ \____/_/ \_\ /_/ \_\_| |_____| |
emh203 | 0:7798270c1f52 | 14 | // |
emh203 | 0:7798270c1f52 | 15 | // |
emh203 | 0:7798270c1f52 | 16 | |
emh203 | 0:7798270c1f52 | 17 | //Initializes the hardware for the Chem box. Must be called before any other CHEM box functions are called. |
emh203 | 0:7798270c1f52 | 18 | void InitChemBox(); |
emh203 | 0:7798270c1f52 | 19 | |
wavenumber | 3:cb48919cd5e8 | 20 | extern DigitalOut RED_LED; |
wavenumber | 3:cb48919cd5e8 | 21 | |
wavenumber | 3:cb48919cd5e8 | 22 | extern DigitalOut GREEN_LED; |
wavenumber | 3:cb48919cd5e8 | 23 | |
emh203 | 0:7798270c1f52 | 24 | //Special Note.... All of the Digital IO functions are queued. This means that they do not take effect |
emh203 | 0:7798270c1f52 | 25 | //until the function FlushDigitalIO() is called. |
emh203 | 0:7798270c1f52 | 26 | |
emh203 | 0:7798270c1f52 | 27 | |
emh203 | 0:7798270c1f52 | 28 | //Enables one of the 8 heater channels. Just pass a number between 0 and 7 |
emh203 | 0:7798270c1f52 | 29 | void EnableHeater(uint8_t RelayIndex); |
emh203 | 0:7798270c1f52 | 30 | |
emh203 | 0:7798270c1f52 | 31 | |
emh203 | 0:7798270c1f52 | 32 | //Disables one of the 8 heater channels. Just pass a number between 0 and 7 |
emh203 | 0:7798270c1f52 | 33 | void DisableHeater(uint8_t RelayIndex); |
emh203 | 0:7798270c1f52 | 34 | |
emh203 | 0:7798270c1f52 | 35 | //Enables one of the 12 Solenoid valve channels. Just pass a number between 0 and 12 |
emh203 | 0:7798270c1f52 | 36 | void EnableSolenoidValve(uint8_t SolenoidIndex); |
emh203 | 0:7798270c1f52 | 37 | |
emh203 | 0:7798270c1f52 | 38 | //Disables one of the 12 Solenoid valve channels. Just pass a number between 0 and 12 |
emh203 | 0:7798270c1f52 | 39 | void DisableSolenoidValue(uint8_t SolenoidIndex); |
emh203 | 0:7798270c1f52 | 40 | |
emh203 | 0:7798270c1f52 | 41 | //Enables one of the 4 digital I/O channels. Just pass a number between 0 and 3 |
emh203 | 0:7798270c1f52 | 42 | void EnableMiscDigitalOutput(uint8_t DigitalOutIndex); |
emh203 | 0:7798270c1f52 | 43 | |
emh203 | 0:7798270c1f52 | 44 | //Disables one of the 4 digital I/O channels. Just pass a number between 0 and 3 |
emh203 | 0:7798270c1f52 | 45 | void DisableMiscDigitalOutput(uint8_t DigitalOutIndex); |
emh203 | 0:7798270c1f52 | 46 | |
emh203 | 0:7798270c1f52 | 47 | //Updates all of the Digital I/O, heater and solenoid channels. Call this function to enable all the queued up I/O commands |
emh203 | 0:7798270c1f52 | 48 | void FlushDigitalIO(); |
emh203 | 0:7798270c1f52 | 49 | |
emh203 | 0:7798270c1f52 | 50 | //Immediatelly disables all heaters and Solenoids. FlushDigitalIO() does not need to be called for this to have an effect |
emh203 | 0:7798270c1f52 | 51 | void DisableAllHeatersAndSolenoids(); |
emh203 | 0:7798270c1f52 | 52 | |
emh203 | 0:7798270c1f52 | 53 | //Enables the +/-15v power to the MFC Channels |
emh203 | 0:7798270c1f52 | 54 | void EnableMFC_Power(); |
emh203 | 0:7798270c1f52 | 55 | |
emh203 | 0:7798270c1f52 | 56 | //Disbales the +/-15v power to the MFC Channels |
emh203 | 0:7798270c1f52 | 57 | void DisableMFC_Power(); |
emh203 | 0:7798270c1f52 | 58 | |
emh203 | 0:7798270c1f52 | 59 | //Writes to one of the MFC Analog output channels. The Value given to the function is in volts |
emh203 | 0:7798270c1f52 | 60 | void WriteMFC_AnalogOut(uint8_t Channel,float Value); |
emh203 | 0:7798270c1f52 | 61 | |
emh203 | 0:7798270c1f52 | 62 | //Reads on the MFC Analog input channels. The value returned is in volts |
emh203 | 0:7798270c1f52 | 63 | float ReadMFC_AnalogInput(uint8_t Channel); |
emh203 | 0:7798270c1f52 | 64 | |
emh203 | 0:7798270c1f52 | 65 | //Reads a 4 to 20mA channel. value returned is in amps (.004 to .020) |
emh203 | 0:7798270c1f52 | 66 | float Read4to20(uint8_t Channel); |
emh203 | 0:7798270c1f52 | 67 | |
emh203 | 0:7798270c1f52 | 68 | //Turns the Fan on |
emh203 | 0:7798270c1f52 | 69 | void EnableFan(); |
emh203 | 0:7798270c1f52 | 70 | |
emh203 | 0:7798270c1f52 | 71 | //Turns the Fan off(); |
emh203 | 0:7798270c1f52 | 72 | void DisableFan(); |
emh203 | 0:7798270c1f52 | 73 | |
emh203 | 0:7798270c1f52 | 74 | // Makes the buzzer ring for a time period (in seconds) |
emh203 | 0:7798270c1f52 | 75 | //Note that this function immediately exits and the beeping is done in the background |
emh203 | 0:7798270c1f52 | 76 | //If you want to beep a couple times, you will need to delay for a certain time period after you call this function |
emh203 | 0:7798270c1f52 | 77 | //before you can call it again |
emh203 | 0:7798270c1f52 | 78 | void Buzz(float Time); |
emh203 | 0:7798270c1f52 | 79 | |
emh203 | 0:7798270c1f52 | 80 | //reads a thermocouple. Returns temperature in degrees C |
emh203 | 0:7798270c1f52 | 81 | float ReadThermocouple(uint8_t ThermocoupleIndex); |
emh203 | 0:7798270c1f52 | 82 | |
emh203 | 0:7798270c1f52 | 83 | //Determines if a thermocouple is disconnected. Each BIT in the return will be set if the Thermocouple is open. |
emh203 | 0:7798270c1f52 | 84 | //so, to see if a particular thermocouple is no connected, you need to bitmask the result. |
emh203 | 0:7798270c1f52 | 85 | /* |
emh203 | 0:7798270c1f52 | 86 | OC_State = ReadThermocouple_OC(); |
emh203 | 0:7798270c1f52 | 87 | |
emh203 | 0:7798270c1f52 | 88 | if(OC_State & (1<<5)) |
emh203 | 0:7798270c1f52 | 89 | { |
emh203 | 0:7798270c1f52 | 90 | //we are here if thermocouple 5 is not connected. The if statement does a bitwise AND to check the bit |
emh203 | 0:7798270c1f52 | 91 | } |
emh203 | 0:7798270c1f52 | 92 | |
emh203 | 0:7798270c1f52 | 93 | */ |
emh203 | 0:7798270c1f52 | 94 | uint16_t ReadThermocouple_OC(); |
emh203 | 0:7798270c1f52 | 95 | |
emh203 | 0:7798270c1f52 | 96 | |
emh203 | 0:7798270c1f52 | 97 | |
emh203 | 0:7798270c1f52 | 98 | //Determines if a thermocouple is shorted to ground. Each BIT in the return will be set if the Thermocouple is sorted to ground. |
emh203 | 0:7798270c1f52 | 99 | //so, to see if a particular thermocouple is shorted to ground, you need to bitmask the result. |
emh203 | 0:7798270c1f52 | 100 | /* |
emh203 | 0:7798270c1f52 | 101 | SCG_State = ReadThermocouple_SCG(); |
emh203 | 0:7798270c1f52 | 102 | |
emh203 | 0:7798270c1f52 | 103 | if(SCG_State & (1<<7)) |
emh203 | 0:7798270c1f52 | 104 | { |
emh203 | 0:7798270c1f52 | 105 | //we are here if thermocouple 7 is shorted to ground. The if statement does a bitwise AND to check the bit |
emh203 | 0:7798270c1f52 | 106 | } |
emh203 | 0:7798270c1f52 | 107 | |
emh203 | 0:7798270c1f52 | 108 | */ |
emh203 | 0:7798270c1f52 | 109 | uint16_t ReadThermocouple_SCG(); |
emh203 | 0:7798270c1f52 | 110 | |
emh203 | 0:7798270c1f52 | 111 | //Determines if a thermocouple is shorted to VCC. Each BIT in the return will be set if the Thermocouple is shorted to VCC. |
emh203 | 0:7798270c1f52 | 112 | //so, to see if a particular thermocouple is shorted to VCC, you need to bitmask the result. |
emh203 | 0:7798270c1f52 | 113 | /* |
emh203 | 0:7798270c1f52 | 114 | SCV_State = ReadThermocouple_SCG(); |
emh203 | 0:7798270c1f52 | 115 | |
emh203 | 0:7798270c1f52 | 116 | if(SCv_State & (1<<4)) |
emh203 | 0:7798270c1f52 | 117 | { |
emh203 | 0:7798270c1f52 | 118 | //we are here if thermocouple 5 is shorted to VCC. The if statement does a bitwise AND to check the bit |
emh203 | 0:7798270c1f52 | 119 | } |
emh203 | 0:7798270c1f52 | 120 | |
emh203 | 0:7798270c1f52 | 121 | */ |
emh203 | 0:7798270c1f52 | 122 | uint16_t ReadThermocouple_SCV(); |
emh203 | 0:7798270c1f52 | 123 | |
emh203 | 0:7798270c1f52 | 124 | |
emh203 | 0:7798270c1f52 | 125 | |
emh203 | 0:7798270c1f52 | 126 | //Determines if a thermocouple is faulted (see MAX31855 Datasheet). Each BIT in the return will be set if the Thermocouple is faulted |
emh203 | 0:7798270c1f52 | 127 | //so, to see if a particular thermocouple is faulted, you need to bitmask the result. |
emh203 | 0:7798270c1f52 | 128 | /* |
emh203 | 0:7798270c1f52 | 129 | Faulted_State = ReadThermocouple_FAULT(); |
emh203 | 0:7798270c1f52 | 130 | |
emh203 | 0:7798270c1f52 | 131 | if(Faulted_State & (1<<10)) |
emh203 | 0:7798270c1f52 | 132 | { |
emh203 | 0:7798270c1f52 | 133 | //we are here if thermocouple 10 is faulted The if statement does a bitwise AND to check the bit |
emh203 | 0:7798270c1f52 | 134 | } |
emh203 | 0:7798270c1f52 | 135 | |
emh203 | 0:7798270c1f52 | 136 | */ |
emh203 | 0:7798270c1f52 | 137 | |
emh203 | 0:7798270c1f52 | 138 | |
emh203 | 0:7798270c1f52 | 139 | uint16_t ReadThermocouple_FAULT(); |
emh203 | 0:7798270c1f52 | 140 | |
wavenumber | 2:73a028278c5c | 141 | /* |
wavenumber | 2:73a028278c5c | 142 | Read the internal reference temperature |
wavenumber | 2:73a028278c5c | 143 | */ |
wavenumber | 2:73a028278c5c | 144 | float ReadInternalTemperature(uint8_t ThermocoupleIndex); |
wavenumber | 2:73a028278c5c | 145 | |
emh203 | 0:7798270c1f52 | 146 | //Writes to one of the Misc Analog Output channels. The Value shoul dbe in Volts (from 0 to 5v) |
emh203 | 0:7798270c1f52 | 147 | void WriteMISC_AnalogOut(uint8_t Channel,float Value); |
emh203 | 0:7798270c1f52 | 148 | |
emh203 | 0:7798270c1f52 | 149 | //Reads one of the MISC Analog Input channels. The value returned will be in volts (from 0 to 5v) |
emh203 | 0:7798270c1f52 | 150 | float ReadMISC_AnalogInput(uint8_t Channel); |
emh203 | 0:7798270c1f52 | 151 | |
emh203 | 0:7798270c1f52 | 152 | //This function must be called in your main loop if you want the USB terminal interface to work! |
emh203 | 0:7798270c1f52 | 153 | void ProcessTerminal(); |
emh203 | 0:7798270c1f52 | 154 | |
emh203 | 0:7798270c1f52 | 155 | |
emh203 | 0:7798270c1f52 | 156 | //This is the Serial object (see MODSERIAL Documentation on the MBED site for details) for RS-232 channel 0 |
emh203 | 0:7798270c1f52 | 157 | extern MODSERIAL RS232_0; |
emh203 | 0:7798270c1f52 | 158 | |
emh203 | 0:7798270c1f52 | 159 | //This is the Serial object (see MODSERIAL Documentation on the MBED site for details) for RS-232 channel 0 |
emh203 | 0:7798270c1f52 | 160 | extern MODSERIAL RS232_1; |
emh203 | 0:7798270c1f52 | 161 | |
emh203 | 0:7798270c1f52 | 162 | //This is the serial object for the USB connection. Used by the Serial terminal |
emh203 | 0:7798270c1f52 | 163 | extern MODSERIAL PC; |
emh203 | 0:7798270c1f52 | 164 | |
wavenumber | 7:de452fceafc1 | 165 | //Process incomings lines from the PUmp |
wavenumber | 7:de452fceafc1 | 166 | void ProcessRS232(); |
emh203 | 0:7798270c1f52 | 167 | |
emh203 | 0:7798270c1f52 | 168 | #endif |