1. 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.
    Dismiss Notice

Multiplex Design Delay Routines

Discussion in 'Microcontrollers' started by Suraj143, Feb 27, 2018.

  1. Suraj143

    Suraj143 Active Member

    Joined:
    Jan 11, 2007
    Messages:
    1,635
    Likes:
    2
    Location:
    South Mald Isld
    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?
     
  2. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,710
    Likes:
    421
    Location:
    Brisbane Australia
    ONLINE
    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.
     
  3. Suraj143

    Suraj143 Active Member

    Joined:
    Jan 11, 2007
    Messages:
    1,635
    Likes:
    2
    Location:
    South Mald Isld
    Hi Thanks for the idea.

    You mean something like this?

    Code (text):
             
    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
     
  4. dave miyares

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    2
    Likes:
    -10


     
  5. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,710
    Likes:
    421
    Location:
    Brisbane Australia
    ONLINE
    I was thinking more like this,
    Code (text):

    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.
     
  6. Suraj143

    Suraj143 Active Member

    Joined:
    Jan 11, 2007
    Messages:
    1,635
    Likes:
    2
    Location:
    South Mald Isld
    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 (text):

    Delay_50mS        clrf        Counter
                movf        Counter,W
                xorlw        .50
                btfss        STATUS,Z
                goto        $-3
                return
     
    Last edited: Feb 27, 2018

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