Instant Interrupts - Revisited - Page 10


Closed Thread
Page 10 of 20 FirstFirst ... 67891011121314 ... LastLast
Results 361 to 400 of 773
  1. #361
    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:

  2. #362
    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.

  3. #363
    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

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


    Did you find this post helpful? Yes | No

    Default

    What!
    You're trying to use a HID program with CDC?

    Well, you can start by using endpoint 3.

    Wouldn't be surprised if there are more problems though.
    <br>
    DT

  5. #365
    Join Date
    Jul 2005
    Posts
    93


    Did you find this post helpful? Yes | No

    Default

    I wasnt aware that the interrupt system was specifically for HID devices... anyways i'm back to trying to make my code work... it's really annoying.. the device works as expected, until i try and aquire a/d and send a serout2 in my main loop.. then it's device not recognized.. i think my brain might explode soon.

  6. #366
    Join Date
    Jul 2005
    Posts
    93


    Did you find this post helpful? Yes | No

    Default

    ahh i see what ur saying darrel.. i' used your code which points to endpoint 1.. i'm going to try it changing it to 3

  7. #367
    Join Date
    Jul 2005
    Posts
    93


    Did you find this post helpful? Yes | No

    Default

    k i think your hint has moved the situation forward.. i'm now getting some output... thanks ... I know I know im a big noob

  8. #368
    Join Date
    Jul 2005
    Posts
    93


    Did you find this post helpful? Yes | No

    Default

    Just gotta figure out now why my adc is all over the place

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


    Did you find this post helpful? Yes | No

    Default

    Are the A/D values all over the place? Or is it the received data at the VB program?

    The way it was shown, you'll be sending and receiving a bunch of extra data by transferring the entire buffer, instead of just the data that needs to be used.

    HID is packet based, CDC is more like standard serial.
    You'll need to consider how many bytes were received, and look for "header" bytes or some other mechanism to sync up the data.

    Everything won't just be at byte[x] in the buffer anymore.
    <br>
    DT

  10. #370
    Join Date
    Jul 2005
    Posts
    93


    Did you find this post helpful? Yes | No

    Smile

    Hi,

    I have some mostly working code now using your interrupts thanks to your "hint" about the endpoints earlier...

    I was reading another thread that was about "If plugged" - The solution works great monitoring SOFIF and IDLEIF registers - the main loop now does run when the cable is unplugged.

    The only case that is still at issue for me is that the device doesnt go passed the "DoUSBinit" subroutine if it's powered on while not connected - which for me is a big deal because the device i'm building is going to be powered up at times with just the LCD i have connected. This LCD is managed by a 16F767 in another device which has some fans too and a light. it's all connected via cat5e cable for one way serial transmission from the 18F4550 via serout2 commands, and i give it 12v and GND each via 3 wires respectively which feed a 7805 and a couple transistors for pulsing the fan speed and light intensity, that all appears to work nicely)

    So I guess the last thing to do before I glue everything together (lol) is to get the device to go to the main loop if usb cable is not plugged at initialization time (and have the usb still work after if its eventually plugged in while the device is running).

    Anyone else have this "self-powered device" / usbinit kind of issues?

  11. #371
    Join Date
    Jul 2005
    Posts
    93


    Did you find this post helpful? Yes | No

    Default

    Darrel the "extra" data is for parsing strings that come in after my oncomm event in visual basic. I get the stuff in between the letters - I haven't successfully used "binarymode" in vb .. always stuck with text mode.

    I use whats come in between "A" and "B" to fork the other data over to certain variables... there's probobly a much better way to do it... I've already seen instances where manipulating the strings in higher speed timers cause lockups and weird things happening.

    But that's not really the right forum for that.. but i'm interested to resolve the issue with the "cable not in during usbinit on device initialization" issue.
    Last edited by RYTECH; - 25th November 2008 at 08:46.

  12. #372
    Join Date
    Jul 2005
    Posts
    93


    Did you find this post helpful? Yes | No

    Default

    Should i wire up an input to the USB V+ and monitor that in addition to the IDLEIF SOFIF registers? USB ---4.7k ----pic input --100k---GND?

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


    Did you find this post helpful? Yes | No

    Default

    The only case that is still at issue for me is that the device doesnt go passed the "DoUSBinit" subroutine if it's powered on while not connected
    Yeah, when it's not connected, it'll never make it to the CONFIGURED_STATE.

    Change the Init routine to this.
    Code:
    DoUSBinit:
        pause 500
        usbinit                  ; initialise USB...
        USBSERVICE               ; service it once
        UIE = $7F                ; enable USB interrupts
        UEIE = $9F               ; enable USB Error interrupts
        @ INT_ENABLE USB_INT
    return
    DT

  14. #374
    Join Date
    Jul 2005
    Posts
    93


    Did you find this post helpful? Yes | No

    Default

    Thanks Darrel that did it for me!

  15. #375
    Join Date
    Jul 2005
    Posts
    93


    Did you find this post helpful? Yes | No

    Default

    Does the USB operation of the 18F4550 have a direct effect on the A/D channels..? Let me explain why i ask....

    Case a) when i power up my circuit the A/D values float - not 200 or 300 millivolts - which for my inexperience, hackjob craftsmanship, and source voltage reference would be acceptable, but sometimes, usually when i power up without the usb cable connected, the values float sometimes as much as 800 millivolts on my 12v line, i've metered the several points, there's no floating, so it's something to do with the IC's operation. I can usually correct the issue by plugging in the device and unplugging it. I'm stumped as to what exactly is going on... i'm wondering if this 800 millivolt swing has something to do with the pic enabling or disabling its internal pullups on the usb data lines. it seems to revolve around the state of the usb connectivity... when the problem is not present my readings are mostly acceptable, the caps and aquisition times seem to work ok.

    wonder whats going on... i think i chose the wrong IC for my solar powered charge controller... I really like the usb connectivity, but the IC with only 1 power led and 1 led that flashes every so often (about 1/16 cycles through main) the circuit draws about 120 mA... is that around normal for not having any sleep cycle in main? I tried to activate the WDT to implement a sleep but it seems the USB bootloader (or something) doesnt like it, cause when i reset the chip after the WDT enable change the USB reports the device is not recognized....

  16. #376
    Join Date
    Jul 2005
    Posts
    93


    Did you find this post helpful? Yes | No

    Default

    so i guess i actually have 2 issues still, i cant sleep (neither can my device) and the A/D sometimes acts "wonky" depending on the state of the usb pluggedness.

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


    Did you find this post helpful? Yes | No

    Default

    I've never tried to put a USB PIC to sleep.
    But the datasheet has some warnings about putting the USB module in "Suspend" mode before going to sleep, and using the Resume bit to "wake-up" on USB activity.
    See section 17.2

    Could be tricky.

    120ma sounds pretty high.
    Try disabling the USB module and VUSB regulator and see if that's where it's comming from. The datasheet doesn't seem to list the current for the USB module.
    <br>
    DT

  18. #378
    Join Date
    Nov 2008
    Posts
    48


    Did you find this post helpful? Yes | No

    Default

    I tried to compile my application with Darrels interrups, i get the compiler errors:
    Error[113] c:\pbp\pbppic18.lib 1200 : Symbol not previously defined(INT_ENTRY_H)
    Error[113] c:\pbp\pbppic18.lib 1214 : Symbol not previously defined(INT_ENTRY_L)
    Message[301] d:\embedded\......... test.asm : MESSAGE: (Temp variables exceeding T7)

    Can someone help ???

    Pic is a 18F6722

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


    Did you find this post helpful? Yes | No

    Default

    For the first two, you probably haven't defined the interrupt sources or handlers.

    See this page for an example.
    http://darreltaylor.com/DT_INTS-18/hello.html

    For the T7 warning, read this ...
    http://www.picbasic.co.uk/forum/show...&postcount=348
    <br>
    DT

  20. #380
    Join Date
    Nov 2008
    Posts
    48


    Did you find this post helpful? Yes | No

    Default

    Hello Darrel,
    thanks, it works now, but there are coming up some more problems:

    When the timer makes 1 second tick, i call a subroutine which has several
    serin2 and serout2 commands to read and set data from some other modules.
    It seems to come to write and read errors (time out comes in the serin2 and serout2 commands).
    Also reading and writing to the 12c bus with I2CREAD and I2CWRITE to
    a display doesn't work any more correct.

    I enabled tmr0, tmr1, rx1 and rx2

    Regards,
    Ralf

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


    Did you find this post helpful? Yes | No

    Default

    If you've enable RX1_INT and RX2_INT, then what is the SERIN/OUT for?

    Aren't you using the USARTS?
    <br>
    DT

  22. #382
    Join Date
    Nov 2008
    Posts
    48


    Did you find this post helpful? Yes | No

    Default

    Sure, i am using both uarts of the Pic, but i have one more serial port accessing
    via serin/serout some more serial devices also (a eight devices bus). The status
    and some controls of these eight modules accessed via serin/serout are
    controlled by the two uarts to a rs232 and a ethernet board.

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


    Did you find this post helpful? Yes | No

    Default

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

    Since you have 4 different things interrupting, the software timing is getting messed up pretty bad.

    If you only needed the transmit side, you could use ...

    Tmr_tx-18
    http://www.picbasic.co.uk/forum/show...1&postcount=28

    But it sounds like you need the RX side too.

    With a need for 3 USART's, You may be out of luck.
    DT

  24. #384
    Join Date
    Nov 2008
    Posts
    48


    Did you find this post helpful? Yes | No

    Default

    Hi Darrel,
    it works now, but is very critical in timing.
    I think about using 12c, but i did not find a good i2c slave routine.
    I tested one in the past, but without success.... :-(
    Did you test your interrupts as an i2c slave? Can you help on this?
    Regards,
    Ralf

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


    Did you find this post helpful? Yes | No

    Default

    > Did you test your interrupts as an i2c slave?

    I haven't, but Robert Soubie did.
    http://www.astrosurf.com/soubie/pic_as_an_i2c_slave.htm
    <br>
    DT

  26. #386
    Join Date
    Nov 2008
    Posts
    48


    Did you find this post helpful? Yes | No

    Default

    I have his routine, writing seems to work but reading not... :-(

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


    Did you find this post helpful? Yes | No

    Default Changing direction after INT

    I'm trying to understand how to return to a specific place when coming out of a INT.

    Specifically, when I receive a command serially and trip the RX_INT, I need to abort the current operation in the main body of the program and restart with the newly commanded mode.
    I have looked at DT_INTS and other advise on interrupts, and still don't understand what I would need to change to get this to happen.
    The code works otherwise and gathers the command from the serial line, its just that I have to wait for the current operation to complete for it to be recognized and acted upon.

    The main code is driving patterns on 8 LEDS with SPWM_INT and it takes 10 or 20 seconds for it to get around to the place where it looks at the new mode. This also applies when I change the mode with a switch input. I have to wait until the operation is finished to get to the part where I look for the input.

    I don't believe that I can just mess with the RetAddr variable in DT_INTS and have that work without other steps. If I have a GOTO in the ISR, then I would likely corrupt the RETURN. I could just sprinkle switch and comm checks all over the place looking for flags, but that seems mediocre. Any advise?

    Thanks
    Mark

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


    Did you find this post helpful? Yes | No

    Default

    We were just talking about that last month.

    This might help.
    http://www.picbasic.co.uk/forum/showthread.php?t=10263
    <br>
    DT

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


    Did you find this post helpful? Yes | No

    Default

    Thanks for the pointer.

    I find myself trying to be more careful about how I name threads.

    It seems that if you miss something when it comes by, it can be spotty when you try to find it again.
    I have been putting effort into a systematic method to catalog the threads that I get the most from.

    There is a wealth of info if I can get better at mining it.

    Mark

  30. #390
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default How long does it take to process disable command?

    Hi DT,

    When @ INT_DISABLE TMR0_INT command is used @4Mhz 16F628A, can you estimate how long does it take to process it and eventually disable it?

    uS?


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

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


    Did you find this post helpful? Yes | No

    Default

    Hi Sayzer,

    For 14-bit chips,
    It takes 1 instruction cycle to disable the interrupt and depending on what bank it's in at the time, it may take 1 or 2 instructions to change to the correct bank before disabling.

    So @ 4mhz, it could take from 1 to 3 uS.

    On 18F's, it's always just 1 instruction.
    <br>
    DT

  32. #392
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    Hi Sayzer,

    For 14-bit chips,
    It takes 1 instruction cycle to disable the interrupt and depending on what bank it's in at the time, it may take 1 or 2 instructions to change to the correct bank before disabling.

    So @ 4mhz, it could take from 1 to 3 uS.

    On 18F's, it's always just 1 instruction.
    <br>


    I assume your answer would be the same for other sources of interrupt (other then TMR0).
    In any case, 3 uS is more then good enough for my case.

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

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


    Did you find this post helpful? Yes | No

    Default PIC16F616, Interrupt on PORTA change

    Not sure if this have been covered, but however. I'm actually working with a PIC16F616, there's no interrupt on PORTB change on this one, but Interrupt on PORTA change, great Microchip

    From what i see, it is not included in DT_INTS-14, so here's one method to do so...

    Open DT_INTS-14, and add the sections in Red
    Code:
    ASM
      #define INT_INT   INTCON,INTF     ;-- INT External Interrupt
      #define RBC_INT   INTCON,RBIF     ;-- RB Port Change Interrupt
      #define RAC_INT   INTCON,RAIF     ;-- RA Port Change Interrupt
      #define TMR0_INT  INTCON,T0IF     ;-- TMR0 Overflow Interrupt 16F
      #define TMR1_INT  PIR1,TMR1IF     ;-- TMR1 Overflow Interrupt
      #define TMR2_INT  PIR1,TMR2IF     ;-- TMR2 to PR2 Match Interrupt
      #define TX_INT    PIR1,TXIF       ;-- USART Transmit Interrupt
      #define RX_INT    PIR1,RCIF       ;-- USART Receive Interrupt
      #define CMP_INT   PIR2,CMIF       ;-- Comparator Interrupt
      #define EE_INT    PIR2,EEIF       ;-- EEPROM/FLASH Write Operation Interrupt
      #define BUS_INT   PIR2,BCLIF      ;-- Bus Collision Interrupt
      #define PSP_INT   PIR1,PSPIF      ;-- Parallel Slave Port Read/Write Interrupt
      #define AD_INT    PIR1,ADIF       ;-- A/D Converter Interrupt
      #define SSP_INT   PIR1,SSPIF      ;-- Master Synchronous Serial Port Interrupt
      #define CCP1_INT  PIR1,CCP1IF     ;-- CCP1 Interrupt
      #define CCP2_INT  PIR2,CCP2IF     ;-- CCP2 Interrupt
    
    ENDASM
    
    asm
    INT_Source  macro  IFR, IFB, IER, IEB
        if ((IflagReg == IFR) && (IflagBit == IFB))
      list  
    INT_Flag_Reg = IFR
    INT_Flag_Bit = IFB
    INT_Enable_Reg = IER
    INT_Enable_Bit = IEB
    Found = YES
        endif
    ;  nolist  
        endm 
    endasm
    
    
    asm
    ;-------------------------------------------------------------------------------
    GetIntInfo  macro  IflagReg, IflagBit
    
    Found = NO
    ; nolist
      ifdef INTF    ;----{ INT External Interrupt }----------------[INTCON, INTF]---
          INT_Source  INTCON, INTF, INTCON, INTE
      endif
      ifdef RBIF    ;----{ RB Port Change Interrupt }--------------[INTCON, RBIF]---
          INT_Source  INTCON, RBIF, INTCON, RBIE
      endif
      ifdef RAIF    ;----{ RA Port Change Interrupt }--------------[INTCON, RAIF]---
          INT_Source  INTCON, RAIF, INTCON, RAIE
      endif
      ifdef T0IF    ;----{ TMR0 Overflow Interrupt }-------------[INTCON, TMR0IF]---
          INT_Source  INTCON, T0IF, INTCON, T0IE
      endif
      ifdef TMR1IF  ;----{ TMR1 Overflow Interrupt }---------------[PIR1, TMR1IF]---
          INT_Source  PIR1, TMR1IF, PIE1, TMR1IE
      endif
      ifdef TMR2IF  ;----{ TMR2 to PR2 Match Interrupt }-----------[PIR1, TMR2IF]---
          INT_Source  PIR1, TMR2IF, PIE1, TMR2IE
      endif
      ifdef TXIF    ;----{ USART Transmit Interrupt }----------------[PIR1, TXIF]---
          INT_Source  PIR1, TXIF, PIE1, TXIE
      endif
      ifdef RCIF    ;----{ USART Receive Interrupt }------------------[PIR1 RCIF]---
              INT_Source  PIR1, RCIF, PIE1, RCIE
      endif
      ifdef CMIF    ;----{ Comparator Interrupt }--------------------[PIR2, CMIF]---
          ifdef PIR2
              INT_Source  PIR2, CMIF, PIE2, CMIE
          else
              INT_Source  PIR1, CMIF, PIE1, CMIE
          endif
      endif
      ifdef EEIF    ;---{ EEPROM/FLASH Write Operation Interrupt }---[PIR2, EEIF]---
          ifdef PIR2
              INT_Source  PIR2, EEIF, PIE2, EEIE
          else
              INT_Source  PIR1, EEIF, PIE1, EEIE
          endif
      endif
      ifdef BCLIF   ;----{ Bus Collision Interrupt }----------------[PIR2, BCLIF]---
          INT_Source  PIR2, BCLIF, PIE2, BCLIE
      endif
      ifdef PSPIF   ;--{ Parallel Slave Port Read/Write Interrupt }--[PIR1, PSPIF]--
          INT_Source  PIR1, PSPIF, PIE1, PSPIE
      endif
      ifdef ADIF   ;----{ A/D Converter Interrupt }------------------[PIR1, ADIF]---
          INT_Source  PIR1, ADIF, PIE1, ADIE
      endif
      ifdef SSPIF  ;----{ Master Synchronous Serial Port Interrupt }--[PIR1, SSPIF]-
          INT_Source  PIR1, SSPIF, PIE1, SSPIE
      endif
      ifdef CCP1IF ;----{ CCP1 Interrupt }-------------------------[PIR1, CCP1IF]---
          INT_Source  PIR1, CCP1IF, PIE1, CCP1IE
      endif
      ifdef CCP2IF ;----{ CCP2 Interrupt Flag }--------------------[PIR2, CCP2IF]---
          INT_Source  PIR2, CCP2IF, PIE2, CCP2IE
      endif
        
      list
        endm
      list  
    ENDASM
    Sure enough there's some other PIC with interrupt on PORTA change, I just never came across one... or maybe... but never used that feature yet
    Steve

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

  34. #394
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default

    Oops - double post....removed.
    Last edited by HankMcSpank; - 19th May 2009 at 13:25.

  35. #395
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default

    mister_e.... I'd like to get interupts working on my 16F690 ....I visited Darrel's website & on the very first example "Hello World", he shows the code along with a short schematic - the interupt is showing as being presented on port RBO (actually called RBO/INT on the diagram).

    I have some (newbie!) questions...

    Are Darrel's interput routines for a specific PIC?

    I ask because my PIC 16F690 doesn't even have an RB0(!), therefore to my next question....

    Is there a particular PIC pin I should be using for his routines to work.

    My end goal is quite simple...I have an encoder wheel with 48 black stripes that I'm having one helluva job getting the polling right....I'd simply like to be able to use a PIC interupt for when each black stripe passes the photo transistor 'pickup' (to increment a PIC counter)

    That said, for testing puproses I do need one more interupt ...this being for a magnetic switch (I've glued a magnet to the edge of the disc so I know when the wheel has turned once) to interupt once per rev, I can then make sure that the PIC 'saw' all the stripes for the past rev....so to my other question - is there normally just one INT pin that's useable for externally triggered interupts on a PIC (specifically a 16F690)

    i'd dearly love to be able to use Darrel's simple routines...but I'm a little clueless wrt ensuring I'm connecting my incoming 'pulses' to the correct PIC 16F690 pins!

    edit: Darrel has kindly replied to the earlier PM I sent him, telling me that I need to look for the pin marked 'INT'...which on my PIC 16F690 is apparently pin RA2 - tks Darrel!
    Last edited by HankMcSpank; - 19th May 2009 at 13:24.

  36. #396
    Join Date
    Mar 2006
    Location
    China
    Posts
    266


    Did you find this post helpful? Yes | No

    Default Use T?CKI

    Hi,

    If you have a T?CKI pin on your pic you can use that pin to check for black stripes. This is the pin for the external clock signal connected to the internal timer/counter. This way you can get an interupt every black stripe or every 2:nd or once per wheel rotation (or anything else more or less). This is all depending of what you preload the counter with. If you have a 8-bit counter and load FF into it, next clock pulse will overflow the counter and you will get an interupt. If you preload it with FF-(dec 48) it will overflow once every full rotation of the wheel.

    If you just want to count the stripes preload it with 0 and off you go....

    This way your PIC will do most of the counting by itself and giving you more instruction time for something more useful.

    If you use the RA2/INT for the magnetic switch you can use RA5/T1CKI the external clock input for the stripes phototransistor

    /me
    Last edited by Jumper; - 19th May 2009 at 14:00.

  37. #397
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Jumper View Post
    Hi,

    If you have a T?CKI pin on your pic you can use that pin to check for black stripes. This is the pin for the external clock signal connected to the internal timer/counter. This way you can get an interupt every black stripe or every 2:nd or once per wheel rotation (or anything else more or less). This is all depending of what you preload the counter with. If you have a 8-bit counter and load FF into it, next clock pulse will overflow the counter and you will get an interupt. If you preload it with FF-(dec 48) it will overflow once every full rotation of the wheel.

    If you just want to count the stripes preload it with 0 and off you go....

    This way your PIC will do most of the counting by itself and giving you more instruction time for something more useful.

    If you use the RA2/INT for the magnetic switch you can use RA5/T1CKI the external clock input for the stripes phototransistor

    /me
    Thanks...there's some top tips there.

    Just a thought here - is it even possible to get reliable results with mechanical switches & interupts?

    By this I mean, a mechanical switch normally needs a debounce, else you'd get more than one interupt for every time the switch 'settled'? In my situation, it's importnat that there's just one 'trigger' for every revolution of the encoder wheel (so I can establish how many interupts/black stripes the PIC has counted over one rev)...if I used an interupt for the magnetic switch, there'd be a possibility of not just one interupt...but several in quick succession...which will cause a bit of 'fog' whilst trying to confirm that my wheel, circuit & PIC are all in sync & counting 48 stripes per turn!

    By the way...I've now dabbled with Darrel's "Hello World" which will suit my encoder wheel needs perfectly....after wrestling with 'pin' polling for weeks with my encoder wheel & getting very erratic results, I'm one very happy McSpank here today! October 05, 2002 maybe was a good day...but I can say without any shadow of a doubt, for me the 19 May 2009 was a lot better !!

    Just a couple of small suggestions for Darrel's website (to save avoid a lot of newbie-esque puzzlement) - on Darrel's very first hello world code page, it might be worth saying that a user will need to establish their own PIC variant's 'INT' pin, along with perhaps a couple of PIC specific examples. (it might be ovbious to you old hands, but looking at the plethora of pins PICs have, it wasn't obvious to me!)

    Also, for what it's worth...the 16F690 is perhaps the most common chip that newbies come into contact with at the moment (on account it's bundled with Microchip's very popular PikKit2 starter kit)...I had a problem with Darrel's "Hello World" code when I first compiled ...."error: variable wsave3 position request 416 beyond ram_end 367.", ultimately meaning a line in Darrel's DT_INTS-14.bas file needed commenting out - that might also be worth a mention too? (or at least some mention on a FAQ page?)

    Anyway, a hearty thanks to Darrel... without his effort towards making interupts easy with PICBasic , I'm sure I would have left interupts for another day (ie sometime in 2023!)
    Last edited by HankMcSpank; - 19th May 2009 at 15:50.

  38. #398
    Join Date
    Nov 2008
    Posts
    9


    Did you find this post helpful? Yes | No

    Default Help

    I am using a 16f866 with your instant interrupt but I cannot get it to wake up from sleep using a USART RX int.. If i use a Pause 1 in the main loop it works fine but I would really like for it to go to sleep and just wait. Please let me know what I am doing wrong.. here is the code.. Thank you Darrel for the awesome instant interrupt routines.


    Code:
    Define OSC 8
    
    INCLUDE "DT_INTS-14.bas"     ' Base Interrupt System
    INCLUDE "ReEnterPBP.bas"     ' Include if using PBP interrupts
    
    ' Set receive register to receiver enabled
    DEFINE HSER_RCSTA 90h 
    
    ' Set transmit register to transmitter enabled
    DEFINE HSER_TXSTA 20h 
    
    ' Set baud rate
    DEFINE HSER_BAUD 2400
    
    x var byte
    OSCCON=%01111000
    
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler   RX_INT ,  _ToggleLED1,   PBP,  yes
        endm
        INT_CREATE               ; Creates the interrupt processor
    ENDASM
    
    @ INT_ENABLE  RX_INT      
    
    Main:
    @sleep
    @nop
    GOTO Main
    
    '---[RX-Int - interrupt handler]--------------------------------------------------
    ToggleLED1:
    hserin [x]
    hserout ["Hello"]
    @ INT_RETURN
    Last edited by jchandir; - 31st May 2009 at 01:18.

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


    Did you find this post helpful? Yes | No

    Default

    I assume you meant 16F886?

    From the datasheet...
    During Sleep mode, all clocks to the EUSART are
    suspended. Because of this, the Baud Rate Generator
    is inactive and a proper character reception cannot be
    performed.
    You can use the AUTO-WAKE-UP ON BREAK feature of the EUSART, but there are several things to consider.

    Take a look at section 12.3.2 AUTO-WAKE-UP ON BREAK
    <br>
    DT

  40. #400
    Join Date
    Nov 2008
    Posts
    9


    Did you find this post helpful? Yes | No

    Default

    shoot.. i meant 16f688... sorry about my careless mistake.

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

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