PDA

View Full Version : 16F648A Pin 0 and 1



Dwayne
- 4th June 2004, 16:11
Hello Folks,

What does it take to make Pins A0 and A1 input pins on the 648A? A friend of mine and I have been working on this, and we both cannot figure it out.
We have trisa=%00000011

we have tried various values od ADCom setting to 7 etc.

Thanks in advance

Dwayne

picnaut
- 4th June 2004, 18:23
Hi,

This may be a configuration fuse issue at program time.

In any case, why don't you post your fuse settings and your code so we can see exactly what you're doing.

Also, if cost is not too much of an issue (and your PCB hasn't been spun already), I'd recommend the PIC16F88 instead of the PIC16F648.

Cheers!

Melanie
- 4th June 2004, 18:49
ADCom????

You found some secret register in this PIC that Microchip's not told us about?

As is usual with PIC's that have Comparators, you need to switch them OFF and turn those ports Digital... see Datasheet section 10.0...

CMCON=7

esp figure 10.1 on Page 62.

Thereafter, don't forget TRISA=%00000011 too...

Melanie

Dwayne
- 4th June 2004, 21:40
Hello Melanie and Picnaut,


Melanie>>ADCom????

You found some secret register in this PIC that Microchip's not told us about?<<

Lets face it... at 3 Oclock in the morning, 8 hours later, I can dream up anything that doesn't work <chuckle>. Along with the inability to type and comprehend what I type!... I think it is called morning sickness... but since I am a male...It seems I was lacking in smarts as well as sleep...<g>

Melanie >>As is usual with PIC's that have Comparators, you need to switch them OFF and turn those ports Digital... see Datasheet section 10.0...

CMCON=7
<<

THATS IT! <g> CMCom not ADCom... We tried that.

Thereafter, don't forget TRISA=%00000011 too...

I will try to post some code... Since I am at work, I have no code to post this minute...but I am retrieving it from a friend now..<g>

Got it now... Here is the Code. Thanks a million in advance.


Dwayne


' Run on Pic 628/648a Serial in on PortA.1, Parallel out to LCD on B

Comd VAR BYTE '1 if next byte command for lcd, else zero
DataByte VAR BYTE 'data or command for lcd
Counter VAR BYTE 'counts incoming bytes

TRISA = $02 'input on porta.1
TRISB = $00 'all outputs
CMCON = $07 'shut off analog comparators

InitLCD:
DataByte = 13 'Turn on LCD
GoSub ComWrite

ReadLoop:
If PORTA.1 = 0 Then GoTo ReadLoop
'stay in loop until incoming data
'**stays in this loop forever. Can you tell me why?**

PORTA.0 = 1 'check timing of read
For Counter = 0 TO 7 step 1
PauseUs 500 'Pause to be adjusted until
'reads match incoming data
'try for 1200 baud first
DataByte = DataByte >> 1
DataByte.7 = PORTA.1 'shift serial into data

Next Counter

PORTA.0 = 0 'check timing compare length with
'incoming data stream on scope

IF Comd = 1 Then
GoSub ComWrite
GoTo ReadLoop
EndIF

IF DataByte = $FE Then
Comd = 1 'next byte command to LCD
GoTo ReadLoop
EndIF

DataWrite:
PORTB = DataByte
PORTA = $0C 'Enable on porta.3, command/data a.2
PauseUs 5
PORTA = $04
GoTo ReadLoop

ComWrite: 'sub writes a command to LCD
PORTB = DataByte
PORTA = $08
Comd = 0
PauseUs 5
PORTA = 0
Return

Melanie
- 5th June 2004, 16:05
Might seem like silly questions, but (1) have you checked that your Input pin is actually swinging Hi/Lo... (0-5v) does it need a pull-up/down Resistor? (2) Are you wired to the correct pin? (3) Is the pin shorting out against an adjacent pin?

I generally set the Ports digital, THEN set Port I/O directions... here's a little ditty that you can use to check if your Port is actually getting data... just needs an LED (with the obligatory Series Resistor) somewhere...

LED var PortB.0
InputPin var PortA.1

CMCON=7
TRISA=3
TRISB=0

Pause 500
Loop:
If InputPin=1 then
High LED
else
Low LED
endif
Goto Loop
End

Melanie

Dwayne
- 7th June 2004, 18:18
Hello Melanie,

Melanie >>Might seem like silly questions, but (1) have you checked that your Input pin is actually swinging Hi/Lo... (0-5v) does it need a pull-up/down Resistor? (2) Are you wired to the correct pin? (3) Is the pin shorting out against an adjacent pin?

I generally set the Ports digital, THEN set Port I/O <<

In this field... Nothing is silly IMO! <g>

Yes, we have checked, and the input is doing a very nice HI/LOW 5 volt swing. We checked shorting to other pins... no luck..But we thought about it for the kicks <g>. We were also verified correct pin too.

Thanks a million for the excellent suggestions.

Dwayne

Melanie
- 7th June 2004, 18:43
Well, if you've got a 0-5v swing on the correct pin, then you know your external environment is OK. My blinky LED code will check if the PIC is working and you've not got a blown pin.

The 648 is basically a 4K version of the 628. There's nothing mysterious about it. CMCON and TRISA are the controlling factors for PORTA.

Strip your code down to the basics, you could have something setting the ports to output without even realising... Example... Instead of MyVar=PortA, putting PortA=MyVar can really ruin your day and you end up looking for phantom bugs for the next week because you can't see what you've done.

languer
- 7th June 2004, 20:29
Dwayne,

I would try Melanie's trick for a quick sanity check. But aren't you setting the PortA.1 to 0 in various places.

PORTA = $08
PORTA = 0

I do not know if by doing this you reset the port to be an output but you may want to look at the TRISA register (MPLAB or Listing) after you manipulate it as above.

Just a thought.


Edit:

One more thing, since you're not using interrupts but are sampling the input (if it turns out to be an input) you could have a case where the sampling is synchronized to zeros on your serial input. I explain myself, if both TX and RX are at the same rate there is a chance this may happen. If the TX is running much faster than the RX there is a better chance this will happen (actually you have less of a chance of properly sampling on the clock edge, but that's a different story).

Melanie
- 8th June 2004, 08:55
Yes, you do set the Port to Output by performing an Output operation on it. Just as I said in my last posting... it can really ruin your day if you're not paying attention.

Dwayne
- 8th June 2004, 15:28
Hello Languer,


Thanks Languer and Melanie again..


Languer >>I would try Melanie's trick for a quick sanity check. But aren't you setting the PortA.1 to 0 in various places.

PORTA = $08
PORTA = 0<<

Yes, We wanted to make darn sure the PortA.0 is actually a value of Zero.

We aslo ran into a problem a while back (a few months for a guess), of Port and and its assignment. If we assigned the entire port a to a value, our program worked, but if we assigned just the pin, it would not work. We never did figure that one out <g>... So we tried assigning the port a two different ways and intermixing them <chucke>... That is why you see the entire porta assigned a hex value, and the port a.0 a off/low switch.

I guess you can say we were grasping for straws <g>. I think we will try melanies suggestion again, but do it with totally new code. Since there really isn't much in the code anyhow! <g>.


Languer>>
One more thing, since you're not using interrupts but are sampling the input (if it turns out to be an input) you could have a case where the sampling is synchronized to zeros on your serial input. I explain myself, if both TX and RX are at the same rate there is a chance this may happen. If the TX is running much faster than the RX there is a better chance this will happen (actually you have less of a chance of properly sampling on the clock edge, but that's a different story).<<

Thanks!... We have'n't got it to go past that edge (or into that area yet <g>. But this is a good thing to keep in mind.

Dwayne

languer
- 9th June 2004, 09:14
Dwayne,

I read your previous post on having to set the whole port and not individual bits. I do not know why you can not achieve this (maybe Melanie can chime in on this). But since you got some of it working, what would happen if you duplicate,


TRISA = $02

at the beginning of the ReadLoop: sub. Or better yet at the end of the ComWrite: sub (so the code only gets executed then and not everytime the read loop gets called).

Melanie
- 9th June 2004, 16:25
You should NEVER do whole Port operations that affect an entire Port when that Port has mixed I/O on it. That's just bad programming - so don't do it. You end up switching Inputs into Outputs and vice versa. PIC Inputs for example are normally high impedance, setting them to Output for example, shorts out their feed signals or worse applies voltages upstream into those circuits that shouldn't have voltages applied directly into their outputs.