From e26da4aff996d203e443c43f405962bb5a0efc39 Mon Sep 17 00:00:00 2001 From: MX682X Date: Tue, 10 Oct 2023 21:41:25 +0200 Subject: [PATCH] fixes V2 --- megaavr/libraries/PTC/README.md | 16 ++++++++-------- megaavr/libraries/PTC/src/ptc.c | 16 ++++++++-------- megaavr/libraries/PTC/src/ptc.h | 6 +++--- megaavr/libraries/PTC/src/ptc_types.h | 10 +++++----- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/megaavr/libraries/PTC/README.md b/megaavr/libraries/PTC/README.md index 0b760450..5d815336 100644 --- a/megaavr/libraries/PTC/README.md +++ b/megaavr/libraries/PTC/README.md @@ -1,4 +1,4 @@ -# ptc_touch +# PTC Library An Arduino compatible C library to support the PTC in the AtTiny 1-Series ## Features @@ -89,7 +89,7 @@ The ptc_ch_bm_t is a typedef that depends on the pincount of the device and rang ### PTC Operation ![PTC_InnerWorkings](https://github.com/MX682X/ptc_touch/assets/58419867/823c487c-0633-4031-b381-45e7a32867fb) -(Source: [Microchip's PTC Subsystem Firmware User's Guide](https://web.archive.org/web/20221225142000/https://www.mouser.com/pdfdocs/SAMA5D2_PTC_Firmware_UG.pdf)) +(Source: [Microchip's PTC Subsystem Firmware User's Guide]()) This schematic was made for a different chip, but it is likely to look similar on the AVRs. Most of the following is a hypothesis based on the publicly available documentation and observation. @@ -127,9 +127,9 @@ If a node is not sensitive enough, you can increase the Analog Gain (if it becom ### Global settings of the State-maschine The state-machine, which changes the node's state between Calibration, touch, no touch, etc. uses some variables that are valid for all nodes, those are: - - `uint16_t force_recal_delta`. Each node has a threshold value that is used to calculate the delta. This Threshold value is drifting over time to adjust for environmental changes. If the threshold value drifts 512 +/- this value, a recalibration of CC is performed. Default: 150 - - `uint8_t touched_detect_nom`. Number of consecutive Measurements (Conversions) that are above the touch threshold until the node becomes "touched". Default: 3 - - `uint8_t untouched_detect_nom`. Number of consecutive measurements that are below the no-touch threshold until the node is fully untouched. Default: 3 - - `uint8_t touched_max_nom`. Number of consecutive measurements plus one in the touched state until a recalibration is forced. Can be disabled by writing 255 to it. Default: 200 - - `uint8_t drift_up_nom`. If the delta is higher then the reference, but lower then the threshold, the amount of consecutive measurements plus one, until the reference is incremented. Can be disabled with 255. Default: 20. - - `uint8_t drift_down_nom`. If the delta is below the reference, the amount of consecutive measurements plus one until the reference is decremented. Can be disabled with 255. Default: 20. +- `uint16_t force_recal_delta`. Each node has a threshold value that is used to calculate the delta. This Threshold value is drifting over time to adjust for environmental changes. If the threshold value drifts 512 +/- this value, a recalibration of CC is performed. Default: 150 +- `uint8_t touched_detect_nom`. Number of consecutive Measurements (Conversions) that are above the touch threshold until the node becomes "touched". Default: 3 +- `uint8_t untouched_detect_nom`. Number of consecutive measurements that are below the no-touch threshold until the node is fully untouched. Default: 3 +- `uint8_t touched_max_nom`. Number of consecutive measurements plus one in the touched state until a recalibration is forced. Can be disabled by writing 255 to it. Default: 200 +- `uint8_t drift_up_nom`. If the delta is higher then the reference, but lower then the threshold, the amount of consecutive measurements plus one, until the reference is incremented. Can be disabled with 255. Default: 20. +- `uint8_t drift_down_nom`. If the delta is below the reference, the amount of consecutive measurements plus one until the reference is decremented. Can be disabled with 255. Default: 20. diff --git a/megaavr/libraries/PTC/src/ptc.c b/megaavr/libraries/PTC/src/ptc.c index 7ce8e945..25337796 100644 --- a/megaavr/libraries/PTC/src/ptc.c +++ b/megaavr/libraries/PTC/src/ptc.c @@ -43,8 +43,8 @@ volatile cap_sensor_t *currConvNode = NULL; ptc_node_type_t currConvType = 0; // does not "remember" if type was low-power ptc_node_type_t nextConvType = 0; -uint16_t acqPeriod = 20; // Period in ms until a new acquision is started -uint16_t lastAcqTime = 0; // millis value of last Acqusition (16-bit) +uint16_t acqPeriod = 20; // Period in ms until a new acquisition is started +uint16_t lastAcqTime = 0; // millis value of last acquisition (16-bit) ptc_freq_t freq_select = 0; /* FREQ_SEL_0 to FREQ_SEL_15, FREQ_SEL_SPREAD -> CTRLD */ @@ -149,7 +149,7 @@ uint8_t ptc_node_set_resistor(cap_sensor_t* node, uint8_t res) { } -// Change preschaler. Recomended ADC frequency: < 1.5MHz, but max 3 factors below +// Change pre-scaler. Recommended ADC frequency: < 1.5MHz, but max 3 factors below uint8_t ptc_node_set_prescaler(cap_sensor_t* node, uint8_t presc) { PTC_CHECK_FOR_BAD_POINTER(node); @@ -184,7 +184,7 @@ uint8_t ptc_node_set_gain(cap_sensor_t* node, uint8_t aGain, uint8_t dGain) { /* * Two functions to suspend and resume of the normal PTC operation, however, - * this functions will only work when no acqusition is in progress. Neither + * this functions will only work when no acquisition is in progress. Neither * when the library is in low-power mode. This is due to the fact that the * low-power mode relies on the registers being set once, at the low-power * initialization. Thus, the user has to disable LP mode, then suspend, resume @@ -539,8 +539,8 @@ void ptc_process_node_sm (cap_sensor_t* node) { } - } else if (nodeSM & PTC_SM_NO_TOUCH) { /* default State, no touch */ - if (nodeDelta < -150) { /* if the touch value is way too small, something chnaged with the lines, recal */ + } else if (nodeSM & PTC_SM_NO_TOUCH) { /* default State, no touch */ + if (nodeDelta < -150) { /* if the touch value is way too small, something changed with the lines, recalibrate */ nodeSM = PTC_SM_RECAL_FLT; } else if (nodeDelta >= node->touch_in_th) { nodeSM = PTC_SM_TOUCH_IN_FLT; @@ -924,7 +924,7 @@ void ptc_set_registers(cap_sensor_t* node) { pPTC->CTRLA = ADC_RUNSTBY_bm | ADC_ENABLE_bm; /* 0x81 */ if (0 == node->state.low_power) - pPTC->COMMAND = 0x01; // Normal opertion: Manual Start + pPTC->COMMAND = 0x01; // Normal operation: Manual Start else pPTC->EVCTRL = 0x01; // Low Power: Start by positive Flank on Event #elif defined (__PTC_DA__) @@ -934,7 +934,7 @@ void ptc_set_registers(cap_sensor_t* node) { void ptc_eoc(void) { PTC_t *pPTC; - volatile cap_sensor_t *pCurrentNode; // volatile nedded to pass type check + volatile cap_sensor_t *pCurrentNode; // volatile needed to pass type check _fastPtr_d(pPTC,&PTC); _fastPtr_d(pCurrentNode,currConvNode); diff --git a/megaavr/libraries/PTC/src/ptc.h b/megaavr/libraries/PTC/src/ptc.h index 7ff70370..c074f62d 100644 --- a/megaavr/libraries/PTC/src/ptc.h +++ b/megaavr/libraries/PTC/src/ptc.h @@ -62,7 +62,7 @@ extern "C" { // if it's Flash, it will be 0x80, as signed it means negative. // if it's anything else (I/O, EEPROM, etc.), p will be <= 14 // thus making a signed check will make pretty sure the pointer points to a RAM address -// Disadvantage: GCC can not validate this at compiletime as it does not know the variable's +// Disadvantage: GCC can not validate this at compile time as it does not know the variable's // address at compile-time. #define PTC_CHECK_POINTER(__p__, __ret__) \ if (((int8_t)((uint16_t)__p__ >> 8)) < 0x38) { \ @@ -100,7 +100,7 @@ uint8_t ptc_enable_node(cap_sensor_t* node); // Disables a node. If the conversion is started, it will be finished uint8_t ptc_disable_node(cap_sensor_t* node); -// Can be used outside an acqusition process to select ADC/SELFCAP/MUTUAL/SHIELD +// Can be used outside an acquisition process to select ADC/SELFCAP/MUTUAL/SHIELD void ptc_set_next_conversion_type(ptc_node_type_t type); // Main task handle for PTC. Handles State-Machine, drift, and calibration @@ -149,7 +149,7 @@ inline uint8_t ptc_add_mutualcap_node(cap_sensor_t* node, const ptc_ch_bm_t yCh, uint8_t ptc_suspend(void); void ptc_resume(void); -// If you want to know the compensation capacitance in fempto Farrad +// If you want to know the compensation capacitance in femto Farrad uint16_t ptc_get_node_cc_femto(cap_sensor_t* node); ptc_lib_sm_set_t* ptc_get_sm_settings(); diff --git a/megaavr/libraries/PTC/src/ptc_types.h b/megaavr/libraries/PTC/src/ptc_types.h index 28cea3b8..8dcb5797 100644 --- a/megaavr/libraries/PTC/src/ptc_types.h +++ b/megaavr/libraries/PTC/src/ptc_types.h @@ -1,5 +1,5 @@ -/* - * Refer to ptc_touch.h file for copyright, changelog, usage and license information +/* + * Refer to ptc_touch.h file for copyright, changelog, usage and license information */ @@ -55,7 +55,7 @@ extern "C" { /** * PTC series resistor setting. For Mutual cap mode, this series * resistor is switched internally on the Y-pin. For Self cap mode, - * thes series resistor is switched internally on the Sensor pin. + * the series resistor is switched internally on the Sensor pin. * * Example: * RSEL_VAL_0 sets internal series resistor to 0ohms. @@ -221,10 +221,10 @@ typedef struct cap_sensor_type { // Abbreviation: NoM: Number of Measurements typedef struct ptc_lib_sm_settings_type { - uint16_t force_recal_delta; // if the threshold value exceeds this compared to optimal (512), force recalibration. Defualt: 150 + uint16_t force_recal_delta; // if the threshold value exceeds this compared to optimal (512), force recalibration. Default: 150 uint8_t touched_detect_nom; // NoM above node threshold for the node to become touched. Default: 3 uint8_t untouched_detect_nom; // NoM below node threshold for the node to become untouched. Default: 3 - uint8_t touched_max_nom; // NoM a touch was detected until a recal if forced. Value +1. Disabled with 0xFF. Default: 200 + uint8_t touched_max_nom; // NoM a touch was detected until a recalibration is forced. Value +1. Disabled with 0xFF. Default: 200 uint8_t drift_up_nom; // NoM when no touch is detected, until the threshold is increased. Value +1. Disabled with 0xFF. Default: 20 uint8_t drift_down_nom; // NoM when no touch is detected, until the threshold is decreased. Value +1. Disabled with 0xFF. Default: 20 } ptc_lib_sm_set_t;