mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-25 11:46:31 +00:00
Make ZCD user configurable using GPIO ZC Pulse
This commit is contained in:
parent
88e00b1041
commit
0d54299aaf
@ -169,7 +169,7 @@ void ZeroCrossMomentStart(void) {
|
||||
while (!TimeReached(timeout) && !TimeReachedUsec(trigger_moment)) {}
|
||||
|
||||
// uint32_t dbg_endtime = micros();
|
||||
// AddLog(LOG_LEVEL_DEBUG, PSTR("ZCR: CodeExecTime %d, StartTime %d, EndTime %d, ZcTime %d, Interval %d"),
|
||||
// AddLog(LOG_LEVEL_DEBUG, PSTR("ZCD: CodeExecTime %d, StartTime %d, EndTime %d, ZcTime %d, Interval %d"),
|
||||
// dbg_endtime - dbg_starttime, dbg_starttime, dbg_endtime, dbg_zctime, dbg_interval);
|
||||
|
||||
TasmotaGlobal.zc_code_offset = micros();
|
||||
@ -180,7 +180,7 @@ void ZeroCrossMomentEnd(void) {
|
||||
|
||||
TasmotaGlobal.zc_code_offset = (micros() - TasmotaGlobal.zc_code_offset) / 2;
|
||||
|
||||
// AddLog(LOG_LEVEL_DEBUG, PSTR("ZCR: CodeExecTime %d"), TasmotaGlobal.zc_code_offset * 2);
|
||||
// AddLog(LOG_LEVEL_DEBUG, PSTR("ZCD: CodeExecTime %d"), TasmotaGlobal.zc_code_offset * 2);
|
||||
}
|
||||
|
||||
void ICACHE_RAM_ATTR ZeroCrossIsr(void) {
|
||||
@ -190,10 +190,16 @@ void ICACHE_RAM_ATTR ZeroCrossIsr(void) {
|
||||
if (!TasmotaGlobal.zc_time) {TasmotaGlobal.zc_time = 1; }
|
||||
}
|
||||
|
||||
void ZeroCrossInit(uint32_t gpio, uint32_t offset) {
|
||||
TasmotaGlobal.zc_offset = offset;
|
||||
pinMode(gpio, INPUT_PULLUP);
|
||||
attachInterrupt(gpio, ZeroCrossIsr, CHANGE);
|
||||
void ZeroCrossInit(uint32_t offset) {
|
||||
if (PinUsed(GPIO_ZEROCROSS)) {
|
||||
TasmotaGlobal.zc_offset = offset;
|
||||
|
||||
uint32_t gpio = Pin(GPIO_ZEROCROSS);
|
||||
pinMode(gpio, INPUT_PULLUP);
|
||||
attachInterrupt(gpio, ZeroCrossIsr, CHANGE);
|
||||
|
||||
AddLog(LOG_LEVEL_INFO, PSTR("ZCD: Activated")); // Zero-cross detection activated
|
||||
}
|
||||
}
|
||||
|
||||
/********************************************************************************************/
|
||||
|
@ -21,8 +21,13 @@
|
||||
#ifdef USE_CSE7761
|
||||
/*********************************************************************************************\
|
||||
* CSE7761 - Energy (Sonoff Dual R3 Pow)
|
||||
*
|
||||
* Without zero-cross detection
|
||||
* {"NAME":"Sonoff Dual R3","GPIO":[32,0,0,0,0,0,0,0,0,576,225,0,0,0,0,0,0,0,0,0,0,7296,7328,224,0,0,0,0,160,161,0,0,0,0,0,0],"FLAG":0,"BASE":1}
|
||||
*
|
||||
* With zero-cross detection
|
||||
* {"NAME":"Sonoff Dual R3 (ZCD)","GPIO":[32,0,0,0,7552,0,0,0,0,576,225,0,0,0,0,0,0,0,0,0,0,7296,7328,224,0,0,0,0,160,161,0,0,0,0,0,0],"FLAG":0,"BASE":1}
|
||||
*
|
||||
* Based on datasheet from ChipSea and analysing serial data
|
||||
* See https://github.com/arendst/Tasmota/discussions/10793
|
||||
\*********************************************************************************************/
|
||||
@ -33,7 +38,6 @@
|
||||
#define CSE7761_FREQUENCY // Add support for frequency monitoring
|
||||
#define CSE7761_ZEROCROSS // Add zero cross detection
|
||||
#define CSE7761_ZEROCROSS_OFFSET 2200 // Zero cross offset due to chip calculation (microseconds)
|
||||
#define CSE7761_ZEROCROSS_GPIO 4 // Sonoff Dual R3 pulse input
|
||||
|
||||
#define CSE7761_UREF 42563 // RmsUc
|
||||
#define CSE7761_IREF 52241 // RmsIAC
|
||||
@ -576,7 +580,7 @@ void Cse7761SnsInit(void) {
|
||||
|
||||
#ifdef CSE7761_FREQUENCY
|
||||
#ifdef CSE7761_ZEROCROSS
|
||||
ZeroCrossInit(CSE7761_ZEROCROSS_GPIO, CSE7761_ZEROCROSS_OFFSET);
|
||||
ZeroCrossInit(CSE7761_ZEROCROSS_OFFSET);
|
||||
#endif // CSE7761_ZEROCROSS
|
||||
#endif // CSE7761_FREQUENCY
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user