Problem with TIMER ON DELAY

Discussion in 'C' started by boschow, Jun 11, 2007.

  1. boschow

    boschow New Member

    Joined:
    Feb 22, 2007
    Messages:
    32
    Likes Received:
    0
    Trophy Points:
    0
    Hi all,
    i am programing a microprocessor. The system part of the application is already done, so i have to write the logic for all the inputs and the outputs ...

    In the system part of the the application there si a function UINT32 CSS_GetTime (UINT16 *ms) that gets the time in seconds and miliseconds since last reboot.

    ms - is the pointer that holds the number of miliseconds (0 ..999). Can be NULL if miliseconds are not needed.

    So i wrote the code something like this:
    Code:
    
    UINT32 get_time;
    UINT32 delay_time = 3;
    
    if input1 {
           get_time = CSS_GetTime(NULL);
           if get_time > delay_time {
                            output1 = 1;
         } else output1 = 0;
    }
    
    This part of the program only works after the reset, because the get_time is never set to zero. Any ideas how can i do this?

    I also tryed with miliseconds. Code:
    Code:
    UINT16 get_mili_sec=0;
    UINT32 get_time;
    UINT32 time_increment;
    UINT32 delay_time = 3;
    UINT32 curr_time;
    
    if input1 {
           get_time = CSS_GetTime (&get_mili_sec);
              if (get_time == 999) {
                       time_increment = 1;
              } else time_increment = 0;
              curr_time += time_increment;
              if (curr_time > delay_time) {
                     output = 1;
                     curr_time = 0;
              } else output = 0;
                        curr_time = 0;
    }
    
    This part of the program also dosent work. Can somebody tell me what am i doing wrong?

    Thx for your time and help,
    Best regards,
    BoSCHoW.
     
  2. boschow

    boschow New Member

    Joined:
    Feb 22, 2007
    Messages:
    32
    Likes Received:
    0
    Trophy Points:
    0
    The timer, is working now. But once the output is set i cannot put it to 0 even if the input is pressed for a shorter time then 3000 ms. I dont know what i did wrong, can somebody help me. Below is the code that i used ...
    Code:
    if (contactor == 1) output1=1;
    else output1=0;
    
    // RS FLIP FLOP SETS FINAL OUTPUT
     (!key_not_pressed 
        && (time_key_active== 0))      contactor = 0;
    else if (!key_not_pressed 
             && (time_key_active == 1)) contactor = 1;
    else if (key_not_pressed 
             && (time_key_active == 0)) contactor = 0;
    else if (key_not_pressed 
             && (time_key_active == 1)) contactor = 0;
    
    //     LOGIC AND - chaks the status of the key
    if ((key_check_status ==0)    // check key status failed 
         && input1) // key pressed
    		key_not_pressed = 0;
    else if ((key_check_status ==0)  // check key status failed
         && !input1) // key not pressed
    		key_not_pressed  = 0;
    else if ((key_check_status ==1) // check key status success
         && !input1)  // key not presset 
                    key_not_pressed  = 1;
    else if ((preverjanje_stanja_tipke==1)	// check key stats success
         &&  input1) // key pressed
                    key_not_pressed  = 0;
    
    // FLIP FLOP - CHECK KEY STATUS
    if (input1  // key pressed
        && (time_key_active == 0))	// key not active
    		preverjanje_stanja_tipke = 1;
    else if (input1 // key pressed
        && (time_key_active == 1)) // key active
        key_check_status = 0;
    else if (!input1 // key not pressed 
        && (time_key_active == 0)) // key not active
        key_check_status = 0;
    else if (!input1 // key not pressed 
        && (time_key_active== 1)) // key active
        key_check_status = 0;
    
     //		 TIMER STARTER
    if (input1) {
        begin_s = CSS_GetTime(&begin_ms);
          do {
            time_key_active= 0;
            now_ms = 0;
            now_s = CSS_GetTime(&now_ms);
            passed_time = (now_s - begin_s) * 1000 + (now_ms - begin_ms);
          
          }
          while (passed_time < 3000);
          time_key_active= 1;
    }
    
    Thanks for your time and help,
    best regards,
    BoSCHoW.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice