PDA

View Full Version : portA.0 cannot be set



hkpatrice
- 29th June 2011, 11:07
Dear Friends,

I am experiencing a very frustating situation and I am hoping someone can help me solve this problem.

I have been using Pics for almost 10 years, now, but this problem baffles me. I am using a pic18F8722, and I cannot set porta.o using the following statement: porta.0=1 or porta.0=0. In either cases, it remains high. The tris setting configures it as an output (trisa=0), and all other bits on the port work fine (excluding a.4 of course, which is open-collector).

However, I can set the pin by using HIGH porta.0 or LOW porta.0.

I have been trying to figure out the reason behind this for 3 days now, but I give up. I have found a work around by using select case in the following way:

dummy= state of the pin I want to set
select case dummy
case 0
low porta.0
case 1
high porta.0
end select

It works, but it is not very elegant...

even this small program does not work:

trisa=0
main:
porta.0=0
porta.1=0
pause 10
porta.0=1
porta.1=1
pause 10
goto main

when I check the pins with my scope, I see a nice square wave on porta.1, but port a.0 stays high.

If I change the program to:


trisa=0
main:
low porta.0
porta.1=0
pause 10
high porta.0
porta.1=1
pause 10
goto main

Then I see a square wave on both pins.

My question is: what is the difference between the code generated with

porta.0=1
and
high porta.0

why is one expression working and not the other one?

(by the way, yes, the fuses are properly set, ADCON1=%00000111 to set the outputs as digital, A/D module disabled, etc...)


I appreciate your help.

Best regards,

Patrice

HenrikOlsson
- 29th June 2011, 11:20
Do you have the pins connected to anything? It smells like the good old Read-Modify-Write problem...

What if you try:

trisa=0
main:
porta.0=0
Pause 1 'Allow PortA.0 to settle low.
porta.1=0
pause 10
porta.0=1 'Allow PortA.0 to settle high
Pause 1
porta.1=1
pause 10
goto main

HIGH and LOW also resets the corresponding bit in the TRIS register (making the pin output) for you so even if you have the pin setup as an input doing HIGH PortX.x will switch it to an ouptut and set it high. I'm not sure WHY it matters in THIS case but we can figure that out IF it turns out to BE a RMW-problem.

/Henrik.

mackrackit
- 29th June 2011, 12:24
You will need to turn the ADC off.
ADCON1 = 15

hkpatrice
- 5th July 2011, 09:38
Henrik,

It was a read-write-modify issue.
a simple PAUSEUS 1 between instructions solved it.
Thanks!

Acetronics2
- 5th July 2011, 10:56
Bonjour Patrice,

Or simply Write " HIGH or LOW PortA.0 " ... it will automatically add a little time ... ( equal to TRISA.0 = 0 ... )

hé,hé ... soyons flemmards !!!

Alain

hkpatrice
- 6th July 2011, 01:14
Bonjour Alain,

You are right, I had noticed that writing "high" or "Low" indeed worked as well.
This is the first time I design a project running at 40 Mhz, so I am dealing with new issues I have not seen before.

You learn every day!

A+

Pat

mister_e
- 6th July 2011, 01:49
Salut Patrice,

With PIC18, there's LAT port made to avoid this problem

You write to LAT ... but read from PORT
LATA.0=1
LATA.1=1
LATA.2=1
LATA.3=1