PIC18EXT.BAS Alteration


Closed Thread
Results 1 to 21 of 21
  1. #1
    Join Date
    Feb 2005
    Location
    Essex, UK
    Posts
    94

    Question PIC18EXT.BAS Alteration

    Hi,

    I need access to the UCON register (USB Control Register) so that I can disable the USB port in an 18F4550.

    I have added the line:

    Code:
    UCON    var byte EXT
    into the PIC18EXT.BAS file and this seems to have done the trick.

    Is this the correct way to have done this or should I not have touched this file at all?

    Thanks very much

    Rob
    Last edited by Rob; - 25th January 2007 at 17:15. Reason: Needed to enclose code in correct fashion

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


    Did you find this post helpful? Yes | No

    Default

    Hi Rob,

    You can add whatever external register definitions you like to this file. That's
    how I add any that aren't already in there.
    Regards,

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

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


    Did you find this post helpful? Yes | No

    Default

    Just remember that the next PBP upgrade will overwrite that file.

    Keep track of what you've changed.
    <br>
    DT

  4. #4
    Join Date
    Feb 2005
    Location
    Essex, UK
    Posts
    94


    Did you find this post helpful? Yes | No

    Talking Thanks!

    Cheers for your replies - much appreciated (as always!).

    Kind Regards

    Rob

  5. #5
    Join Date
    Apr 2008
    Posts
    10


    Did you find this post helpful? Yes | No

    Default 18F2455 PortC.4 & 5 as input

    I added the definition of UCON to the PIC18EXT.BAS file. Which eliminates the compile error. But the PortC.4 and 5 when read with either a high or low applied read zero. What else do i need to do to use these ports as input.

    RD

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


    Did you find this post helpful? Yes | No

    Default

    Adding UCON implies that you are using USB.

    PORTC.4, PORTC.5 are the USB D+/D- pins, so you won't be able to use them as digital I/O at the same time as USB.
    <br>
    DT

  7. #7
    Join Date
    Apr 2008
    Posts
    10


    Did you find this post helpful? Yes | No

    Default Digital inputs

    Not using USB, just want to use them as digital inputs, for some flow sensors. Setting UCON = %00000000.

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


    Did you find this post helpful? Yes | No

    Default

    Code and config fuses will help
    Steve

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

  9. #9
    Join Date
    Apr 2008
    Posts
    10


    Did you find this post helpful? Yes | No

    Default Config Settings for non-USB

    The only config setting i see that affects USB is VREGEN. Does this have to be off for the USB to be disabled. From what i read in the data sheet only UCON.3 needs to be turned off to change PortC.4 & 5 to digital.

    I am using Micro Code Studios boot loader, do you know if they preset bits in the config to enable USB?

    RD

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


    Did you find this post helpful? Yes | No

    Default

    If you were getting compile errors regarding UCON, then the USB library is probably being included without you realizing it. Your program most likely compiles to a size that seems much larger than it should.

    If the file you are compiling is in the same folder as another USB project, then the USB library may be included automatically.

    Or if the 18F2455.bas in the PBP folder has been modified for USB it will do the same thing from any folder.

    If it is in the same folder as another USB project? Move it to it's own separate folder.

    If it's already in it's own folder? Check the 18F2455.bas file in the PBP folder. You should see this in the file...
    Code:
    BANKA   $0000, $005F
    BANK0   $0060, $00FF
    BANK1   $0100, $01FF
    BANK2   $0200, $02FF
    BANK3   $0300, $03FF
    BANK4   $0400, $04FF
    BANK5   $0500, $05FF
    BANK6   $0600, $06FF
    BANK7   $0700, $07FF
    'EEPROM  $F00000, $F000FF
    LIBRARY "PBPPIC18"
    'LIBRARY "PBPUSB18"
    The PBPPIC18 line should NOT be commented, and the PBPUSB18 line should be commented.

    If you are using PBPL, then look in the 18F2455.BAL file instead.

    hth,
    DT

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by rdheiliger View Post
    The only config setting i see that affects USB is VREGEN. Does this have to be off for the USB to be disabled. From what i read in the data sheet only UCON.3 needs to be turned off to change PortC.4 & 5 to digital.

    I am using Micro Code Studios boot loader, do you know if they preset bits in the config to enable USB?

    RD
    Seems the loader enable it... but it's not the problem... you also have to set the UCFG register to Disable the On-Chip Transceiver.

    Code:
    UCFG.3=1
    this way it works.
    Steve

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

  12. #12
    Join Date
    Apr 2008
    Posts
    10


    Did you find this post helpful? Yes | No

    Thumbs up Ucfg.3=1 And Ucon.3=0 Works

    Thank You!!

    Adding both

    UCON var byte EXT
    UCFG var byte EXT

    to PIC18EXT.BAS

    and adding

    UCFG.3=1
    UCON.3=0

    to the code lets PortC.4 and PortC.5 on the 18F2455 operate as inputs.


    Now i can sleep tonight!!!!!!!!!!!!!

    RD

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


    Did you find this post helpful? Yes | No

    Default

    Actually UCON=0 at power up, so you shouldn't need that line... but who knows... it's never a bad idea to set all registers.

    Good night
    Last edited by mister_e; - 7th April 2008 at 00:41.
    Steve

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

  14. #14
    Join Date
    Apr 2008
    Posts
    10


    Did you find this post helpful? Yes | No

    Default Input Cross Talk

    Couldn't go to bed before i hooked up the pulse inputs.

    When i hook up the pulse input to PortC.5 i get pulses on PortC.5 and not on PortC.4.

    When i hook up the pulse input to PortC.4 i get counts on PortC.4 and PortC.5 as well.

    The traces are paralell for awhile but if i was getting cross talk between traces i would think it would be in both directions. But its not. I can eliminate everything in the program that refers to PortC.4, put pulses into PortC.4 and still get pulses on PortC.5. There are no shorts between the traces or anything else on the board. It appears to be internal to the ports.

    I did notice that these two ports do not have smitt triggers as most other inputs do. Can this have some thing to do with it.

    Also there are internal pullups on these two inputs. I supposedly disabled them by setting UCFG.4 to 0 as well.

    My pulse input is from a hall effect switch with a 1K pull up resistor.

    Any thoughts????

    RD

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


    Did you find this post helpful? Yes | No

    Default

    Weird... work perfectly here with 10K external pull-up (EasyPIC 4) but push-buttons... big deal... While i'm still awake, could you post your code so i can test it here?

    Maybe not a bad idea to start a new thread as it's a out of topic from the original.

    PS: for your tests.. did you left one or the other pin floating or you had a pull-up attach to?
    Last edited by mister_e; - 7th April 2008 at 04:26.
    Steve

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

  16. #16
    Join Date
    Apr 2008
    Posts
    10


    Did you find this post helpful? Yes | No

    Default pulse in code

    this is part of a pretty large program.

    the code for the alias'

    SCLK var PortC.0
    ColPump var PortC.1
    RadPump var PortC.2
    RadFlowInput var PortC.4
    ColFlowInput var PortC.5
    SerRecieve var PortC.6
    SerTransmit var PortC.7

    this is the code to read pulse width:

    gosub checksw
    if colflocal > 0 then 'if have a calibration number, read the collector sensor
    pulsin colflowinput,0,colflo
    colfloacc = colfloacc + colflo
    endif
    gosub checksw
    if radflocal > 0 then 'if have a calibration number, read the radiant heat sensor
    pulsin radflowinput,0,radflo
    radfloacc = radfloacc + radflo
    endif
    gosub checksw

    i am averageing over 10 scans then writing the colflowacc and radfloacc to an lcd

    don't stay up too late.

    RD

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


    Did you find this post helpful? Yes | No

    Default

    in meantime try something,
    1 reload the BootLoader firmware and disable the USB voltage generator config fuse,
    2 load it in your PIC and dump your program in ...
    3 see if it change anything...

    Also try on another set of pin... i may think of few thing when using PULSIN on those specific pin....
    Last edited by mister_e; - 7th April 2008 at 04:44.
    Steve

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

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


    Did you find this post helpful? Yes | No

    Default

    I'm unable to reproduce the issue here...
    Code:
            RadFlowInput var PortC.4
            ColFlowInput var PortC.5
    
            ColFlow var word
            RadFlow var word
    
            pause 500
            hserout ["Testing...",13,10]                
    
    start:        
            pulsin colflowinput,0,colfloW
            pulsin radflowinput,0,radfloW
              
    
            hserout ["    PORTC.4=",DEC rADFLOW,_
                     "    PORTC.5=",DEC cOLFLOW,13,10]
    
            GOTO START
    Seems to be a hardware problem... if you have any schematic and part#, that would be handy.
    Steve

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

  19. #19
    Join Date
    Apr 2008
    Posts
    10


    Did you find this post helpful? Yes | No

    Default Hardware

    I did try turning off the USB voltage. Same result.

    I was leaving PortC.5 floating when running the pulses into PortC.4 and vice versa. By tying PortC.5 low or high thru a 1K resistor the problem does go away. Interesting that i don't have to tie PortC.4 low when putting pulses into PortC.5.

    Will get another pulse input set up tomorow and see if the problem goes away.

    I am using a water flow sensor that counts pulses of a magnetic rotor passing a hall effect switch. Am blowing air thru the sensor to test. Am assuming you are using a push button??

    The board is my own design. It is intended as a solar collector control and monitor. This is about the last bug to have it all working.

    Will let you know tomorow, if having both sensors connected works.


    Thanks for the help!!

    RD

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


    Did you find this post helpful? Yes | No

    Default Great!

    Your welcome! you could still use HPWM for your tests... this one have 2 channel.. just play with duty cycle and hop.. you're in business.

    I also tried to left a pin floating but didn't had any problem.. must be because i use a development board and not a breadboard

    But... on the other side, i don't see your full code, maybe somewhere you write to PORTC.x and it cause some "extra noise". BTW if you want to write to a single pin, consider LATx register instead of PORTx. Maybe you already know it?
    Last edited by mister_e; - 7th April 2008 at 05:59.
    Steve

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

  21. #21
    Join Date
    Apr 2008
    Posts
    10


    Did you find this post helpful? Yes | No

    Default Both sensors

    Hooked up both pulse sensors this morning. No crosstalk. Will have to see if i can sqeeze in a ground trace between the two pulse traces on the next board evolution.

    Thanks again, the USB settup on these chips is more than a bit confusing.

    RD

Similar Threads

  1. Elapsed_Int-18 Alteration
    By Rob in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 31st January 2008, 11:51

Members who have read this thread : 0

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