Skip to content

Temperature Alert configuration syntax might be confusing. #2

@fischermoseley

Description

@fischermoseley

The four temperature alerts on the MCP9600 have the following properties that are user-configurable:

Temperature - the temperature at which the alert is triggered (before hysteresis).
Junction - the junction to monitor for the alert. Can be configured to the on-die cold junction that measures ambient temperature, or the off-chip external thermocouple.
Hysteresis - the amount of hysteresis to use in triggering the alert.
Edge - trigger on either the rising or falling edge of the temperature.
Logic Level - make the hardware pins active-high or active-low.
Mode - configure the alert as either an interrupt or a comparator. The interrupt needs to be cleared, where the comparator can just be polled without anything else.
Enable - whether or not the alert is active.

Previously, these settings were all configured in a giant monolitihic function, prototyped like this:

 bool configAlert(uint8_t number, float tempLimit,                 //Configures the alert with the number of the alert to use, whether to use the hot or cold junction, how much hysteresis to use (in degrees C), 
 bool junction, uint8_t hysteresis, bool edge,                  //which edge to trigger on (rising or falling), activity (active high or active low), mode (comparator or interrupt), and whether everything is enabled         
 bool activity, bool mode, bool enable);

I think this is a little annoying and requires the user to have a big one-liner that configures their register. As a result, I broke everything up so that the alert configuration is prototyped like this:

//Temperature Alerts 
bool configAlertTemp(uint8_t number, float temp);                 //Configures the temperature at which to trigger the alert for a given alert number.
bool configAlertJunction(uint8_t number, bool junction);          //Configures the junction to monitor the temperature of to trigger the alert. Set to zero for the thermocouple (hot) junction, or one for the ambient (cold) junction.
bool configAlertHysteresis(uint8_t number, uint8_t hysteresis);   //Configures the hysteresis to use around the temperature set point, in degrees Celcius.
bool configAlertEdge(uint8_t number, bool edge);                  //Configures whether to trigger the alert on the rising (cold -> hot) or falling (hot -> cold) edge of the temperature change. Set to 1 for rising, 0 for falling.
bool configAlertLogicLevel(uint8_t number, bool level);           //Configures whether the hardware alert pin is active-high or active-low. Set to 1 for active-high, 0 for active-low.
bool configAlertMode(uint8_t number, bool mode);                  //Configures whether the MCP9600 treats the alert like a comparator or an interrrupt. Set to 1 for interrupt, 0 for comparator. More information is on pg. 34 of the datasheet.
bool configAlertEnable(uint8_t number, bool enable);              //Configures whether or not the interrupt is enabled or not. Set to 1 to enable, or 0 to disable.
bool clearAlert(uint8_t number);                                  //Clears the interrupt bit on the specified alert channel               
bool isAlertTriggered(uint8_t number);                            //Returns true if the interrupt has been triggered, false otherwise

But I don't know if this is any better because it requires a simple alert configuration to look like this (taken from Example6):

//configure the temperature alert for when the thermocouple is touched
tempSensor.configAlertEnable(risingAlert, 0); //disable the alert (if it was already enabled) while we configure it
tempSensor.configAlertTemp(risingAlert, alertTemp);
tempSensor.configAlertJunction(risingAlert, 0);
tempSensor.configAlertHysteresis(risingAlert, hysteresis);
tempSensor.configAlertEdge(risingAlert, HIGH);
tempSensor.configAlertLogicLevel(risingAlert, HIGH);
tempSensor.configAlertMode(risingAlert, 1);
tempSensor.configAlertEnable(risingAlert, 1); //enable the alert!

If I could get someone's thoughts on if there's a better way to do this, that would be great!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions