How to do a specific task after some time

cembeddedmicrochipmicrocontroller

I have to switch on one relay after some specific time, but at same time I have to do continuous polling for controlling other relays, I am already using interrupt for multiplexing purpose (7 segment display). How can I accomplish this?

Best Answer

You could use your existing interrupt to increment a counter. You should know the period of your existing interrupt already, so divide your required time by that period and that's the number of counts of your counter you need to check for.

For instance, if your multiplexing interrupt happens once every 5ms and you need to wait 10 seconds, then you would wait for your counter to count up to (10 / 0.005 = ) 2000. When you see your counter exceed that value you would then reset the counter and perform your periodic tasks.