Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Multiplex Design Delay Routines

Status
Not open for further replies.

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?
 
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.
 
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
 
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.
 
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:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top