Instant Interrupts - Revisited


Closed Thread
Page 1 of 2 12 LastLast
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

    But I'm afraid there's not much I can add;
    Well, I'm no philosophy major, but I figure...

    The Day you decide you Can't, is also the Day you won't.

    Give it a try.
    Added: or should I say more tries (examples). (SED1335 320x240 graphic LCD)

    DT

    Oh, and, You're Welcome, You're Welcome, You're Welcome,
    You're Welcome, You're Welcome, You're Welcome.
    Last edited by Darrel Taylor; - 17th July 2006 at 01:57. Reason: ADDED

  2. #2
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    Darrel,

    I'm trying to work your Instant Interrupts in to my regular code.

    When compiling, I get the following error messages:

    WARNING:Unable to fit variable RetAddrH in requested bank 16
    WARNING:Unable to fit variable RetAddrL in requested bank 16
    WARNING:Unable to fit variable INT_Flags in requested bank 16
    WARNING:Unable to fit variable HP_Vars in requested bank 0


    Since these are just warnings, do I need to be concerned?
    Is there a solution?
    Charles Linquist

  3. #3
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,170


    Did you find this post helpful? Yes | No

    Default

    I'm the proud owner of an interupt routine in a PIC 16F628, my very first. It handles USART RX from a PIC 18F4550 wonderfully.

    As mentionned on Darrel's information, I had to switch from MP to MPASM and encountered some delays in setting up the _CONFIG switches properly. But once I got that cleaned up I was up and running, this is just awesome!

    (Charles, any chance you are using MP?)

    Robert
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  4. #4
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    No chance.
    Charles Linquist

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


    Did you find this post helpful? Yes | No

    Default

    Do you have anything else designated as BANKA.

    PBP uses some of it, and there's only 128 bytes.

    Arrays, eat it up fast too.

    ??
    <br>
    DT

  6. #6
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,170


    Did you find this post helpful? Yes | No

    Default

    I have a habit of placing INCLUDES at the top of a program. I would assume Darrel's routine would allocate whatever it wants in whatever bank first, then my program would take up what is left.

    If I run out of space I know I have to trim excess fat from my code, or upgrade the mcu.

    Robert
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

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


    Did you find this post helpful? Yes | No

    Default

    And a good habit it is.

    I also tend to put initialization code in the Include files that need to run before the main program starts. So the top is the best, and don't jump over them.

    DT

  8. #8
    Join Date
    Oct 2003
    Location
    Australia
    Posts
    257


    Did you find this post helpful? Yes | No

    Unhappy

    Hi Darrel,

    This is pretty neat code Pretty amazing really. Hahaha

    Anyway, I have a problem with my PIC hanging up because of an Idle State logic level error see <a href="http://www.picbasic.co.uk/forum/showthread.php?t=4301"> Here</a> on a serial input pin.

    I dont want to over complicate the circuit with extra hardware to get around this so I thought that I could use you interrupts to to side step this problem and do it all in software.

    Unfortunately the TMR1 interrupt stops working as well while waiting for serial data eg

    HSERIN [WAIT ("SOME DATA")]

    I was hoping that these interrupts routines were bullet proof regardless of what the program was doing.

    Any ideas?

    Regards
    Squib

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


    Did you find this post helpful? Yes | No

    Default

    Squib,

    TMR1 interrupts will not stop when using HSERIN. Unless the HSERIN is also in an interrupt handler.

    As for the Hanging, the USART will give a Framing Error (RCSTA.2) if the RX pin is held low. Check for the error before trying to HSERIN.
    <br>
    DT

  10. #10
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,170


    Did you find this post helpful? Yes | No

    Default

    Darrel,

    Any obvious reason why this program takes over 10 seconds to start up on a PIC 18F4550?

    If I comment out the Interrupt settings at the top (includes and asm) and the ReceiveUSART handler further below, it takes less than 2 seconds.

    Robert
    Attached Files Attached Files
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

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


    Did you find this post helpful? Yes | No

    Default

    Not sure about this, but gotta start somewhere.

    The RX_INT is being ENABLEd before the USART registers are set-up. Or, more accurately, since HSERIN/OUT are used in the program, PBP initializes the USART first, then RX_INT is enabled, then the USART registers are changed.

    It may be causing a false interrupt that sends it to the ReceiveUSART: handler, which is expecting to see 2 bytes being received, that were never sent. So it sits there.

    Try using this...
    Code:
    DEFINE HSER_CLROERR 1  ' Hser clear overflow automatically 
    DEFINE HSER_RCSTA 90h  ' Hser receive status init 
    DEFINE HSER_TXSTA 24h  ' Hser transmit status init 
    DEFINE HSER_SPBRG 0    ' Hser spbrg init 
    
    While PIR1.5 = 1     ; clear the buffer
        HSERIN [varByte]
    Wend
    
    @ INT_ENABLE  RX_INT     ; enable RX interrupts
    In place of..
    Code:
    @ INT_ENABLE  RX_INT     ; enable RX interrupts
    
    
    DEFINE  HSER_SPBRG  0               ' 1250 KBAUD @ 20 MHz (CPU)
    
            BAUDCON.3 = 0               ' BRG16 Select 8 bit baud rate generator
    
            TXSTA.5 = 1                 ' TXEN  Enable USART transmitter
            TXSTA.4 = 0                 ' SYNC  Asynchronous communication
            TXSTA.2 = 1                 ' BRGH  High speed baud rate
    
            RCSTA.7 = 1                 ' SPEN  Enable USART receiver
            RCSTA.4 = 1                 ' CREN  Enable continuous receive
    DT

  12. #12
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,170


    Did you find this post helpful? Yes | No

    Default

    Nope, wasn't it. But as I was putzing around trying other stuff I noticed a few attempts were within 2 seconds, but for no apparent reason. For some reason it appeared to be an unstable setup and I remembered that unset pins can do this. And that's when I remembered this from page 235 of the 18F4550:

    -----------------------------------------------------------------------
    The pins of the Enhanced USART are multiplexed with
    PORTC. In order to configure RC6/TX/CK and
    RC7/RX/DT/SDO as a USART:
    • bit SPEN (RCSTA<7>) must be set (= 1)
    • bit TRISC<7> must be set (= 1)
    • bit TRISC<6> must be cleared (= 0) for
    Asynchronous and Synchronous Master modes
    or set (= 1) for Synchronous Slave mode
    -----------------------------------------------------------------------

    I had ignored this paragraph 'cause I had never seen a need for these resistors, I thought it was only for the Enhanced USART. So I added the 4K7 resistors on TX (pulldown) and RX (pullup) and everything works fine, even with my old code.

    Thanks D!

    Robert
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  13. #13
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,170


    Did you find this post helpful? Yes | No

    Default

    Well, I misunderstood what I was supposed to do but when I removed the resistors and put in the TRIS statements it took 9 seconds again. So I set the port pins to 0, same thing, I set them to 1, same thing.

    It works properly with just the 4K7 resistors.

    EDIT: I tried pulling both pins down and that works as well.

    Robert
    Last edited by Demon; - 23rd July 2006 at 16:34.
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  14. #14
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,170


    Did you find this post helpful? Yes | No

    Default

    This is great stuff Darrel. I've added interrupts for USART communication between a master and 2 slaves and it works like a charm.

    Now I need to service the USB line every "once in a while" and read a previous reply of yours:
    http://www.picbasic.co.uk/forum/show...9&postcount=33

    This stuff went WHOOOOSH right over my head, you lost me as soon as you started talking about hertzes. From your post I know I have to adjust the prescaler, as well as possibly manage a counter, but that's about it. I have no idea what values to use as a reasonable starting value (I figure some tweaking will be necessary).

    This is the base I have so far, including relevant oscillator information:

    Robert
    Attached Files Attached Files
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

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


    Did you find this post helpful? Yes | No

    Default

    "master and 2 slaves", mmm kinky!

    Well, I can answer part of it.

    Just change ...

    <pre>T1CON = $11 ; Prescaler = 2, TMR1ON</pre> @ 48mhz, that will give an interrupt every 10.9 ms. No need to reload the timers.

    According to the PBP manual, USBservice should be called every 10ms, but it doesn't have to be that precise.

    However,

    I have no idea what will happen when you interrupt another USB routine and try to do a USBservice.
    My guess is that it won't be pretty.

    More than likely, you will need to INT_DISABLE the TMR1_INT, before doing anything else with the USB, then INT_ENABLE it when it's done.
    <br>
    DT

  16. #16
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,170


    Did you find this post helpful? Yes | No

    Default

    Ok, I added the disable/enable at both assembler USB routines generated from HIDMaker but the device is not recognized. I rummaged through the datasheet for TMR1 and T1CON and found this:

    ================================
    When Timer1 is enabled, the RC1/T1OSI/UOE and
    RC0/T1OSO/T13CKI pins become inputs. This means
    the values of TRISC<1:0> are ignored and the pins are
    read as ‘0’.
    ================================

    Now that sucks, I'm using those pins as output to a LCD. I expected the LCD to spaz out but it's working fine.

    I had started with an 18F4550 QFP but had downgraded to a 18F2550 SOIC, easier to solder. I don't have any output pins to spare either, the only pin I'm not using is A3.

    I hate to have to yank all this off the breadboard to put back the 18F4550, again, but I might not have any choice.

    I think I'm going to comment out all unnecessary code (interrupts/HSERIN/HSEROUT) until I have a working USB program again (sprinkling USBSERVICE everywhere). Then I'll put the USB interrupt back in and go on from there.

    Robert
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  17. #17
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,170


    Did you find this post helpful? Yes | No

    Default

    D'oh! Enabling the USB interrupt before USBINIT was not one of my better ideas.

    Step 1: I commented out everything except the LCD and sprinkled USBSERVICE everywhere it is recognized.

    Step 2: I comment out all USBSERVICE and restored the TMR1 interrupt for USBSERVICE and it failed to be recognized (enabling it immediately after USBINIT).

    Robert
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  18. #18
    willem's Avatar
    willem Guest


    Did you find this post helpful? Yes | No

    Question DT_INTS-14 and Multi_SPWM

    Dear readers,

    Although DT_INTS-14 and Multi_SPWM working great if using seperate, I can't get them running combined ....
    I included them together with ReEnterPBP.bas getting errors like

    ERROR Line 10: Redefinition of VAR. (Multi_SPWM.pbp)
    ERROR Line 13: Redefinition of VAR. (Multi_SPWM.pbp)
    ERROR Line 14: Redefinition of VAR. (Multi_SPWM.pbp)
    ERROR Line 18: Redefinition of VAR. (Multi_SPWM.pbp)
    ERROR Line 20: Redefinition of VAR. (Multi_SPWM.pbp)

    (if the order I included them is changed I got about same errors by DT_INTS-14)
    I guess it's because same variables (psave, wsave etc) used in both of them but I don't have the ASM experience to solve the problem and would appreciate any advise/tips.
    Also tips to use another way to interrupt (INT_INT on RB0) Multi_SPWM are welcome...

    Thank you !

    Willem

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


    Did you find this post helpful? Yes | No

    Default

    Hi willem,

    It's a little more than the duplicate variables. They also both want exclusive use of the interrupt vector, and they handle the interrupts in a different way too.

    I've thought about writing a version for DT_INTS, but just haven't had the time. It's quite doable, but it definately takes some ASM.

    Sorry for the bad news,
    DT

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


    Did you find this post helpful? Yes | No

    Cool Software PWM for DT_INTS-xx

    Ok Willem,

    Well, I decided to forget about the things I should have done this weekend, and went ahead and re-wrote the SPWM program to work with the Instant Interrupt system.

    I've added a few things, and it works a little different this time around. So, be sure to look close at the example.

    It'll work with either the 18F or 14-bit versions, even though I only put it in the DT_INTS-14 section for now.

    SPWM_INT
    http://www.darreltaylor.com/DT_INTS-14/SPWM.html

    Enjoy,
    DT

  21. #21
    Baddzso's Avatar
    Baddzso Guest


    Did you find this post helpful? Yes | No

    Default EUSART int

    hi all! hi Darrel!
    I have a question: with these int handler routines can i use hserin with interrupt? because i think the on interrupt command too slow, i have to wait about 1 ms after first char to the pic jump to int routine and receive other chars with hserin.
    many thanks!

    pic: 16f690, intosc, ~7,3728MHz

    (I don't have time to read everything, sorry if this question are answered...)
    Attached Files Attached Files
    Last edited by Baddzso; - 2nd October 2006 at 23:17.

  22. #22
    Join Date
    Jul 2005
    Posts
    93


    Did you find this post helpful? Yes | No

    Question Dt_ints-18 18f4550 usb_int usb bootloader

    I realize i'm likely behind about 2 years on this one.. i've been trying to modify Mister E / Darrel's USBDEMO code so that it works with my existing setup (a vb app that aquires 8 bit a/d result from the chip over usb cdc com port and also relays it to a serially connected 16F767.

    Can anyone make comment or point me to the appropriate thread discussing the DT INTS & Microchip bootloader on an 18F4550. I can't seem to get it going.. i'm doing a cdc device that otherwise works fine with the standard "usbservice" everywhere method.. so I know I don't have a hardware issue... basically what occurs with the new program is nothing. and stuff freezes too (Hyperterminal, my application) without getting any data (or so it seems).

    The device i'm building (i'm not showing you it's a total hackjob - that works) is "self powered" (i think) It runs off either a Max756 or a 7805C output or USB power, which on my hackjob of a board, is selected with jumpers. I've been attempting to detect the state of the usb connection, with limited success.. which currently involves 1x 100k and 1x 10k resistors to ground and USBV+ (5v from the usb cable) meeting in the middle at PORTB.0 which i've named "USBCONNECTED".

    Do I need the INTERRUPT_ORG defines, something else? I'd also like to implement a "SLEEP" command when the cable isnt connected, if anyone can tell me how to properly detect the cable and connection as this is a self powered device which will run off battery / solar power. I've done some research and have a working device but I think my newbish methods for doing things is limiting the speed and using more power than it needs to (logic draws about 60-120mA running full tilt while not connected to USB (no sleep)


    Basically I suppose my question is what should I do in addition to this code in order to use Darrels Interrupt system and use the Microchip Bootloader.


    The Instant Interrupts modified code, sorry for the long post:

  23. #23
    Join Date
    Jul 2005
    Posts
    93


    Did you find this post helpful? Yes | No

    Default the code

    Code:
    '   
        '   RCUSB     ; Edited 'USBDEMO' from Steve and Darrel
        '   =======
        '   
        '   File name  : RCUSBCOMM_INT.pbp
        '   Company    : Rytech Computing 
        '   Programmer : Steve Monfette, Darrel Taylor, Ryan Barrett
        '   Date       : November 23, 2008
        '   Device     : PIC18F4550 & 20MHZ crystal
        '
        '
        '   USB I/O 
        '
        '   Hardware:
        '   ---------
        '       ACTLED PORTB.1 
        '       INTERNAL DEBUG LEDS PORTD.0-3
        '       5v Logic A/D Monitor AN0 USB/Max756/7805 output
        '       Max756v AA/AAA input A/D Monitor AN1 5v max
        '       12v voltage/4 divider A/D Monitor AN2 20v max 7805C input
        '       Max4172 LOAD A/D Monitor AN3 5A max 
        '       Max4172 CHARGE A/D Monitor AN4 2A max
        '       USB Sense PORTB.0 USB Active High
        '       20 MHZ crystal & all the usual USB stuff
        '       Internal button PORTB.4
        '
        '
        '
        '   Pic Configuration
        '   =================
              asm
        __CONFIG    _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L  
        __CONFIG    _CONFIG1H, _FOSC_HSPLL_HS_1H & _FCMEN_OFF_1H & _IESO_OFF_1H 
        __CONFIG    _CONFIG2L, _PWRT_ON_2L & _BOR_ON_2L  & _BORV_2_2L  & _VREGEN_ON_2L   
        __CONFIG    _CONFIG2H, _WDT_OFF_2H 
        __CONFIG    _CONFIG3H, _MCLRE_ON_3H & _LPT1OSC_OFF_3H & _PBADEN_OFF_3H & _CCP2MX_ON_3H 
        __CONFIG    _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _ICPRT_OFF_4L  & _XINST_OFF_4L & _DEBUG_OFF_4L 
        endasm
        DEFINE OSC 48   
        DEFINE LOADER_USED 1
        DEFINE RESET_ORG 800h       
        Define    ADC_BITS      8    
        Define    ADC_CLOCK       3
        Define    ADC_SAMPLEUS  100
    
        DEFINE CCP1_REG PORTC 
        DEFINE CCP1_BIT 2 
        DEFINE CCP2_REG PORTC 
        DEFINE CCP2_BIT 1 
        '
        '   Hardware configuration
        '   ======================    
            '
            '   I/O and PORTs
            '   -------------  
        PORTB   =   0
        PORTC   =   0
        PORTD   =   0
        PORTE   =   0
        TRISB   =   %00010001
        TRISC   =   0
        TRISA   =   %11111111
        TRISD   =   %00000000
        TRISE   =   0
            '
            '   A/D converter
            '   -------------       
        ADCON0  =   %00000001       
        ADCON1  =   %00001000        
        ADCON2  =   %00000111      
            '
            '   CCP/PWM
            '   -------
    '    CCP1CON =   %00001100       ' CCP1, PWM mode
    '    CCP2CON =   %00001100       ' CCP2, PWM mode
    '    PR2     =   249             ' 12khz PWM Freq
    '    T2CON   =   %00000101       ' TMR2 on, prescaler 1:4
            '
            '   USB module
            '   ----------
       ' UCFG    var byte EXT        ' include UCFG register... Yeah Melabs didn't :o(
        ucfg    =   %00010100       ' enable internal USB pull-up, Full speed USB
    
        '   
        '   Interrupt definition
        '   ====================
            '   USB interrupt used to keep USB connection alive
    INCLUDE "DT_INTS-18.bas"    ' Base Interrupt System
    
    ASM
    INT_LIST  macro    ; IntSource,          Label,  Type, ResetFlag?
            INT_Handler    USB_INT,  _DoUSBService,   ASM,  yes
        endm
        INT_CREATE               ; Creates the interrupt processor
    endasm
    
    
        '   
        '   Variables & constants definition 
        '   ================================
        USBBufferSizeTX     con 16       ' input 
        USBBufferSizeRX     con 16       ' output
        USBBufferCount      Var Byte    '
        USBBufferIn         var byte[16] ' store incomming USB data
        USBBufferOut        Var Byte[16] ' store outgoing USB data       
        DataToSend          var byte[16] ' store ADCs & pushButton data to send to USB
        usb_device_state   var byte EXT
        CONFIGURED_STATE   CON EXT
        String1            var byte[16] ' hold 'USB DEMO' string       
            string1[0]="R"
            string1[1]="C"
            string1[2]="U"
            string1[3]="S"
            string1[4]="B"
            string1[5]="C"
            string1[6]="O"                                                                        
            string1[7]="M"  
            String1[8]="M"
            String1[9]="_"
            String1[10]="V"
            String1[11]="1"
            string1[12]="a"
            string1[13]=" "
            string1[14]=" "
            string1[15]=" "
        adval   Var    Byte[8]
        pwmduty var BYTE[4]
        PKTSUM  var byte
        QUAL    con 229
        ACTLED  var PORTB.1 
        spout   var PORTB.7
        DLED1   VAR PORTD.0
        DLED2   VAR PORTD.1
        DLED3   VAR PORTD.2
        DLED4   VAR PORTD.3
        USBCONNECTED var PORTB.0
    
           
        '   Constants definition 
        '   ====================
        GoDone              var ADCON0.1 ' ADC conversion
    
        '
        '   Macro(s) definition
        '   ===================
        asm 
    
    SendUSB macro array
        ;   Use to Copy an specific array to USBBufferOut AND send it
        ;   to USB bus
        variable i=0
        while i<16
            MOVE?BB (array+i),(_USBBufferOut+i)
    i+=1
        endw
        L?CALL _DoUSBOut
        endm
        endasm
    
        '   
        '   Software/Hardware initialisation
        '   ================================
    SwHwInit:
            HIGH DLED1
            Pause 490
            LOW DLED1
            Pause 500
            HIGH DLED1
            Pause 500
            LOW DLED1
            Pause 500
            HIGH DLED1
            Pause 500
            LOW DLED1
            Pause 500
            HIGH DLED1
            adval[0]= 0
            adval[1]= 0
            adval[2]= 0
            adval[3]= 0
            adval[4]= 0
            adval[5]= 0
            adval[6]= 0
            adval[7]= 0
            pwmduty[0]= 0
            pwmduty[1]= 0
            pwmduty[2]= 0
            pwmduty[3]= 0
            gosub DoUSBinit:
        '
        '   Main program start
        '   ==================
    Start: 
        '   
        '   ------------------------------------------------------------ 
            if (PORTB.4)!=0 then
    @       SendUSB _String1
            TOGGLE DLED2               
            endif
        toggle actled
    'GOSUB GetAD:
    'GOSUB toLCD:
    datatosend[0] = "A"
    DataToSend[1] = "V"
    DataToSend[2] = "B"
    Datatosend[3] = adval[0]
    Datatosend[4] = "C"
    Datatosend[5] = adval[2]
    Datatosend[6] = "D"
    Datatosend[7] = adval[3]
    Datatosend[8] = "E"
    Datatosend[9] = adval[4]
    DataToSend[10]= "F"
    Datatosend[11]= "Z"
    Datatosend[12]= "G"
    Datatosend[13]= "Y"
    Datatosend[14]= "Z"
    Datatosend[15]= "Z"
    @   SendUSB _DataToSend 
    gosub dousbin:
    GOTO START:
    
        '
        '                           Subroutines area
        '                           ================        
        '
        '
    DoUSBIn:
        '
        '   Check and receive data from the USB bus                            
        '   =======================================
    @  INT_DISABLE USB_INT
        USBBufferCount = USBBufferSizeRX                ' RX buffer size
        USBService                                      ' keep connection alive
        USBIn 1, USBBufferin, USBBufferCount, Timeout   ' read data, if available
    Timeout:                                            '
    @  INT_ENABLE USB_INT
        pwmduty[0]  = USBBUFFERIN[0] ' output to PORTB
        pwmduty[1]  = USBBufferin[1]
        pwmduty[2]  = USBBufferIn[2]
        pwmduty[3]  = USBBufferIn[3]
        return
        '
        '
        '
    DoUSBOut:
        '
        '   Send data to the USB bus & Wait for USB interface to attach                         
        '   ===========================================================
    @  INT_DISABLE USB_INT
        WaitPC:                                         '
        USBBufferCount = USBBufferSizeTX                ' TX buffer size
        USBService                                      ' keep connection alive
        USBOut 1, USBBufferOut, USBBufferCount, Waitpc  ' if bus available, transmit data
    @  INT_ENABLE USB_INT
        return
    
    ;_____________________________________________________________________________
    
    ;_______________________________________________________________________________________________________
    DoUSBinit:
        pause 500
        usbinit ' initialise USB...
        repeat  ' kick-start it
            usbservice
        until usb_device_state = CONFIGURED_STATE
    @   INT_ENABLE  USB_INT
    return
    ;_______________________________________________________________________________________________________
    DoUSBService:
        usbservice
    @   INT_RETURN
    ;_______________________________________________________________________________________________________
    GetAD:
    ADCON0=%00000001:Gosub GetSample:adval[0]=ADRESH 'get AN0 into adval[0] (7805 5v source voltage)
    toggle actled
    'ADCON0=%00001001:Gosub GetSample:adval[2]=ADRESH '12v Voltage -skip over AN1 (max756) get AN2 (12v battery source voltage divider output) into adval[2]
    'toggle actled
    'ADCON0=%00001101:Gosub GetSample:adval[3]=ADRESH   ' 12v Current -AN3 into adval[3] (max4172 12v battery current out)  
    'toggle actled
    'ADCON0=%00010001:Gosub GetSample:adval[4]=ADRESH   'AN4 into adval[4] (12v Input current)
    RETURN
    ;_______________________________________________________________________________________________________
    GetSample:
    PAUSEUS 100
    GoDone=1
    While GoDone=1:Wend
    Return
    ;_______________________________________________________________________________________________________
    ToLCD:
    SerOut2 spout,16468,[DEC3 QUAL,DEC3 adval[0],dec3 adval[2],Dec3 adval[3],dec3 pwmduty[0],dec3 pwmduty[1],dec3 pwmduty[2],DEC3 pwmduty[3],13,10]
    RETURN
    Last edited by ScaleRobotics; - 2nd December 2010 at 07:35.

  24. #24
    Join Date
    Jul 2005
    Posts
    93


    Did you find this post helpful? Yes | No

    Default

    thought i'd post my setup:

    MPASM 5.20
    PBP 2.50b
    MCS 3.0.0.5

  25. #25
    Join Date
    Jan 2007
    Posts
    2


    Did you find this post helpful? Yes | No

    Default version of the compiler?

    What version of the compiler should be used? Thanks,

  26. #26
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    2.46 or higher (2.47 here)

    MPASM... just download the latest version of MPLAB 7.51 (maybe 7.52 now).
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

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


    Did you find this post helpful? Yes | No

    Default Can nested gosubs be used from within PBP instant Interrupt

    Hi,

    I need to call a subroutine from within a low priority PBP instant interrupt on a PIC 18F452. I am using both High Priority and Low Priority Interrupts.

    I need to know whether PBP uses a software stack for its gosub calls or use the PIC18 stack pointer. I am concerned if calling a nested gosub from within a PBP InstInt would cause stack overflow.
    Regards

    Sougata

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


    Did you find this post helpful? Yes | No

    Default

    PBP uses the hardware Stack. But with 31 levels on the 18F's, you have to be pretty sloppy to overflow it.

    The PIC itself uses the Hardware Stack to handle an interrupt. But, DT_INTS does NOT use the Hardware Stack. It essentially uses a 2-level software stack. 1 for High Priority, and 1 for Low.

    Once in an interrupt, it's OK to call a subroutine, as long as both HIGH and LOW priorities can never call the same routine at the same time.

    HTH,
    DT

  29. #29
    Join Date
    Oct 2003
    Location
    Australia
    Posts
    257


    Did you find this post helpful? Yes | No

    Default Ad_int Problems

    DT,

    I'm trying to force an interrupt whenever the voltage on my analog input pin changes (connected to a 5k POT and RA:0, 16F88).

    I was hopping that AD_INT handler would fire when ever the POT was adjusted but it doesn't.

    I can read the POT voltage ok in my program, so I think all the analog stuff is set ok.

    Is what I am trying to do gonna work or not?

    Squib

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


    Did you find this post helpful? Yes | No

    Default AD_INT does not work that way

    Hi,
    an interrupt whenever the voltage on my analog input pin changes
    The ADC takes a finite time to complete its conversion. When the conversion is complete the AD_INT flag is set. This means that you should always start your conversion manually. However your PIC16F88 has a compare module. That can automatically setup periodic conversion of your AD module. So you would be getting interrupts from the AD_INT that a new value is available. Just read the AD results and compare it with the previous one to find out if your pot has been changed. Please note do not expect two consecutive conversions to be exactly equal even if you are not touching the pot. Supply, layout, noise, blah, blah...... . So compare it for a change of value within a range.
    Regards

    Sougata

  31. #31
    Join Date
    Oct 2003
    Location
    Australia
    Posts
    257


    Did you find this post helpful? Yes | No

    Default

    Hmm,

    That kind of defeats the purpose of what I wanted to do....

    All understood and thanks for the info.

    Rgds,
    Squib

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


    Did you find this post helpful? Yes | No

    Default Use your compare module in special event trigger

    Hi Squibcakes,

    You can use your compare module to automatically fire your ADC at a given interval. So the ADC will automatically generate interrupts. In your interrupt routine compare the current value with the old value. Keep some margin as two consecutive results may be different even if your pot is unchanged. When a change is found set a flag and process it in your main loop.
    Regards

    Sougata

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


    Did you find this post helpful? Yes | No

    Default

    sougata,

    I'm glad it's working out for you. And yes, it is more managable. Kinda the whole idea behind it.

    Squibcakes,

    No, it doesn't work that way.

    The AD_INT is fired on the completion of an A/D conversion. Not when the value changes.

    So, in your AD_INT handler, you could test to see if the recent A/D reading differs from the previous A/D value. If it does, call a subroutine.

    Then start another conversion before exiting the handler.

    Added: Or like sougata said, have a timer periodicaly start a conversion, then do the same.

    HTH,
    DT

  34. #34


    Did you find this post helpful? Yes | No

    Default Re: Instant Interrupts - Revisited

    Quote Originally Posted by Darrel Taylor View Post
    sougata,

    I'm glad it's working out for you. And yes, it is more managable. Kinda the whole idea behind it.

    Squibcakes,

    No, it doesn't work that way.

    The AD_INT is fired on the completion of an A/D conversion. Not when the value changes.

    So, in your AD_INT handler, you could test to see if the recent A/D reading differs from the previous A/D value. If it does, call a subroutine.

    Then start another conversion before exiting the handler.

    Added: Or like sougata said, have a timer periodicaly start a conversion, then do the same.

    HTH,
    I've been using DT_INTS-14 for a while with various types of interrupts but now I want to implement one for A/D. I've created the dummy interrupt handler, but my question is whether I can read the value of the conversion using PBP's ADCIN or should I grab directly from the registers. If the latter, I could use some help with that.

    My ADC set up is as follows:

    Code:
    ; PIC12F1840
    
    DEFINE ADC_BITS      8       ; Set number of bits in result
    DEFINE ADC_SAMPLEUS  5       ; Set sampling time in uS
    DEFINE ADC_CLOCK     3       ; Set clock source (3=rc)
    
    FVRCON    = 0                ' Fixed Voltage Reference is disabled
    ANSELA    = %00000010        ; Analog on PORTA.1 (AN1) only
    ADCON0    = %00000101        ' ADC (analog-to-digital) is enabled on AN1 (RA1) only
    ADCON1.7  = 0                ; Left-justified results in 8-bits
    
    ASM
    INT_LIST  macro    ; IntSource,           Label,  Type, ResetFlag?
            INT_Handler    INT_INT, _Flash_Mode_Btn,   PBP,  yes
            INT_Handler     AD_INT, _ADC_change,       PBP,  yes
        endm
        INT_CREATE     ; Creates the interrupt processor
    ENDASM
    
    
    ' Enable interrupts
    @ INT_ENABLE   INT_INT      ; INT Interrupt
    @ INT_ENABLE   AD_INT       ; A/D Interrupt
    I'm working on implementing Darrel's MIBAM with a trim pot to set the brightness of an LED.

  35. #35
    Join Date
    Oct 2005
    Posts
    35


    Did you find this post helpful? Yes | No

    Question Darrels' Bring Together Interrupts

    Hello,


    I have been toying with Darrels' interrupts and the elapsed timer

    programs. It's an amazing piece of work and just what I need at the

    moment. Thanks!

    Going on, I tried the "bring together" demo but that didn't go so

    well. It won't compile using MPASM. The error messages are ;


    FATAL ERROR too many errors
    Error line 15: redefination of VAR. (DT_INTS-14.bas)
    Error line 26: redefination of VAR. (DT_INTS-14.bas)
    Error line 27: redefination of VAR. (DT_INTS-14.bas)


    ........Etc.


    I am using the Pic 16f877 but that shouldnt matter at this point.

    Any ideas?

    Thanks John
    Thanks,
    Homerclese

  36. #36
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    mmm, weird, no problem here. so we talk about
    http://darreltaylor.com/DT_INTS-14/combine.html

    If so, did you add something special in the code or you're using EXACTLY the following...
    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
           LCDOUT $FE,$C0, DEC Days,"d-",DEC2 Hours,":",DEC2 Minutes,":",DEC2 Seconds
        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
    which version of PBP and MPASM are you using?

    Are all files located in the same folder?
    Last edited by mister_e; - 2nd March 2007 at 00:11.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  37. #37
    Join Date
    Oct 2005
    Posts
    35


    Did you find this post helpful? Yes | No

    Question

    Hello,

    I tried a cut and paste of your code and got a whole new set of errors. The only code differences I could find were the ones at the top for outputting to a LCD display. The include files all exist in my usual PBP folder. I'm using Microcode Studio version 2.2.1.1 with Pic Basic Pro 2.40.


    Thanks John
    Thanks,
    Homerclese

  38. #38
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    did you get...
    <img SRC="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1438&stc=1&d=117284877 8">

    If so, make sure you have selected MPASM in the View>> Compile And Program option >>> Assembler

    EDIT
    Pic Basic Pro 2.40.
    I don't know if it could be the problem... The current version is now 2.47.
    Attached Images Attached Images  
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  39. #39
    Join Date
    Jan 2006
    Posts
    31


    Did you find this post helpful? Yes | No

    Default Multiple interrupt

    Hi Darrel

    I've seen lots sample codes of digital clock and elapsed timer demos in this forum and all of them are using LCD as an output device. I was wondering why is it that nobody post sample codes driving 7-segment displays in multiplex mode?

    I've seen your code and it was amazing. I tried compiling it but i received errors. I'm using PIC16F628A, 4MHz xTAL and PICBasic Pro v2.33.

    I'm planning to test your code using TMR0 interrupt handling the refreshing of the 7-segments and TMR1 handling the 1/100 timer tick.

    Can you share to me sample approaches on how to handle the elapsed timer using 7-segment displays in multiplexed mode?


    emavil

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


    Did you find this post helpful? Yes | No

    Thumbs up Thanks Darrel

    Hi,

    It works. Your II rules. I am using it to 100Hz and thanks for your concern.
    Regards

    Sougata

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 : 6

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