PDA

View Full Version : Problem with A port on 18F2550



NL2TTL
- 7th May 2007, 14:36
I have a problem with my a port on the 18F2550 device. When i use this code the a port will toggle all the time. What do I wrong.

I have the following code:

Include "modedefs.bas"

Define OSC 20
DEFINE DEBUG_REG PORTC
DEFINE DEBUG_BIT 7
DEFINE DEBUG_BAUD 9600
DEFINE DEBUG_MODE 1

LEDGroen VAR PORTB.7
LEDRood VAR PORTA.2


Relais1 VAR PORTA.5 ' Relaiscontact'

LATA = 0


ADCON1 = 7 'poort a op digitaal
'ADCON1 = 0 'poort a op analoog

ADCON0 = 0
ADCON2 = 0

'CMCON = 7


TRISB.3 = 1 'Input
TRISB.2 = 1 'Input
TRISA.1 = 1 'Input

TRISA = 255


DEFINE ADC_BITS 8 ' Set number of bits in result (8, 10 or 12)
DEFINE ADC_CLOCK 2 ' Set clock source (rc = 3)
DEFINE ADC_SAMPLEUS 50 ' Set sampling time in microseconds

Init:

HIGH LEDGroen
PAUSE 500
LOW LEDGroen
Pause 500
HIGH LEDRood
PAUSE 500
LOW LEDRood
Pause 500
Debug "->Start<-", 13,10

Goto Main


Main:
High Relais1
Goto Main:

skimask
- 7th May 2007, 14:51
I have a problem with my a port on the 18F2550 device. When i use this code the a port will toggle all the time. What do I wrong.
I have the following code:........................


Since your last thread was about 3v3 PICs, I have to ask...
What is your power supply? And are you running a PIC18F2550 or PIC18LF2550?

And what's this line for?
---------Baudrate CON T9600 ' Voor communicatie met RFID-module---------

NL2TTL
- 7th May 2007, 18:20
This is for a other project, it's a normal 5V operation system.
The line where you talk about is not needed.

mister_e
- 7th May 2007, 19:18
make sure that there's no possible Brown-out reset @20MHz and @3 V. Usually the datasheet show the minimum voltage for a given crystal speed.

EDIT: nevermind.. misread your post.

well you'll need to post your Config Fuses line OR send your compiled .HEX files.

Make sure your ADCON setting is good as well.

NL2TTL
- 8th May 2007, 09:29
I Use the following A ports:

Input1 VAR PORTA.0 'input
Relais1 VAR PORTA.5 'output
Data_In VAR PORTA.4 'serial data
LEDRood VAR PORTA.2 'output

I use the following adcon settings:

LATA = 0
ADCON1 = 7 'poort set as digital

ADCON0 = 0
ADCON2 = 0
TRISA.1 = 1 'Input

TRISA = 255

Fuses are set:

http://www.ttalens.com/images/picbasic/fuses1.JPG

skimask
- 8th May 2007, 14:13
Does the ">Start<" go out the serial port about every 2 seconds or so?

NL2TTL
- 8th May 2007, 14:39
This is a one time operation.

skimask
- 8th May 2007, 14:57
This is a one time operation.

I know it's a one time operation. That's the way you've written it in the program.
I'm asking if, while the program is in operation, do you get the ">Start<" out of the serial port about every 2 seconds or so?

NL2TTL
- 8th May 2007, 16:05
Yes every 2 seconds

mister_e
- 8th May 2007, 18:47
Out of curiosity, which PIC programmer do you use?

could you post your compiled .HEX file?

Make sure your MCLR pin is tied to Vcc via a resistor.

Seems to work as design here...

NL2TTL
- 8th May 2007, 19:18
I'm using a ICD2 compiler.

He're is the hex file

mister_e
- 8th May 2007, 19:29
OK i got the same problem here. Are you using the same code as in POST #1 ???

One thing is sure, if i disable the Watchdog timer, it works...

skimask
- 9th May 2007, 06:22
OK i got the same problem here. Are you using the same code as in POST #1 ???

One thing is sure, if i disable the Watchdog timer, it works...

That's why I asked 'Does it show ">Start<" every 2 seconds out the serial port'...
In the picture posted earlier with all the fuses shown, the WDT prescaler is set to 1:128 and Enabled.
(Yesterday when I asked the question about the 2 seconds, I had the math worked out and it came up to about 2 seconds (give or take)...
Tonight when I do the math, I only get 1/2 second...I musta been drunk or something :D )

NL2TTL
- 9th May 2007, 08:17
So you guys say shut down the watchdog timer. How can i do this?
Can this be the reason that a other microprocessor board with same config and same sort of simple program hangs after a few days.

skimask
- 9th May 2007, 08:46
So you guys say shut down the watchdog timer. How can i do this?
Can this be the reason that a other microprocessor board with same config and same sort of simple program hangs after a few days.

1 - Reopen the same program you opened in Post #5 (MPLAB IDE)
2 - Left-Click on the 'Configure' menu
3 - Further click on 'Configuration Bits'
4 - Press the down arrow on your keyboard 10 times
5 - By now you should have '300003 1F Watchdog Timer Enabled' selected
6 - Left-Click on the line that is now highlighted
7 - Left-Click on the drop-down menu that appears
8 - Left-Click on the words 'Disabled-Controlled by SWDTEN bit'

2nd question - it's possible...

Or you could turn up your WDT post-scaler.

mister_e
- 9th May 2007, 13:35
Yeah... but, from what i suppose, PBP have to take care of the watch dog... maybe 2.47 fixed it.

Anyways, i'm doing cofee here, i will try the original code with WatchDog enabled. i think i already did it here... but curiosity...

EDIT:


;----- CONFIG2H Options --------------------------------------------------
_WDT_OFF_2H EQU H'FE' ; HW Disabled - SW Controlled
_WDT_ON_2H EQU H'FF' ; HW Enabled - SW Disabled

interesting

paul borgmeier
- 9th May 2007, 17:32
Why not just add
CLEARWDTinside the tight loop?

skimask
- 9th May 2007, 19:50
So you guys say shut down the watchdog timer. How can i do this?
Can this be the reason that a other microprocessor board with same config and same sort of simple program hangs after a few days.

Find your .lst file for this program. Search for the:

Main:
High Relais1
Goto Main:

block and see if there is a CLEARWDT in the middle of the loop. If not, then do like Paul said and add a CLEARWDT in the middle of the loop in your source file. That should fix it without having to mess with the config settings.
And which version of PBP are you using? Maybe that's got something to do with the problem...

mister_e
- 9th May 2007, 22:59
well.. unless you really want to use the Watch-dog features, just disable it.