File tree Expand file tree Collapse file tree 1 file changed +9
-8
lines changed Expand file tree Collapse file tree 1 file changed +9
-8
lines changed Original file line number Diff line number Diff line change @@ -33,6 +33,8 @@ static uint8_t env_cnt = 0;
3333static bool env_saved = true;
3434
3535static double time_val = 0.0 ;
36+ static double time_sum = 0.0 ;
37+
3638static bool first_edge = true;
3739static bool period_done = true;
3840
@@ -135,7 +137,6 @@ static void pwm_init(void)
135137static void fan_task (void * pvParameter )
136138{
137139 uint8_t rpm_cnt = 0 ;
138- double rpm_sum = 0.0 ;
139140 uint32_t fan_evt = 0 ;
140141
141142 tim_init ();
@@ -181,23 +182,23 @@ static void fan_task(void *pvParameter)
181182 if (rpm_cnt ++ == 4 ) {
182183 rpm_cnt = 0 ;
183184
184- fan_rpm = rpm_sum / 4.0 ;
185+ fan_rpm = 60.0 / time_sum ;
185186
186- rpm_sum = 0.0 ;
187+ time_sum = 0.0 ;
187188 } else {
188- rpm_sum += 15.0 / time_val ;
189+ time_sum += time_val ;
189190 }
190191 break ;
191192 default :
192193 break ;
193194 }
194195 } else {
196+ rpm_cnt = 0 ;
197+ fan_rpm = 0 ;
198+ time_sum = 0.0 ;
199+
195200 first_edge = true;
196201 period_done = true;
197-
198- fan_rpm = 0 ;
199- rpm_cnt = 0 ;
200- rpm_sum = 0.0 ;
201202 }
202203
203204 if (!env_saved && env_cnt ++ == 50 ) {
You can’t perform that action at this time.
0 commit comments