The EXT (external) modifier.


Closed Thread
Results 1 to 20 of 20

Hybrid View

  1. #1
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    970


    Did you find this post helpful? Yes | No

    Thumbs up

    Very good treatise on the EXT. Thank you Darrell. This is wonderful as I was trying to work out a convenient way to do structures in PBP. I guess you could consider putting this post in the announcements as a sticky. It is very useful.

    Jerson

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


    Did you find this post helpful? Yes | No

    Default

    Thanks Jerson! Here's some more to chew on.

    Arrays within Arrays

    Along with BYTEs and WORDs, you can have Arrays as part of the "Packet". It's just up to you to make sure that everything fits properly.

    Perhaps you need to send a series of A/D samples along with the previous Packet to a VB program on a PC.
    By Mapping a WORD Array inside the BYTE array, the Sample data automatically becomes part of the Packet.

    This adds a 10 WORD array to the previous Packet. And just for good measure I'll put another BYTE variable after it for a CheckSum.
    Code:
    MyArray  VAR BYTE[29] BANK0
    ASM
    Arg0 = _MyArray          ; word
    Arg1 = _MyArray + 2      ; byte
    Arg2 = _MyArray + 3      ; word
    Arg3 = _MyArray + 5      ; word
    Arg4 = _MyArray + 7      ; byte
    Samples = _MyArray + 8   ; 10 WORD array (20 bytes)
    ChkSUM  = _MyArray + 28
    ENDASM
    
    Arg0    VAR  WORD  EXT
    Arg1    VAR  BYTE  EXT
    Arg2    VAR  WORD  EXT
    Arg3    VAR  WORD  EXT
    Arg4    VAR  BYTE  EXT
    Samples VAR  WORD  EXT   ; 10 WORD array
    ChkSUM  VAR  BYTE  EXT
    Note here that you don't need to specify the array size for the Samples variable. But you do have to leave enough room for it in the array.
    And if you get an "Unable to fit variable ____ in requested bank x" warning, change the BANK0 modifier to BANK1 or another bank that has room.
    The entire array must be in a single bank for this technique to work.

    Now you can just take the A/D samples and store them in the WORD array...(which is really in the MyArray).
    Code:
    FOR X = 0 to 9
        ADCIN  0, Samples(X)
    NEXT X
    Calculate a CheckSum for the whole Packet...
    Code:
    ChkSUM = 0
    FOR X = 0 to 27
        ChkSUM = ChkSUM ^ MyArray(X)
    NEXT X
    And with very little program space used, you have a Complete Packet with 5 WORD or BYTE variables, 10 word sized A/D samples and a checksum for data integrity, ready to send with ...
    Code:
      HSEROUT ["Header", STR MyArray\29]
    And, once again, it's bi-directional. You can receive the Packet of Samples just as easily, with ...
    Code:
    HSERIN [wait("Header"), STR MyArray\29]
    DT

  3. #3
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default Just what the doctor ordered!

    Thanks for your great work on this. I was looking at doing just this type of process.

    I plan to capture a series of equally timed ADCs. This data would eventually be sent to my computer. It will have a time stamp header to indicate the time of the first capture, followed by the series of ADC values, followed by a parity word. It seems you have given me just the tool I need for the task at hand. I can't wait to try it out.
    Have you been shuffling through that pile of scribbled notes on my desk?

    Thanks again for your contribution. I'm quite new to PICs and this forum, but it is clear from the reading I've done so far that you stand out as one of the top shelf folks here. I've learned a lot.

    Steve

    BTW, what about instant interrupts for the 16-bit flavors? My project requires quite a bit of RAM (more than any 14-bit PIC) and I really like what I saw reading through those threads. I even thought about trying to shoehorn them into my 18F4620, but balked. I am still quite the newbie. I know it would teach me a lot to work it out on my own, and I would enjoy the process, but I can't spare the time right now.

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


    Did you find this post helpful? Yes | No

    Default PIC18F2431 feature?

    Just found some erratic results on a 18F2431, the following work
    Code:
            '
            '       Pic Configuration
            '       =================
            ASM         
            __CONFIG _CONFIG1H, _OSC_XT_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
            __CONFIG _CONFIG2L, _PWRTEN_ON_2L & _BOREN_ON_2L & _BORV_45_2L
            __CONFIG _CONFIG2H, _WDTEN_OFF_2H & _WINEN_OFF_2H ;& WDPS_32768_2
            __CONFIG _CONFIG3L, _T1OSCMX_OFF_3L & _HPOL_LOW_3L & _LPOL_HIGH_3L & _PWMPIN_OFF_3L
            __CONFIG _CONFIG3H, _MCLRE_ON_3H
            __CONFIG _CONFIG4L, _LVP_OFF_4L & _DEBUG_OFF_4L
            ENDASM
            DEFINE OSC 4
            
            '
            '       Hardware configuration
            '       ======================
                    '
                    '       I/Os
                    '       ----
                    PORTA = 0
                    LATA = 0
                    PORTB=0
                    LATB = 0
                    PORTC =0
                    LATC = 0
    
                    TRISA = 0
                    TRISB = 0
                    TRISC = 0
                    '
                    '       ADCs
                    '       ----
                    ANSEL0 = 0
                    '
                    '       Timers & pouet pouet
                    '       --------------------
                    T0CON = 0
                    T1CON = 0
                    T5CON = 0
                    CAP1CON=0
                    CAP2CON = 0
                    CAP3CON = 0
                    DFLTCON = %00111010
                    QEICON = 0
                    '        
                    '       MSSP
                    '       ----
                    SSPSTAT = 0
                    SSPCON VAR BYTE EXT
                    SSPCON = 0
    
                    '
                    '       CCP
                    '       ---
                    PTCON0=0
                    PTCON1= %10000000
                    PWMCON0 = %01001111
                    PWMCON1 = %00000001
    
                    PTPERL=$FF
                    PTPERH=$3F
    
                    DTCON = 0
                    OVDCOND= 255
                    OVDCONS=255
                    FLTCONFIG = %00000000
                    SEVTCMPL = 0
                    SEVTCMPH = 0
           
            '   
            '       Software variables
            '       ==================
            DUTY VAR WORD          
            '
            '       Software constants
            '       ==================
            Duty0   VAR WORD
            Duty0 = 16383
            
            '------------------------------< Main program >-----------------------------------
            '
    Start:
                    '   
                    '       Those bellow work 100%
                    '       ----------------------
            FOR DUTY = 0 TO Duty0
                PDC0L=DUTY.LowByte
                PDC0H=DUTY.HighByte
                PAUSEUS 50
                NEXT
            FOR DUTY = 0 TO Duty0
                PDC1L=DUTY.LowByte
                PDC1H=DUTY.HighByte
                PAUSEUS 50
                NEXT
    
            FOR DUTY = 0 TO Duty0
                PDC2L=DUTY.LowByte
                PDC2H=DUTY.HighByte
                PAUSEUS 50
                NEXT
                
            GOTO Start
    while the following work weird, and depending the code overhead, results are different...
    Code:
            '
            '       Pic Configuration
            '       =================
            ASM         
            __CONFIG _CONFIG1H, _OSC_XT_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
            __CONFIG _CONFIG2L, _PWRTEN_ON_2L & _BOREN_ON_2L & _BORV_45_2L
            __CONFIG _CONFIG2H, _WDTEN_OFF_2H & _WINEN_OFF_2H ;& WDPS_32768_2
            __CONFIG _CONFIG3L, _T1OSCMX_OFF_3L & _HPOL_LOW_3L & _LPOL_HIGH_3L & _PWMPIN_OFF_3L
            __CONFIG _CONFIG3H, _MCLRE_ON_3H
            __CONFIG _CONFIG4L, _LVP_OFF_4L & _DEBUG_OFF_4L
            ENDASM
            DEFINE OSC 4 
                            
            '
            '       Hardware configuration
            '       ======================
                    '
                    '       I/Os
                    '       ----
                    PORTA = 0
                    LATA = 0
                    PORTB=0
                    LATB = 0
                    PORTC =0
                    LATC = 0
    
                    TRISA = 0
                    TRISB = 0
                    TRISC = 0
                    '
                    '       ADCs
                    '       ----
                    ANSEL0 = 0
                    '
                    '       Timers & pouet pouet
                    '       --------------------
                    T0CON = 0
                    T1CON = 0
                    T5CON = 0
                    CAP1CON=0
                    CAP2CON = 0
                    CAP3CON = 0
                    DFLTCON = %00111010
                    QEICON = 0
                    '        
                    '       MSSP
                    '       ----
                    SSPSTAT = 0
                    SSPCON VAR BYTE EXT
                    SSPCON = 0
    
                    '
                    '       CCP
                    '       ---
                    PTCON0=0
                    PTCON1= %10000000
                    PWMCON0 = %01001111
                    PWMCON1 = %00000001
    
                    PTPERL=$FF
                    PTPERH=$3F
    
                    DTCON = 0
                    OVDCOND= 255
                    OVDCONS=255
                    FLTCONFIG = %00000000
                    SEVTCMPL = 0
                    SEVTCMPH = 0
           
            '   
            '       Software variables
            '       ==================
            ASM
    PDC0REG=PDC0L
    PDC1REG=PDC1L
    PDC2REG=PDC2L
            ENDASM       
            PDC0REG VAR WORD EXT
            PDC1REG VAR WORD EXT
            PDC2REG VAR WORD EXT  
    
            DUTY VAR WORD          
            '
            '       Software constants
            '       ==================
            Duty0   VAR WORD
            Duty0 = 16383
            
            '------------------------------< Main program >-----------------------------------
            '
    Start:
            FOR DUTY = 0 TO Duty0
                PDC0REG=DUTY
                PAUSEUS 50
                NEXT
    
            FOR DUTY = 0 TO Duty0
                PDC1REG=DUTY
                PAUSEUS 50
                NEXT
    
            FOR DUTY = 0 TO Duty0
                PDC2REG=DUTY        ' wierd stuff :o(
                PAUSEUS 50
                NEXT                
            GOTO Start
    When i say weird, PDC2 PWM duty cycle seems to be affected.. work or not, blink and so on.

    Any idea?
    Steve

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

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


    Did you find this post helpful? Yes | No

    Default

    a LITTLE results report
    ==============================================
    DUTY =402
    DUMMY_H =01 DUMMY_L = 91
    PDC2_H =00 PDC2_L = 92
    ==============================================
    DUTY =403
    DUMMY_H =01 DUMMY_L = 92
    PDC2_H =00 PDC2_L = 93
    ==============================================
    DUTY =404

    DUMMY_H =01 DUMMY_L = 93
    PDC2_H =00 PDC2_L = 94
    ==============================================
    DUTY =405
    DUMMY_H =01 DUMMY_L = 94
    PDC2_H =00 PDC2_L = 95
    ==============================================
    DUTY =406
    DUMMY_H =01 DUMMY_L = 95
    PDC2_H =00 PDC2_L = 96
    ==============================================
    DUTY =407
    DUMMY_H =01 DUMMY_L = 96
    PDC2_H =00 PDC2_L = 97
    ==============================================
    DUTY =408
    DUMMY_H =01 DUMMY_L = 97
    PDC2_H =00 PDC2_L = 98
    ==============================================
    DUTY =409
    DUMMY_H =01 DUMMY_L = 98
    PDC2_H =00 PDC2_L = 99
    ==============================================
    DUTY =410
    DUMMY_H =01 DUMMY_L = 99
    PDC2_H =00 PDC2_L = 9A
    ==============================================
    DUTY =411
    DUMMY_H =01 DUMMY_L = 9A
    PDC2_H =00 PDC2_L = 9B
    ==============================================
    DUTY =412
    DUMMY_H =01 DUMMY_L = 9B
    PDC2_H =00 PDC2_L = 9C
    ==============================================
    as this happen on PDC2, i use the following to produce the above report
    Code:
    Start:
            FOR DUTY = 0 TO duty0
                PDC0reg=duty
                pauseus 50
                NEXT
    
            FOR DUTY = 0 TO duty0
                pdc1reg=duty
                pauseus 50
                NEXT
    
            FOR DUTY = 0 TO duty0
                pdc2reg=duty        ' wierd stuff :o(
                pauseus 50
                DUMMY=PDC2REG
                HSEROUT ["DUTY    =", DEC DUTY,13,10,_
                         "DUMMY_H =", HEX2 DUMMY.HIGHBYTE,"    DUMMY_L = ",HEX2 DUMMY.LOWBYTE, 13,10,_
                         "PDC2_H  =", HEX2 PDC2H         ,"    PDC2_L  = ",HEX2 PDC2L,13,10,_
                         "==============================================",13,10]
    
                NEXT                
            GoTo Start
    seems to don't pass the Highbyte eh!
    Steve

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

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


    Did you find this post helpful? Yes | No

    Default

    Yes, weirdness indeed.

    But the weirdness is why Microchip can't seem to keep things consistant between their products.

    In the case of PDCxH:L, the HighByte comes first.

    But in most other registers like TMRxL:H, the LowByte comes first.

    So unfortunately, PDCxH:L, CAPxBUF and probably others won't work with the EXT type variables.

    HTH,
    DT

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


    Did you find this post helpful? Yes | No

    Default

    aaaaahhhh.. cr... and the RTFM datasheet section 5 of the day goes to me...

    sorry
    Steve

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

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


    Did you find this post helpful? Yes | No

    Default

    No, that's good info to have in this thread.

    Until now, I didn't know it either.

    Gotta ask questions.

    DT

Similar Threads

  1. Replies: 1
    Last Post: - 28th January 2010, 23:15
  2. TMR1 external LP xtal setup check
    By comwarrior in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 13th October 2009, 19:11
  3. How to use an external oscillator
    By Mugelpower in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 5th February 2008, 15:19
  4. External clock
    By Firegod in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 17th March 2007, 01:53
  5. switching external vref+ and vdd vref
    By alejandro_halon in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 16th February 2005, 21:13

Members who have read this thread : 2

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

Posting Permissions

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