Subversion Repositories EngineBay2

Rev

Rev 25 | Rev 27 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 25 Rev 26
Line 188... Line 188...
188
        if (RPM_Pulsecount > 0)
188
        if (RPM_Pulsecount > 0)
189
        {
189
        {
190
                // now have time for N pulses in clocks
190
                // now have time for N pulses in clocks
191
                // need to scale by 19.55: one unit is 19.55 RPM
191
                // need to scale by 19.55: one unit is 19.55 RPM
192
                // 1Hz is 60 RPM
192
                // 1Hz is 60 RPM
193
                float new_RPM = (30.0 / 19.55 * RPM_Pulsecount * RPM_COUNT_RATE)
193
                float New_RPM = (30.0 / 19.55 * RPM_Pulsecount * RPM_COUNT_RATE)
194
                                / (RPM_FilteredWidth) + 0.5;
194
                                / (RPM_FilteredWidth) + 0.5;
195
 
-
 
-
 
195
// increase RPM filtering
196
                Coded_RPM += (new_RPM * Scale - Coded_RPM) / 4;
196
                Coded_RPM += (New_RPM * Scale - Coded_RPM) / 8;
197
 
197
 
198
#if !defined MY_DEBUG
198
#if !defined MY_DEBUG
199
                // reset here unless we want to debug
199
                // reset here unless we want to debug
200
                RPM_Pulsecount = 0;
200
                RPM_Pulsecount = 0;
201
                RPM_FilteredWidth = 0;
201
                RPM_FilteredWidth = 0;
Line 222... Line 222...
222
 
222
 
223
 
223
 
224
uint16_t CHT_Observations[2] =
224
uint16_t CHT_Observations[2] =
225
{ 0, 0 };
225
{ 0, 0 };
226
 
226
 
-
 
227
// look for the trigger pin being high then low - the points
-
 
228
// are opening, and skip the reading
-
 
229
 
-
 
230
 
227
void ProcessCHT(int instance)
231
void ProcessCHT(int instance)
228
{
232
{
229
        uint8_t buffer[2];
233
        uint8_t buffer[2];
230
        if (instance > 2)
234
        if (instance > 2)
231
                return;
235
                return;
232
        CHT_Timer[instance]++;
236
        CHT_Timer[instance]++;
-
 
237
 
-
 
238
        static uint8_t prevCB;
-
 
239
 
-
 
240
        uint8_t readCB =
-
 
241
        HAL_GPIO_ReadPin(CB_Pulse_GPIO_Port, CB_Pulse_Pin);
-
 
242
 
-
 
243
        if(!(prevCB == GPIO_PIN_SET && readCB ==
-
 
244
                                 GPIO_PIN_RESET) )
-
 
245
          {
-
 
246
 
233
        if ((CHT_Enable == ENABLE) && (CHT_Timer[instance] >= 4)) // every 300 milliseconds
247
        if ((CHT_Enable == ENABLE) && (CHT_Timer[instance] >= 4)) // every 300 milliseconds
234
        {
248
        {
235
 
249
 
236
                CHT_Timer[instance] = 0;
250
                CHT_Timer[instance] = 0;
237
 
251
 
Line 247... Line 261...
247
 
261
 
248
                // good observation if the status bit is clear, and the reading is less than 1023
262
                // good observation if the status bit is clear, and the reading is less than 1023
249
 
263
 
250
                uint16_t temp_c = obs>>5;
264
                uint16_t temp_c = obs>>5;
251
 
265
 
252
                uint8_t good = ((obs & 4) == 0) && (temp_c > 0) && (temp_c < 250);
266
                uint8_t good = ((obs & 7) == 0) && (temp_c > 0) && (temp_c < 250);
253
 
267
 
254
                if (good)
268
                if (good)
255
                {
269
                {
256
                        CHT_Observations[instance]=temp_c;
270
                        CHT_Observations[instance]=temp_c;
257
 
271
 
258
                }
272
                }
259
 
273
 
260
        }
274
        }
-
 
275
          }
261
 
276
 
-
 
277
        prevCB= readCB;
262
        plx_sendword(PLX_X_CHT);
278
        plx_sendword(PLX_X_CHT);
263
        PutCharSerial(&uc1, instance);
279
        PutCharSerial(&uc1, instance);
264
        plx_sendword(CHT_Observations[instance]);
280
        plx_sendword(CHT_Observations[instance]);
265
 
281
 
266
}
282
}
Line 477... Line 493...
477
        init_ADC_filter();
493
        init_ADC_filter();
478
 
494
 
479
        uint32_t Ticks = HAL_GetTick() + 100;
495
        uint32_t Ticks = HAL_GetTick() + 100;
480
        int CalCounter = 0;
496
        int CalCounter = 0;
481
 
497
 
482
        Power_CHT_Timer = HAL_GetTick() + 10000; /* wait 10 seconds before powering up the CHT sensor */
498
        Power_CHT_Timer = HAL_GetTick() + 1000; /* wait 10 seconds before powering up the CHT sensor */
483
 
499
 
484
 
500
 
485
 
501
 
486
 
502
 
487
  /* USER CODE END 2 */
503
  /* USER CODE END 2 */
Line 528... Line 544...
528
                }
544
                }
529
 
545
 
530
                if (Starter_Debounce == STARTER_LIMIT)
546
                if (Starter_Debounce == STARTER_LIMIT)
531
                {
547
                {
532
                        EnableCHT(DISABLE);
548
                        EnableCHT(DISABLE);
533
                        Power_CHT_Timer = HAL_GetTick() + 5000;
549
                        Power_CHT_Timer = HAL_GetTick() + 1000;
534
                }
550
                }
535
                else
551
                else
536
                /* if the Power_CHT_Timer is set then wait for it to timeout, then power up CHT */
552
                /* if the Power_CHT_Timer is set then wait for it to timeout, then power up CHT */
537
                {
553
                {
538
                        if ((Power_CHT_Timer > 0) && (HAL_GetTick() > Power_CHT_Timer))
554
                        if ((Power_CHT_Timer > 0) && (HAL_GetTick() > Power_CHT_Timer))