Darrel's interrupts in a 7 segment display


Closed Thread
Results 1 to 17 of 17

Hybrid View

  1. #1
    Join Date
    Oct 2004
    Posts
    448

    Default Darrel's interrupts in a 7 segment display

    I have a design with a 3 digit 7 segment multiplexed display that showed a certain value. The circuit and the code worked fine while the display was about the only thing the PIC had to do.

    Now, I tried to use Darrel's "DT_INTS-14.bas" as I need a few other things done in the code as well.

    The chip is a 16F887.

    My observations; the display flickers a lot; changing the prescaler to 1:1 is still bad, but better than other settings. Pre-loading TMR1 with any value seems to have no effect.

    What am I doing wrong?


    ANSEL = 0
    ANSELH = 0
    CM1CON0.7 = 0
    CM2CON0.7 = 0

    TRISA = 0
    TRISB = 0
    TRISC = 0
    TRISD = 0
    TRISE = 0

    N VAR BYTE

    SEGDEF VAR BYTE

    INCLUDE "DT_INTS-14.bas" ' Base Interrupt System
    INCLUDE "ReEnterPBP.bas" ' Include if using PBP interrupts

    ASM
    INT_LIST macro ; IntSource, Label, Type, ResetFlag?
    INT_Handler TMR1_INT, _DISP, PBP, yes
    endm
    INT_CREATE ; Creates the interrupt processor
    ENDASM

    T1CON = $1
    ; Prescaler = 8, TMR1ON
    @ INT_ENABLE TMR1_INT ; enable Timer 1 interrupts

    Main:


    '********************
    TMR1H = %11111111
    TMR1L = %11110111
    '********************

    toggle stat_LED
    pause 500

    GOTO Main

    '---[TMR1 - interrupt handler]--------------------------------------------------
    DISP: N = 1
    GOSUB BIN2SEG
    PORTC = SEGDEF
    PORTE = 6
    PAUSE 3

    N = 2
    GOSUB BIN2SEG
    PORTC = SEGDEF
    PORTE = 5
    PAUSE 3

    N = 3
    GOSUB BIN2SEG
    PORTC = SEGDEF
    PORTE = 3
    PAUSE 3

    @ INT_RETURN

    BIN2SEG:LookUp n,[132,175,193,137,170,152,144,143,128,136,210,251],SEGDEF

    Return

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    My observations; the display flickers a lot; changing the prescaler to 1:1 is still bad, but better than other settings. Pre-loading TMR1 with any value seems to have no effect.
    Blinky?? No doubt!

    Assuming a 4Mhz OSC, your interrupt frequency is ~15Hz (~65.5ms).
    Then each digit is shown for ~3ms for a total of 9ms out of that 65.5.
    With the third digit left ON, that one's probably very bright.
    What am I doing wrong?
    For one, you need to reload the Timer in the Interrupt Handler, not the Main loop.
    The interrupt frequency should be at least 300Hz, 1Kz is better.

    Code:
    DISP:
      T1CON.0 = 0     ; stop timer
      TMR1H = %11111100
      TMR1L = %00011111
      T1CON.0 = 1     ; restart timer
    And in the handler, only turn on 1 digit per interrupt. Don't pause, don't gosub.
    DT

  3. #3


    Did you find this post helpful? Yes | No

    Default Don't pause, don't gosub

    ahhhh, there's the kick i needed.
    I also am working on a 3digit 7seg led display, using modified code
    (read: massively mangled stolen code :P)
    and was doing the same thing..
    (pausing, and calling/gosubing the bin2seg lookup)

    Code:
    MOVF _led1data,W
     call bin2seg
     MOVWF PORTD
     bsf _led1digit                   
     call dly7seg
     bcf _led1digit
     
     movf _led2data,W
     call bin2seg
     movwf PORTD
     bsf _led2digit
     call dly7seg
     bcf _led2digit
     
     movf _led3data,W
     call bin2seg
     movwf PORTD
     bsf _led3digit
     call dly7seg
     bcf _led3digit
    so some ideas i was wrestling with just got answered?..

    1)thinking should look digits up in the main loop? and use the already "lookedup" variables in the interupt routine.

    2)now the one digit per interrupt, I had thought about, but couldn't figure out how to do. (put on back burner, until I saw this)
    little trickier.. without a gosub?

    would something like this work? (seems long way no?)

    Code:
    if digitloop=3 then digitloop=0 'only three digits
    digitloop=digitloop+1             'next digit
    
    if digitloop=1 goto digit1        'which digit we displaying?
    endif
    if digitloop=2 goto digit2
    endif
    
    
    digit3:                                'wasn't 1 or 2 so must be 3!
    PORTC = SEGDEF3                'output "prelookedup" data
    PORTE = 3                          'turn digit on
    goto dispdone                     'goto finish 
    
    digit2:                                'doing digit 2
    PORTC = SEGDEF2                'output "prelookedup" data
    PORTE = 5                          'turn digit on
    goto dispdone                     'goto finish 
    
    digit1:                                'doing digit1
    PORTC = SEGDEF1                'output "prelookedup" data
    PORTE = 6                          'turn digit on
    goto dispdone                     'goto finish 
    
    
    DISPDONE:                             'reload timer
      T1CON.0 = 0     ; stop timer
      TMR1H = %11111100
      TMR1L = %00011111
      T1CON.0 = 1     ; restart timer
    @ INT_RETURN                         'exit int routine
    on the right track?
    should the timer be stopped at the beginning of the routine?

    now in the main, will we need 3 lookup tables? can lookup into an array? or how about...

    Code:
    n=1                        'to be replaced with digit1 variable (N=N1) 
    gosub bin2seg
    segdef1=segdef
    n=2                        'digit2
    gosub bin2seg
    segdef2=segdef
    n=3                       'digit3
    gosub bin2seg
    segdef3=segdef
    
    BIN2SEG:
    LookUp n,[132,175,193,137,170,152,144,143,128,136,210,251],SEGDEF
    return
    (I was attempting mine in assembly, but so as not to hijack the thread, did this way)

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    You guys always make me hungry. I LOVE spaghetti.
    Just not in my code.

    Code:
    Main:
      FOR Value = 0 TO 999
        GOSUB SetDisp
        PAUSE 500
      NEXT Value
    GOTO Main
    
    '---[Set 7-seg patterns to WORD value]--------------------------------------
    SetDisp:
      FOR Idx = 2 to 0 STEP -1
        Temp = Value DIG Idx
        LookUp Temp,[132,175,193,137,170,152,144,143,128,136,210,251],Temp
        SEGDEF(Idx) = Temp
      NEXT Idx
    RETURN
    
    '---[TMR1 - interrupt handler]----------------------------------------------
    DISP:
      T1CON.0 = 0                  ; stop timer
      TMR1H = %11111100
      TMR1L = %00011111
      T1CON.0 = 1                  ; restart timer
    
      PORTE = %111                 ; turn off all digits to prevent ghosting
      PORTC = SEGDEF(digitloop)    ; put segment pattern to pin
      PORTE = ~(DCD digitloop)     ; turn on the digit
    
      digitloop = digitloop + 1    ; prepare for next digit
      IF digitloop = 3 then digitloop = 0
    @ INT_RETURN
    Completely untested ...
    Attached Files Attached Files
    DT

  5. #5


    Did you find this post helpful? Yes | No

    Default

    WOW... how simple to put the digitloop at the end, MUCH cleaner. less if'ing
    was looking at it backwards lol , maybe I should try standing on my head..

    and I started to do a loop (for) deal, but cant use val(x) in the lookup, and went all off the other way. lol.. shoulda figured out/stuck with the original idea.


    THANKS! looks shweet cant wait to test

    Think you solved both our problems!

  6. #6
    Join Date
    Oct 2004
    Posts
    448


    Did you find this post helpful? Yes | No

    Default Worked! now, another (sub)problem

    Wow, worked the first time, Darrel.

    Now, if I want to bit bang (I've already commited the hardware UART to something else) a couple of parameter values over the serial port, where in the code you've shown would the line go?

    I've been struggling with this, with no success; or is this normal when one is using TMR0?

    Regards,

    Anand

  7. #7
    Join Date
    May 2013
    Location
    australia
    Posts
    2,631


    Did you find this post helpful? Yes | No

    Default Re: Darrel's interrupts in a 7 segment display

    most obvious reason would be to make the easiest possible (construction wise ) homebrew pcb layout . ie reduce the need for a ds board or even just minimise via's

  8. #8
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: Darrel's interrupts in a 7 segment display

    Quote Originally Posted by richard View Post
    most obvious reason would be to make the easiest possible (construction wise ) homebrew pcb layout . ie reduce the need for a ds board or even just minimise via's
    Yes it just has me wondering as I can not see any obvious benefit. As I will never use these I am going to stop worrying about it.

  9. #9
    Join Date
    Feb 2008
    Location
    Michigan, USA
    Posts
    231


    Did you find this post helpful? Yes | No

    Default Re: Darrel's interrupts in a 7 segment display

    intriguing discussion, but you're right... a rabbit trail. Mine works, I'm moving on.
    Mark

Similar Threads

  1. 7 Segment Displays and MAX7219
    By Bill Legge in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 31st October 2010, 18:30
  2. LED Machine Tach For Tired Eyes
    By Archangel in forum mel PIC BASIC Pro
    Replies: 33
    Last Post: - 27th January 2010, 14:55
  3. Weird compile issue 7 segment LED display
    By George in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 21st June 2006, 02:12
  4. 7 segment digit problem (using Mister E's code)
    By jmgelba in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 9th September 2005, 20:25
  5. WRITE not working
    By servo260 in forum mel PIC BASIC Pro
    Replies: 31
    Last Post: - 29th December 2004, 02:02

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts