# Multiplex Design Delay Routines

#### Suraj143

##### Active Member
I’m doing a 16 row X 32 column matrix design & the display multiplexing is done in the ISR. At 1mS rate I’m getting into the ISR & update each row on every interrupt. For a frame it will take 1mS X 16 = 16mS.

I need to show moving patterns on the display & for that I need to generate delay routines (In the main code). For the time being I use delays using just delay loop codes.

The problem is, I see a very little flicker thing when the patterns moving. Do I need to generate delays using frames instead of just delay loops?

#### Pommie

##### Well-Known Member
If you have a 1 mS interrupt then use that to increment a counter and use the counter to time things.

Something like nextEvent=counter+20 and then if(counter>=nextEvent) will execute your code 50 times per second.

Mike.

#### Suraj143

##### Active Member
Hi Thanks for the idea.

You mean something like this?

Code:
ISR_Enter        incf        Counter,F    ;1mS update rate
retfie

Main_Code        call        Pattern1
call        Delay_50mS
call        Pattern1
call        Delay_80mS
----
----

Delay_50mS        clrf        Counter
movf        Counter,W
xorlw        .50
btfss        STATUS,Z
goto        $-3 return Delay_80mS clrf Counter movf Counter,W xorlw .80 btfss STATUS,Z goto$-3
return

#### Pommie

##### Well-Known Member
I was thinking more like this,
Code:
IRQ{        counter++;
}

main{
while(1){
if(counter>=timeUp){
timeUp=counter+20;        wait 20mS
//do things here 50 times per second
{
if(counter>=timeUp2){
timeUp2=counter+50;
//do things here 20 times per second
}
}
}
Mike.
edit, in your case the while(1) would be replaced with a goto main at the end of your code.
Note, if you have count as 32 bit then it will stop working after 49 days due to wrap around.

#### Suraj143

##### Active Member
I got what you mean. You are doing subroutines by comparing the counter variable.So it will work according to predetermined periods.

I need fix delay routines 20mS,30mS,40mS,50mS, 80mS & 100mS. Need to call them whenever I wanted without affecting ISR mux.

Clearing the Counter variable will lead to achieve a maximum 1mS delay error

Code:
Delay_50mS        clrf        Counter
movf        Counter,W
xorlw        .50
btfss        STATUS,Z
goto        \$-3
return

Last edited: