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.