PDA

View Full Version : PIC18EXT.BAS Alteration



Rob
- 25th January 2007, 17:11
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:


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

Bruce
- 25th January 2007, 18:03
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.

Darrel Taylor
- 25th January 2007, 20:24
Just remember that the next PBP upgrade will overwrite that file.

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

Rob
- 25th January 2007, 21:58
Cheers for your replies - much appreciated (as always!).

Kind Regards

Rob

rdheiliger
- 6th April 2008, 22:50
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

Darrel Taylor
- 6th April 2008, 22:56
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>

rdheiliger
- 6th April 2008, 22:59
Not using USB, just want to use them as digital inputs, for some flow sensors. Setting UCON = %00000000.

mister_e
- 6th April 2008, 23:01
Code and config fuses will help ;)

rdheiliger
- 6th April 2008, 23:17
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

Darrel Taylor
- 6th April 2008, 23:19
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...
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,

mister_e
- 6th April 2008, 23:43
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.


UCFG.3=1
this way it works.

rdheiliger
- 7th April 2008, 00:22
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

mister_e
- 7th April 2008, 00:38
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 http://www.mister-e.org/Pics/Dodo

rdheiliger
- 7th April 2008, 04:10
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

mister_e
- 7th April 2008, 04:21
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?

rdheiliger
- 7th April 2008, 04:32
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

mister_e
- 7th April 2008, 04:35
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....

mister_e
- 7th April 2008, 05:32
I'm unable to reproduce the issue here...


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.

rdheiliger
- 7th April 2008, 05:51
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

mister_e
- 7th April 2008, 05:55
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 :D

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?

rdheiliger
- 7th April 2008, 15:27
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