Instant Interrupts - Revisited


Closed Thread
Results 1 to 40 of 773

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default

    If you are using an interrupt handler to receive the serial data, then nothing else can happen until the handler is finished.

    If other things must continue operating at the same time, you either have to read the serial data 1 byte per interrupt, or have the HSERIN statement in the main loop so that it can be interrupted like everthing else.

    Sitting in the handler WAITing for the data, will not work.
    <br>
    DT

  2. #2
    Join Date
    Dec 2007
    Posts
    4


    Did you find this post helpful? Yes | No

    Thumbs down Slow scan for 7 seg multiplexing

    Thanks for answer me Darrel.

    The code for my application is the follow:


    '-------------------------------------------------------------------------------------
    '
    'Start

    INCLUDE "MODEDEFS.BAS"

    define loader_used 1
    DEFINE OSC 20 ' Define crystal as 4Mhz

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

    ' ** Declare the Variables **
    LEDS Var Byte ' The amount of LEDs in the display
    O_C Var Byte ' Used by the interrupt for time sharing
    Counter Var byte ' General purpose counter
    Del Var Word ' General purpose delay loop variable
    del1 var word
    D_Number Var word ' The number to display on the LEDS
    DP Var Byte ' Position of the decimal point
    Disp_Patt Var Byte ' Pattern to output to PortC
    Num Var Byte[4] ' Array to hold each digits value
    Digit1 var Portd.4 ' 1ro
    Digit0 Var Portd.5 ' 2do
    Digit3 Var Portd.6 ' 3ro
    Digit2 Var Portd.7 ' 4to

    ' ** THE MAIN PROGRAM STARTS HERE **

    trisd=%00001111 'portd.4 a portd.7 like output
    TrisB=0 ' Make PortB and PortC outputs
    PortC=0:PortB=0 ' Clear PortB and PortC
    O_C=0 ' Clear the time share variable

    TRISB=0

    x var byte
    y var byte
    duty var byte
    canal var byte
    d var word

    v1 VAR word
    V2 VAR word
    ciclo var word
    indi var bit
    conta var byte

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

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


    d=0
    ciclo=0
    indi=0

    high portd.7
    high portd.6
    high portd.5
    high portd.4



    Main:
    serout2 portc.6,84,[13,"C>"]
    serin2 portc.7,84,3000,main,[dec4 D_Number]
    serout2 portc.6,84,["L"]
    Gosub Display ' Display the value
    goto main

    Display:
    For LEDS=3 to 0 step -1 ' Loop for 4 digits (0-65535) ' Disable the interrupt while we calculate
    Num[LEDS]=D_Number dig LEDS ' Extract the seperate digits into the array
    If D_Number<10 and LEDS=1 then Num[LEDS]=10 ' Zero Suppression for the second digit
    If D_Number<100 and LEDS=2 then Num[LEDS]=10 ' Zero Suppression for the Third digit
    If D_Number<1000 and LEDS=3 then Num[LEDS]=10 ' Zero Suppression for the Third digit ' Re-enable the interrupt
    Next
    return
    ' INTERRUPT HANDLER
    ' Multiplexes the 3-digits
    '
    Disable ' Disable all interupts during the interrupt handler

    Multi:
    'sigue: ' 0 1 2 3 4 5 6 7 8 9 A B C E F G H I J L N 0 U b c d e f g h i n p q s o u
    lookup Num[O_C],[63,6,91,79,102,109,125,39,127,111,119,127,57,121,1 13,125,118,6,30,56,55,63,62,124,88,94,123,113,111, 116,4,84,115,103,109,92,28],Disp_Patt
    ' Lookup Num[O_C],[192,249,164,176,153,146,130,248,128,144,255],Disp_Patt ' Decode the segments for the LED
    ' Process the first display (farthest right)
    If O_C=0 then ' If it is our turn then
    Digit3=1 ' Turn OFF the 3er LED
    PortB=Disp_Patt ' Place the digit pattern on portC
    If DP=1 then PortB.7=0 ' Check the value of DP and Turn ON the decimal point
    Digit0=0 ' Turn ON the first LED
    Endif
    ' Process the second display
    If O_C=1 then ' If it is our turn then
    Digit0=1 ' Turn OFF the first LED
    PortB=Disp_Patt ' Place the digit pattern on portC
    If DP=2 then PortB.7=0 ' Check the value of DP and Turn ON the decimal point
    Digit1=0 ' Turn ON the second LED
    Endif
    ' Process the third display
    If O_C=2 then ' If it is our turn then
    Digit1=1 ' Turn OFF the second LED
    PortB=Disp_Patt ' Place the digit pattern on portC
    If DP=3 then PortB.7=0 ' Check the value of DP and Turn ON the decimal point
    Digit2=0 ' Turn ON the third LED
    Endif

    ' Process the 4th display
    If O_C=3 then ' If it is our turn then
    Digit2=1 ' Turn OFF the second LED
    PortB=Disp_Patt ' Place the digit pattern on portC
    If DP=4 then PortB.7=0 ' Check the value of DP and Turn ON the decimal point
    Digit3=0 ' Turn ON the third LED
    Endif

    O_C=O_C+1 ' Increment the time share counter
    If O_C>=4 then O_C=0 ' If it reaches 3 or over then clear it

    @ INT_RETURN ' Allow more interrupts

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


    Did you find this post helpful? Yes | No

    Default

    Yup, that's pretty slow.

    At 20mhz with 1:1 prescaler, you'll get an interrupt every 13.1ms.
    That's 52.4ms for all 4 digits, which is a 20hz refresh rate. Way too slow.

    If you want to make it go faster, you have to load something in the Timer. As it is, it's just free-running.

    Also, you'll never get those SERIN/OUT2's to work. They are timed by software, which gets continuously interrupted. You need to use the USART with HSERIN/OUT.

    And, ENABLE/DISABLE are for ON INTERRUPT. They have no effect with Instant Interrupts.
    <br>
    DT

  4. #4
    Join Date
    Dec 2007
    Posts
    4


    Did you find this post helpful? Yes | No

    Thumbs up what's the way for more speed?

    Darrel, thanks. before your instant interrups tools never I was experimenting interrupts.

    I have clear idea the hserin/hserout sustitution, but I ignored what's the procedure (concretly) for incress the speed.

    I havew the display working now, but I need to find de solution for the slow scan.

    The question is How incress the speed with the preescaler 1:1 now?

    what's the value for load?

    Thanks and regards

    Luis Elizarraraz

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by itelmex View Post
    The question is How incress the speed with the preescaler 1:1 now?

    what's the value for load?
    You should have at least 100hz refresh rate, or 400hz interrupts (4 digits).

    Code:
    DEFINE  Freq 400
    DEFINE  Prescaler 1
    Timer1  VAR WORD EXT
    TmrLoad CON EXT
    @Timer1 = TMR1L
    @TmrLoad = 65536 - (OSC*1000000/4/Prescaler/Freq)
    Then, first thing in the handler...
    Code:
    T1CON.0 = 0
    Timer1 = Timer1 + TmrLoad
    T1CON.0 = 1
    Last edited by Darrel Taylor; - 3rd September 2008 at 02:01. Reason: Modified to turn off timer before loading, and add
    DT

  6. #6
    Join Date
    Dec 2007
    Posts
    4


    Did you find this post helpful? Yes | No

    Thumbs up Display four 7 sgments with rs232 input

    Darrel:

    Thanks for the solution!

    For finish this project, I'm going to show the final version for the code.

    Recapitulation:

    Hardware:

    Four 7 segments modules conected to the portb, like driver using uln2803.

    Each module is conected to the anode with 2 transistors: bc337 directed to portd (portd.4 to portd.7 for each module) and from the bc337 colector to the irf640 gate.

    For the communication, max232 connected to the pc (data inputs) and the ttl side, to the portc.6 and portc.7 (tx and rx).

    I send to the pc the characters "C>" like invitation for to introduce the data.

    The data follow the format: "CXXXX" where XXXX is any number from 0000 to 9999.
    When the circuit receive the data in the correct format, this send to the pc the character "L" (Listen).

    The problems with the slow scan was solutioned with the Darrel Taylor instant interrups tools. I finded relative easy the first project using interrups..!Thanks and more thanks Darrel ¡

    Finally, the code:


    '-----------------------------------program picbasic pro /Darrel support-------------------
    '
    INCLUDE "MODEDEFS.BAS"

    define loader_used 1
    DEFINE OSC 20

    DEFINE HSER_RCSTA 90h
    DEFINE HSER_TXSTA 20h
    DEFINE HSER_BAUD 9600
    'DEFINE HSER_SPBRG 25

    DEFINE Freq 400
    DEFINE Prescaler 1
    Timer1 VAR WORD EXT
    TmrLoad CON EXT
    @Timer1 = TMR1L
    @TmrLoad = 65536 - (OSC*1000000/4/Prescaler/Freq)


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


    ' ** Declare the Variables **
    LEDS Var Byte ' The amount of LEDs in the display
    O_C Var Byte ' Used by the interrupt for time sharing
    Counter Var byte ' General purpose counter
    Del Var Word ' General purpose delay loop variable
    del1 var word
    D_Number Var word ' The number to display on the LEDS
    DP Var Byte ' Position of the decimal point
    Disp_Patt Var Byte ' Pattern to output to PortC
    Num Var Byte[4] ' Array to hold each digits value

    TRISD=%00001111 'portd.4 a portd.7 como salidas
    TrisB=0 ' Make PortB and PortC outputs
    PortC=0:PortB=0 ' Clear PortB and PortC
    O_C=0 ' Clear the time share variable

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

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

    PORTD=%11110000

    Main:
    hserout [13,"C>"]
    hserin [dec4 D_Number]
    SIGUE:
    hserout ["L"]
    Gosub Display ' Display the value
    goto main

    Display:
    For LEDS=3 to 0 step -1 ' Loop for 4 digits (0-65535) ' Disable the interrupt while we calculate
    Num[LEDS]=D_Number dig LEDS ' Extract the seperate digits into the array
    If D_Number<10 and LEDS=1 then Num[LEDS]=10 ' Zero Suppression for the second digit
    If D_Number<100 and LEDS=2 then Num[LEDS]=10 ' Zero Suppression for the Third digit
    If D_Number<1000 and LEDS=3 then Num[LEDS]=10 ' Zero Suppression for the Third digit ' Re-enable the interrupt
    Next
    return
    ' INTERRUPT HANDLER
    ' Multiplexes the 4-digits
    '
    Multi:
    T1CON.0 = 0
    Timer1 = Timer1 + TmrLoad
    T1CON.0 = 1

    'sigue: ' 0 1 2 3 4 5 6 7 8 9 A B C E F G H I J L N 0 U b c d e f g h i n p q s o u Z
    lookup Num[O_C],[63,6,91,79,102,109,125,39,127,111,119,127,57,121,1 13,125,118,6,30,56,55,63,62,124,88,94,123,113,111, 116,4,84,115,103,109,92,28,255],Disp_Patt
    ' Lookup Num[O_C],[192,249,164,176,153,146,130,248,128,144,255],Disp_Patt ' Decode the segments for the LED
    ' Process the first display (farthest right)
    If O_C=0 then portd=%11011111
    If O_C=1 then portd=%11101111
    If O_C=2 then portd=%01111111
    If O_C=3 then portd=%10111111
    PortB=Disp_Patt ' Place the digit pattern on portC
    O_C=O_C+1 ' Increment the time share counter
    If O_C>=4 then O_C=0 ' If it reaches 3 or over then clear it
    @ INT_RETURN ' Allow more interrupts
    '-----------------------end --------------------------------------------------------

    The display is working very good.

    Regards.

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


    Did you find this post helpful? Yes | No

    Wink

    That looks much better.

    It's nice to have someone that can take a little guidance, and make it work.

    Thanks for the Code Example!
    DT

Similar Threads

  1. Clock using Instant Interrupts
    By PICpocket in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 16th February 2009, 21:43
  2. DT instant interrupts with mister_e keypad
    By Tomexx in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 26th November 2008, 20:02
  3. DT's Instant Interrupts trouble
    By Tomexx in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 24th November 2008, 20:48
  4. Keypad and DT's Instant Interrupts
    By Homerclese in forum General
    Replies: 11
    Last Post: - 27th April 2007, 06:32
  5. Replies: 1
    Last Post: - 1st November 2006, 03:11

Members who have read this thread : 8

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

Tags for this Thread

Posting Permissions

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