diff --git a/TC1/main.h b/TC1/main.h index b315ca7..81b6c48 100644 --- a/TC1/main.h +++ b/TC1/main.h @@ -4,7 +4,7 @@ #include "mico.h" #include "MiCOKit_EXT.h" -#define VERSION "v0.7" +#define VERSION "v0.8" #define TYPE 1 #define TYPE_NAME "zTC1" @@ -26,10 +26,10 @@ #define Relay_OFF 0 #define Relay_0 MICO_GPIO_6 -#define Relay_1 MICO_GPIO_7 -#define Relay_2 MICO_GPIO_8 -#define Relay_3 MICO_GPIO_9 -#define Relay_4 MICO_GPIO_10 +#define Relay_1 MICO_GPIO_8 +#define Relay_2 MICO_GPIO_10 +#define Relay_3 MICO_GPIO_7 +#define Relay_4 MICO_GPIO_9 #define Relay_5 MICO_GPIO_18 #define Relay_NUM PLUG_NUM diff --git a/TC1/user_power.c b/TC1/user_power.c index 3f34a07..b0158f3 100644 --- a/TC1/user_power.c +++ b/TC1/user_power.c @@ -9,34 +9,60 @@ mico_timer_t power_timer; -static uint32_t timer_count_last = 0; +static uint32_t clock_count_last = 0; +static uint32_t clock_count = 0; static uint32_t timer_count = 0; -static uint32_t timer = 0; +static uint32_t timer_irq_count = 0; static void power_timer_handler( void* arg ) { // uint8_t pin_input = MicoGpioInputGet( POWER ); - if ( timer_count_last != timer_count ) - { -// os_log("power_irq_handler:%u-%u=%u",timer_count,timer_count_last,timer); - timer_count_last = timer_count; + uint32_t timer = 0; - timer=timer/1000; - power=9500000/timer; - os_log("power_irq_handler:%u,%07u",power,timer); + if ( timer_irq_count > 1 ) + { + timer = (clock_count - clock_count_last); + + os_log("power_irq_handler:%09u %u %u",timer,timer_irq_count,timer_count); + if ( timer_count > 3 ) + { + timer /= 1000; + timer += 4294967; //0xffffffff/1000; + } else if ( clock_count < clock_count_last ) + { + timer += 0xffffffff; + timer /= 1000; + }else timer/=1000; + power = 17100000 * (timer_irq_count - 1) / timer; + timer_count = 0; + timer_irq_count = 0; + } else + { + timer_count++; } -// if(timer_count==0) os_log("power_timer_handler Hight:%d",timer_count_last); + +// if ( clock_count_last != timer_count ) +// { +//// os_log("power_irq_handler:%u-%u=%u",timer_count,clock_count_last,timer); +// timer = (timer_count - clock_count_last); +// if ( timer_count < clock_count_last ) timer += 0xffffffff; +// +// timer = timer / 1000; +// power = 15200000 / timer; +// os_log("power_irq_handler:%u,%07u",power,timer); +// clock_count_last = timer_count; +// } +// if(timer_count==0) os_log("power_timer_handler Hight:%d",clock_count_last); // timer_count++; -// timer_count_last=timer_count; +// clock_count_last=timer_count; } static void power_irq_handler( void* arg ) { -// timer_count_last=timer_count; - timer_count = mico_nanosecond_clock_value(); - timer=timer_count-timer_count_last; - if(timer_count