Close

TIM 4 routine

A project log for Moto_oiler

Trying to build my own chain lubrication system with blackjack&etc.

zaksignuzaksignu 02/19/2019 at 16:380 Comments

Main flashing cycle contains 5 TIM4 tick. During TIM4 ticking, orderstate variable moves from 0 to 4 and returns to 0. 

  

      orderstate

       0          1            2           3         4          
        |250мс|250мс|250мс|250мс|250мс|
       ------------------------------------------------------
        |||||||||||||||            |||||||||||||||||   

{
switch (flow_state)   //  looking for flow state
{
  case 1: // switch FLOW ON
                if (PB_ODR_bit.ODR2 == 0) PB_ODR_bit.ODR2 = 1;  
  case 0:// switch FLOW OFF
                if (PB_ODR_bit.ODR2 == 1) PB_ODR_bit.ODR2 = 0;          
}
switch (oiler_status)  // looking for global status and fire led
{
  case _idle:
                PB_ODR_bit.ODR7 = idle[orderstate][0];
                PB_ODR_bit.ODR6 = idle[orderstate][1];
                break;
  case _someoil:
                PB_ODR_bit.ODR7 = someoil[orderstate][0];
                PB_ODR_bit.ODR6 = someoil[orderstate][1];
                break;
  case _littleoil:
                PB_ODR_bit.ODR7 = littleoil[orderstate][0];
                PB_ODR_bit.ODR6 = littleoil[orderstate][1];
                break;
  case _nocurr:
                PB_ODR_bit.ODR7 = nocurr[orderstate][0];
                PB_ODR_bit.ODR6 = nocurr[orderstate][1];
                break;
  case _overcurr:
                PB_ODR_bit.ODR7 = overcurr[orderstate][0];
                PB_ODR_bit.ODR6 = overcurr[orderstate][1];
                break;
  case _flow:
                PB_ODR_bit.ODR7 = overcurr[orderstate][0];
                PB_ODR_bit.ODR6 = overcurr[orderstate][1];
                break;
}

if (orderstate >= 4) {orderstate = 0;} else {++orderstate;};
TIM4_SR1_bit.UIF = 0;
}

Discussions