Instant Interrupts - Revisited - Page 9


Closed Thread
Page 9 of 20 FirstFirst ... 567891011121319 ... LastLast
Results 321 to 360 of 773
  1. #321
    Join Date
    Jun 2008
    Posts
    84


    Did you find this post helpful? Yes | No

    Default

    Well,
    First I was asking if someone has problems with INT when using the BPI-216 LCD.
    Anyway,
    When using this code on my 16F887, The LCD gets freaked.
    I will just display junk. I tried to eliminate some of the timers, and as said before, When having only INT for button or for clock it reduce the junk.

    Other code which implemets clock without INT but just timer, (http://www.picbasic.co.uk/forum/showthread.php?t=2129) works perfect with this LCD.
    Here is the code that makes it go crazy:
    Code:
    LED1   VAR  PORTD.0
    LED2   VAR  PORTD.1
    
    INCLUDE "DT_INTS-14.bas"     ' Base Interrupt System
    INCLUDE "ReEnterPBP.bas"     ' Include if using PBP interrupts
    INCLUDE "Elapsed_INT.bas"    ' Elapsed Timer Routines
    
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler    INT_INT,  _ToggleLED1,   PBP,  yes
            INT_Handler   TMR0_INT,  _ToggleLED2,   PBP,  yes
            INT_Handler   TMR1_INT,  _ClockCount,   PBP,  yes
        endm
        INT_CREATE               ; Creates the interrupt processor
    ENDASM
    
    OPTION_REG = OPTION_REG & $80 | 1  ; Set TMR0 Prescaler to 256, leave RBPU alone
    @    INT_ENABLE   INT_INT     ; enable external (INT) interrupts
    @    INT_ENABLE  TMR0_INT     ; enable Timer 0 interrupts
    @    INT_ENABLE  TMR1_INT     ; Enable Timer 1 Interrupts  
    
    GOSUB ResetTime              ' Reset Time to  0d-00:00:00.00
    GOSUB StartTimer             ' Start the Elapsed Timer
    
    Main:
      IF SecondsChanged = 1 THEN  
         SecondsChanged = 0
            IF Hours>9 THEN
              SEROUT PORTB.1,6,[254,128,#Hours,58]
              pause 300
                ELSE
                  SEROUT PORTB.1,6,[254,128,48,#Hours,58]
                  pause 30
            ENDIF
            IF Minutes>9 THEN
              SEROUT PORTB.1,6,[254,131,#Minutes,58]
              pause 300
                ELSE
                  SEROUT PORTB.1,6,[254,131,48,#Minutes,58]
                  pause 300
            ENDIF
            IF Seconds>9 THEN
              SEROUT PORTB.1,6,[254,134,#Seconds]
              pause 300
                ELSE
                  SEROUT PORTB.1,6,[254,134,48,#Seconds]
                  pause 300
            ENDIF
    GOTO Main
    
    '---[INT - interrupt handler]---------------------------------------------------
    ToggleLED1:
         TOGGLE LED1
    @ INT_RETURN
    
    '---[TMR0 - interrupt handler]-------------------------------(Blinky Light)------
    T0Count  VAR WORD
    ToggleLED2:
        T0Count = T0Count + 1
        IF T0Count = 512 THEN T0Count = 0 : TOGGLE LED2
    @ INT_RETURN

  2. #322
    Join Date
    Jun 2008
    Posts
    84


    Did you find this post helpful? Yes | No

    Default

    btw,
    If I disable INT (INTCON=0) the LCD shows correctly, but of ocurse interrupts are not working.

  3. #323
    Join Date
    Dec 2003
    Location
    Storrs, Ct.
    Posts
    91


    Did you find this post helpful? Yes | No

    Default

    What I do is turn off interrupts before serial and back on after serial completes. Like this:
    Code:
    sendudp:
            INTCON.7 = 0
            SerOut2 PORTC.6, 84, [$50] 'ask siteplayer to send udp
            INTCON.7 = 1
            udpcount = 0 
            gosub delay
            return
    Somewhere in here there is a list of the commands affected by Instant interrupts. I just turn the interrupts off, execute the command and turn the interrupts back on.
    I'm not sure if this is the best way to handle things but it's worked well for me so far.
    Hope this helps.
    "It will never happen here!" just happened here.
    My thoughts and prayers for Sandy Hook victims and families.

  4. #324
    Join Date
    Jun 2008
    Posts
    84


    Did you find this post helpful? Yes | No

    Default

    Well,
    What if the interrupts are for the clock ?
    Disabling it will cause the clock not to keep going.

  5. #325
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by menta View Post
    Well,
    What if the interrupts are for the clock ?
    Disabling it will cause the clock not to keep going.
    Then add an RTC chip.

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


    Did you find this post helpful? Yes | No

    Default

    Hi menta,

    Any type of software timed commands like SERIN/OUT, OWIN/OUT, PAUSE, PULSIN/OUT etc, will be disturbed by these types of Interrupts.

    That's why there's an ON INTERRUPT GOTO statement. It reverses the situation, so that the PAUSE, SERIN/OUT etc trash the Interrupts instead, which seems more tolerable to people new to PBP, but just drove me crazy. And is why I ended up with DT_INTS.

    With Interrupts, you need to use HARDWARE solutions instead of the SOFTWARE timed commands, and in your case the 16F887 has a USART on-board that is NOT affected by interrupts.

    So just switch over to HSEROUT, and your problems will vanish.

    DT

  7. #327
    Join Date
    Jun 2008
    Posts
    84


    Did you find this post helpful? Yes | No

    Default

    Great, will try this.

  8. #328
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Hi DT,

    This question is not related to the current ongoing subject but is about your int routine.

    Is it safe (or how safe) to call a subroutine inside your interrupt handler?

    Or inside PBP int handler?


    Thanks.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  9. #329
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,795


    Did you find this post helpful? Yes | No

    Default

    I am not DT, but for sure it is not recommended in any way to do a call inside the int routine. Think of the delays to go forth and back plus whatever you are going to do inside the sub. Can you make it absolutely sure that the call will be a zap?

    I am sure there is another wayto implement your project.

    Ioannis

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


    Did you find this post helpful? Yes | No

    Default

    I agree with Ioannis.
    It's not really recommended, but it is possible.

    The worst case scenario is with a 16F PIC.
    They only have 8 stack levels, and some of PBP's commands can use 4 of them. Which is why you can only nest gosubs 4 levels deep in any 16F program.

    In your main program, it may already be 3-4 levels deep when an interrupt triggers. If you then ReEnter PBP, do a GOSUB and try to run a 4-level PBP command, the stack will definitely overflow.

    Using the Software Stack can eliminate that problem.

    With an 18F there are several more stack levels, so it's not as much of a problem. And of course, if you write the handlers and subroutines in ASM, it's even less of a problem.
    <br>
    DT

  11. #331
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Thanks IO.
    I already knew about delay issues but it takes approx. 30 seconds for my code to complete int routine. So my code is not time sensitive.

    What I needed to know was DT's warnings about deep levels.

    Thanks DT, that is what I now need to consider.

    ---------------------
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  12. #332
    Join Date
    Jun 2005
    Posts
    20


    Did you find this post helpful? Yes | No

    Default

    Hi--

    I'm having a problem with Instant Interrupts that I can't figure out... I'm using Darrell's Elapsed Timer with V3.2 of DT_INTS-18 and Reenter-PBP-18. The chip is an 18F4520 running at 16MHz. The interrupt-driven elapsed timer system works beautifully, but then I can no longer use the second PWM output, CCP2, which I have set up to output on portc.1. CCP1 works perfectly. This is true whether I use the HPWM command and PBP defines or set up the PWM registers directly as described in the data sheet.

    What happens is that portc.1 goes low and stays that way. If I disable the DT includes and the interrupt handler, the PWM CCP2 port functions normally. I have checked and double checked things like the portb/c multiplexing and the tris output settings, etc. What I think is happening is something in Darrrell's code is clearing CCP2CON, but I haven't been able to find it.

    Does anybody have any ideas to try?

    Thanks--

    --Alan

  13. #333
    Join Date
    Feb 2005
    Location
    Kolkata-India
    Posts
    563


    Did you find this post helpful? Yes | No

    Default Can we have the code please

    Hi,

    It is very unlikely that DT's int handler mess with your CCP2CON register. Do you have a LCD / Serial / Debug out then try dumping the CCP2COn values periodically to know whats going on.

    A look at the code may be helpful. I have 18F4520 ready with me and would like to duplicate the problem for my own interest.
    Regards

    Sougata

  14. #334
    Join Date
    Jun 2005
    Posts
    20


    Did you find this post helpful? Yes | No

    Default

    Hi sougata--

    The code is massive, with a dozen include files... it would be a real mess to upload it. PWM on channel 1 always works. I have discovered since I posted that message that if I start Timer1 (T1CON.0 = 1, the timer that is used by Darrell's Elapsed Timer code), then the PWM on channel 2 works. Stop timer 1, and channel 2 PWM stops working. But if I comment out all of Darrell's code and recompile, both PWM ports work perfectly.

    PWM only uses Timer 2, so I am baffled. I do have an LCD attached, I will try reading the CCP2CON register and see what its thinking.

    Thanks--

    --Alan

  15. #335
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    I think the default for channel 2 is Timer1 unless you use the DEFINE HPWM2_TIMER 2 option.
    Channel 1 defaults to Timer2 so you would still see this channel working when disabling Timer1.

    See if adding DEFINE HPWM2_TIMER 2 doesn't cure the problem.

    Edit: Scratch that one. This is apparantly only for 17C7xx device types.
    Last edited by Bruce; - 25th July 2008 at 20:20. Reason: Only for 17C7xx devices
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

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


    Did you find this post helpful? Yes | No

    Default

    Well, without the code, we're reduced to playing 20 questions.

    Please post at least the Interrupt Definitions, handlers (other than Elapsed), and ANY and ALL lines that modify the following registers.

    T1CON
    INTCON
    INTCON2
    INTCON3

    PIE1
    PIE2
    IPR1
    IPR2

    <br>
    DT

  17. #337
    Join Date
    Feb 2005
    Location
    Kolkata-India
    Posts
    563


    Did you find this post helpful? Yes | No

    Default T1CON wrong settings

    Hi,

    DT's Elapsed Timer takes care of setting T1CON right in the "StartTimer" . If by any means T1CON oscillator is turned on then PORTC.1 becomes an input regardless of the TRIS settings. Still it does not explain why and how the PWM starts when Timer1 is started.

    What happens when your PWM stops the pin in set low/high ?
    I hope you are quite aware that if duty cycle is higher than period then the pin never gets cleared.

    Mr.E where is your crystal ball ??!!??
    Regards

    Sougata

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by sougata View Post
    If by any means T1CON oscillator is turned on then PORTC.1 becomes an input regardless of the TRIS settings.
    That's a good possibility.

    Still it does not explain why and how the PWM starts when Timer1 is started.
    So True!

    > Mr.E where is your crystal ball ??!!??
    Ummm, being that he hasn't logged in since 15th June 2008
    I'd say he's in Jail.

    Can't imagine mister-e not checking in, if he could.
    <br>
    Last edited by Darrel Taylor; - 26th July 2008 at 09:01. Reason: Mr-E
    DT

  19. #339
    Join Date
    Jun 2005
    Posts
    20


    Did you find this post helpful? Yes | No

    Default

    Hmmm... Sougata's point about starting timer1 sounds like it might be the culprit, at least as far as RC1 going to input. PWM2 drives a fan via a MOSFET, so if RC1 goes to input, the pullup I have on the MOSFET would drive the fan to full speed, which is exactly what's happening. I haven't yet found in the data sheet why turning timer1 on does that to RC1.

    I have attached the code relevant to Darrel's question. The INCLUDE files that aren't attached don't modify the registers Darrel was talking about. I have very little experience with using the timers or using interrupts-- is it possible to just modify the Elapsed Timer routine to use timer 0 or timer3?

    Thanks--

    --Alan
    Attached Files Attached Files
    Last edited by alanmcf; - 29th July 2008 at 00:56.

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by alanmcf View Post
    Hmmm... Sougata's point about starting timer1 sounds like it might be the culprit,
    It is!

    The line T1CON = %00001101 '<-- settings for 16 MHz turns on the Timer1 Oscillator, which disables RC1's digital I/O functions.

    Since you are using the Elapsed Timer, there's no need to set T1CON. The Include file does that for you.
    <br>
    DT

  21. #341
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,795


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    Can't imagine mister-e not checking in, if he could.
    <br>
    In fact, I had some tel. discussion 1 and 1/2 month ago with Steve, but when I tried to find him again, he disappeared. No telephones (only tel. answering machine) no e-mails. If anyone knows about Steve please inform. He had some misfortunes in the past as we can recall, just hope all is OK now, lying in some beach.

    Ioannis

  22. #342
    Join Date
    Jun 2005
    Posts
    20


    Did you find this post helpful? Yes | No

    Default

    Hi Darrel--

    Are you saying that your elapsed timer routine uses Timer1 without actually turning it on, thereby avoiding the portc.1 problem? I will try this immediately!

    Thanks--

    --Alan

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


    Did you find this post helpful? Yes | No

    Default

    Yes, It uses Timer1. But it doesn't turn on the External Oscillator.

    Timer1 has a feature that lets you hook up a 32768hz crystal on the T1OSO(RC0) and T1OSI(RC1) pins. This oscillator will continue running in sleep mode, so it can be used to keep time like a clock.

    But the way you are using the Timer, it's using the signal from the main System Oscillator, so there's no need to turn the ext. osc on.

    For the Elapsed timer, you can use the StartTimer and StopTimer subroutines.

    hth,
    DT

  24. #344
    Join Date
    Feb 2005
    Location
    Kolkata-India
    Posts
    563


    Did you find this post helpful? Yes | No

    Default About Steve

    Skimask pointed this out

    http://www.picbasic.co.uk/forum/show...0058#post60058


    BTW I would encourage everybody to have a look at DT's codes and try to figure out the amount of hard work and pure AI (I beleive he is an android built by microchip using surplus production ) he has put in.

    Meant to make our life easy and enlighten us, the mere mortals on PIC and PBP.
    Last edited by sougata; - 29th July 2008 at 20:28. Reason: Forgot to thank DT once again for his great contribution
    Regards

    Sougata

  25. #345
    Join Date
    Jun 2005
    Posts
    20


    Did you find this post helpful? Yes | No

    Default

    Sougata is right, and yes, Darrel, I am not worthy. Arthur C. Clarke said that any sufficiently advanced technology would be indistinguishable from magic; Instant Interrupts is magic, and Darrel is the resident magician.

    Thanks so much for creating it!

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


    Did you find this post helpful? Yes | No

    Default

    And Helen Keller said ...

    "Life is a succession of lessons which must be lived to be understood."

    Until you've had the problem, you won't know about them.

    Keep having problems.
    DT

  27. #347
    Join Date
    Jun 2008
    Posts
    3


    Did you find this post helpful? Yes | No

    Default Temp variables exceeding T7

    Hi Darrel, sorry my english.

    I need help for this message:

    Message[301] c:\..........asm 3074:MESSAGETemp variables exceeding T7)

    Tks.

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


    Did you find this post helpful? Yes | No

    Default

    When you have Complex formulas, or very Long IF/THEN comparisons, the PBP compiler generates additional (T)emporary System variables to keep track of the intermediate results.

    If those formulas are in the Interrupt Handler, it can cause big problems. But, if they are ONLY in the main program, they will NOT be a problem.

    There's no way for DT_INTS to know if they are in the Handler or the Main program, so it gives a Warning (message) to let you know to look and verify that they are NOT in the handlers.

    After you have VERIFIED that the formulas are NOT in the handlers. You can add this define to stop the Warning.
    Code:
    DEFINE  NO_T7_WARNING 1
    hth,
    DT

  29. #349
    Join Date
    Aug 2008
    Posts
    3


    Did you find this post helpful? Yes | No

    Exclamation DT_INTS breaks pulsein/count PBP routines?

    Is this true? I can believe it to be. If so, is there any way I can replace this functionality using the interrupt driven counters or something? A hardware counter is not an option unfortunately, as the board is already in units in the field.

    The reason I need to add interrupts is because I need to add background hardware UART character reception using UART2 because the program spends too much time doing other things in the foreground to service the port soon enough.

    Is there a list of what PBP functions are affected by DT_INTS? If so where can I find it?

    Does anyone have examples of interrupt driven serial IO using DT_INTS? How about pulse counting routines?

    Thanks,
    Mike

  30. #350
    Join Date
    Mar 2006
    Location
    Pennsylvania, USA.
    Posts
    130


    Did you find this post helpful? Yes | No

    Default

    Hi Mike,
    Here is my serial interrupt handler using Darrel's Instant Interrupts;

    SerialInt:
    Hserin [STR buffer\45\$8e] 'read up to 45 bytes into array, end if value is hex 8e.
    @ Int_Return

    That's all there is to it. If you do a search for frequency measurement, you will find some code that Bruce put together using Instant Interrupts to measure pulse width, and I think you could make it work for you.

    Good Luck,

    Jerry
    If your oscilloscope costs more than your car...

  31. #351
    Join Date
    Aug 2008
    Posts
    3


    Did you find this post helpful? Yes | No

    Default

    Thanks for the code snippet! It looks easier then I thought it would be to implement the serial stuff. I was worried I would have to code something in ASM and use buffers etc...

    As for the frequency measurement stuff, I did a search and I can't seem to find what your referring to. Do you happen to have a link handy? Is it on this board, or somewhere else?

    Thanks,
    Mike

  32. #352
    Join Date
    Dec 2007
    Posts
    4


    Did you find this post helpful? Yes | No

    Thumbs up 7 seg display with rs232 data input

    I was testing with darrel Taylor Instant interrups. The colaboration is fantastic. Great.

    I mount four 7 seg, 4 inches each, with common anode, and the 16f877A. The input for data is the serial input, across portc.7. I probe fist without darrel tool, using on interrupts and I see that the serial input line stop de scan for the 7 segs, because the multiplexing loss the times in this waiting for the data. Each display is activate with portd.4 to portd.7

    The circuit work fine, so, the program need tuning up.

    When I used the Darrel tool, the time for the 7 segs scan don't change with the data wait in the serian in line, including this part in the main loop. The scan for the multiplexing is in instant interrup routine. My dude, in this case, is with time multiplexing scan. I not Know what is the lines for the scan, and in this moment, i only see the scan very slow.

    I need help for to put the timer a time for correct and fast scan.

    Thanks.

    Luis Elizarraraz

  33. #353
    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

  34. #354
    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

  35. #355
    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

  36. #356
    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

  37. #357
    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 03:01. Reason: Modified to turn off timer before loading, and add
    DT

  38. #358
    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.

  39. #359
    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

  40. #360
    Join Date
    Sep 2006
    Location
    Australia
    Posts
    5


    Did you find this post helpful? Yes | No

    Thumbs up Instant Interrupt

    Quote Originally Posted by Darrel Taylor View Post
    <table><tr><td></td><td>
    At long last.

    The Instant Interrupt system for 18F PIC's is now available.

    It's become increasingly harder to keep things up to date here on the forum, so I've moved everything over to my website.
    I'm still working on some of the pages, but everything you need is already there. It seems to take longer to make the web pages, than it does to write the program.

    http://darreltaylor.com/DT_INTS-18/home.html</td></tr></table>

    <br>
    Thank you very much Darrel. Your excellent works have saved me lots of headache.

Similar Threads

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

Members who have read this thread : 9

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