PDA

View Full Version : Port 'a' problems



Robotica1
- 14th July 2007, 13:55
I am writing a very simple (theoretically) string of code to flash some LED's in a variety of patterns on a 12 segment bar graph. I am using a 16f628a. Port b outputs are a ok and working a treat. As you can see by lines 4 & 5 I have set my 'a' ports as standard I/O (or so I thought). However whenever I try to set two 'a' ports high at the same time only one will go high.

Does anyone know how to make the 'a' ports on a 16f628a act like normal old good old 84a I/O ports.

I have attached the code and a pinout for the Bargraph. Please ignore the fact that the first loop excludes any following code from being run--this loop is a late edition for debugging only.

mackrackit
- 14th July 2007, 14:06
http://www.picbasic.co.uk/forum/showthread.php?t=562

http://www.picbasic.co.uk/forum/showthread.php?t=561

These are from the FAQ - Frequently Asked Questions section, read them and see if it helps. Basically You will need to MAKE the pins NORMAL.

If you still have problems let us know.

mister_e
- 14th July 2007, 14:07
first thing to understand why it doesn't work, is to open the datasheet and look what the 628 have that the 84 don't.

Now you discover that the F628 it have analog comparator on PORTA. WOOOOHOOO, but it doesn't solve the problem yet.

Before using those pins as regular i/o, you need to set them as digital.

Find the Analog comparator section in the datasheet, and look the CMCON settings.

Now you understand that you'll need to use...

CMCON=7
at the top of your code.

HTH

EDIT: oups, i'm late ;)

Robotica1
- 14th July 2007, 14:13
Thanks for the help but no joy. I already knew about the port 'a' comparator story.. hence lines 4&5 of my code

movlw 7
movwf CMCON

I understand that as having the same effect as CMCON=7 (I even tried changing a couple of nights ago just to check). As long as only one port needs to be high there is no problem it is only when two or more want to be high simultaneously??? I am really frustrated as this was for a birthday present which is kind of due tomorrow??

mackrackit
- 14th July 2007, 14:16
Hey, you got attachments!!

The
movlw 7

movwf CMCON
is assembly. if you are going to write it that way you need to let the program know .


ASM
movlw 7

movwf CMCON
ENDASM

mister_e
- 14th July 2007, 14:18
can you post your whole code here?

If you do it in asm, make sure you're in the right BANK first.. unless, you may have no joy at all. BANKSEL comes handy... IN 100% ASM ONLY. If you're using a mix of PBP and assembler, you NEED to use
CHK?RP CMCON

instead of BANKSEL.

HEY, wait a minute... the code you posted in your first post is not PBP, but something close to ASM and BASIC??? What is it?

Sure it's based on Skimask's wishes :D

mackrackit
- 14th July 2007, 14:21
Mister_E,
Look at the first post. Attachments are there now.

Robotica1
- 14th July 2007, 14:25
That's the only assembly routine I have in the code. It's all attached but if you need I'll include in the body of a post. Yeah Dave :) (Don't know what was happening there with attachments...thanks again). Anyway I tried CMCON=7 and CMCON=%00000111. When the code hits "high l9:high l11:pause 3:"..l9 flashes (almost imperceptibly) then l11 goes high. When it gets to the next section ('High l10:low l11:high l12) then l10 goes high and l12 does nothing!!

mister_e
- 14th July 2007, 14:28
what happen if you remove all those colon in your code???

Pause 3, seems really fast so far... 300 could be more interesting.

Not sure of those multiple...


RETURN
END

L12 refer to RA.4, and it's an open drain type. You can't drive a LED as you wish. At least, you could drive it if it's connected between Vdd, and the PIC, not between GND and PIC

Robotica1
- 14th July 2007, 14:35
I have a pause of 3 because I am using an external clock signal from a 555 astable with an adjustable (low) frequency ( so that the flash rate is adjustable). It is definately a visible speed. The colons are there because I had each sequence on it's own line earlier. I split the lines and left the colon's because I read something last night in an old post by ski-mask discussing something along these lines. I just recoded without the colons as I'm typing this and nothing changed at all.

mackrackit
- 14th July 2007, 14:42
What Mister_E said about RA.4 might be it -- or -- Looking at the two attachments it might be a combination of code and hardware. In the code I do not see a complimentary pin all of the time.

I made this up for some hide I work with, it explains what I am getting at.
http://mackrackit.com/mac/www/dave/LED/LEDs.html

mister_e
- 14th July 2007, 14:48
I don't understand why it shouldn't work unless you have an hardware problem OR a bad configuration fuse setting.....

what happen with that one???


@ __CONFIG _INTRC_OSC_NOCLKOUT & _MCLRE_OFF & _LVP_OFF & _WDT_OFF & _PWRTE_ON & _BODEN_ON
'
' or use the one bellow if you use PM assembler
' @ device pic16F628A, intrc_osc, wdt_on, mclr_on, lvp_off, protect_off
PORTB = 0
PORTA = 0
TRISB = 0
TRISA = 0
CMCON = 7

START:
PORTA = 255
PORTB = 255
PAUSE 200
PORTA = 0
PORTB = 0
PAUSE 200
GOTO START

but yeah... pure assumption, no schematic available, and i need more cofee :D

Robotica1
- 14th July 2007, 14:51
Sorry, forgot to fix that...I only did that as another debug...original code was


symbol l9= porta.0
symbol l10= porta.1
symbol l11= porta.2
symbol l12= porta.3

I reallocated to see if it was a problem with ra0 as it was the original playup pin. I have now set it back!! As far as some complimentary others not etc. If you look at the LED setup for the Bargraph hardware some (ie l1, l4, l9 and l12) are standalone LEDs whereas (l2,l3...l5,l6...l7,l8...and l10,l11) are wired in sequence. This means if I want to light LED 1 I send l1 high. If I want to light LED 2 I have to send l2 high and l3 low etc.

mackrackit
- 14th July 2007, 14:59
This means if I want to light LED 1 I send l1 high. If I want to light LED 2 I have to send l2 high and l3 low etc.

Right, but

When the code hits "high l9:high l11ause 3:"..l9 flashes (almost imperceptibly) then l11 goes high. When it gets to the next section ('High l10:low l11:high l12) then l10 goes high and l12 does nothing!!



high l9:high l11:pause 3:

low l9:low l11

high l10:low l11:high l12:pause 3:

low l10:low l12
But something does not look right in the above.

mister_e
- 14th July 2007, 15:17
Possible to have a schematic? Picture worth thousands words ;)

an yup, i feel it could be done in few code lines. i bet on 50% reduction here, maybe more...