Single bit to port A4 on 16F628A - HOW

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
daveb0360
Posts: 139
Joined: Mon Sep 21, 2009 10:17 am
Location: Leicester
Has thanked: 35 times
Been thanked: 12 times

Single bit to port A4 on 16F628A - HOW

Post by daveb0360 »

Hi,
Can anyone suggest how I output a hi or lo signal to port A4 on a pic16F628A please?
I have attached an LED to this port and need the code to switch it on or off at various points in the program........in fact it's not an led but an npn transistor base drive but the principal is the same.
I have tried the program on Bit A7 and it works no problem but the PCB's are made now and I need to use A4
I am currently using A0 as input from a switch or trigger signal.....this works fine. A1 and A2 are direct LED drives which also work fine. A3 is the Anode drive via transistor for a 7 seg display and that is fine also. I just can't get A4 to be an output. I have tried another chip which gives the same result so am ruling damage out. I have tried masking, not masking on inputs and outputs etc and nothing lights this led. I have it connected for active high via a 220R resistor to ground. If I connect to +V to A4 (reversed of course), it lights continuously which tells me the port bit is not being toggled within the program - it's permanently LO.

I have attached my code if anyone would like to see what this dimwit has done......or missed.

Thanks in advance
Attachments
DMUFinal1.fcf
(11.5 KiB) Downloaded 301 times

User avatar
Steve
Matrix Staff
Posts: 3434
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times

Re: Single bit to port A4 on 16F628A - HOW

Post by Steve »

I think A4 is an open-drain output on that device and needs a pull-up resistor.

Sean
Valued Contributor
Valued Contributor
Posts: 548
Joined: Tue Jun 26, 2007 11:23 am
Has thanked: 6 times
Been thanked: 44 times

Re: Single bit to port A4 on 16F628A - HOW

Post by Sean »

Hello,

The RA4 pin on the PIC16F628A (and many other PIC devices) has the alternative function of TOCKI. For this reason the normal output driver is not included and only a low side transistor is available. This means that the RA4 output can only actively pull low.
An LED driven from this port pin should be supplied from the positive supply rail, with the control logic adjusted to match this polarity.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Single bit to port A4 on 16F628A - HOW

Post by Benj »

Yes Steve is correct you can either use a pull up resistor on that pin to allow it to source current or you can make the LED active low and wire it in from the VDD line via the 200R resistor and into the output pin.

daveb0360
Posts: 139
Joined: Mon Sep 21, 2009 10:17 am
Location: Leicester
Has thanked: 35 times
Been thanked: 12 times

Re: Single bit to port A4 on 16F628A - HOW

Post by daveb0360 »

Aha........I knew there had to be a reason.....thanks guys, this doesn't present a problem other than a small mod to the PCB. I havn't defined the output polarity of our signal in the documentation yet so easy to work around. Experience counts it seems!
Cheers again
Dave

daveb0360
Posts: 139
Joined: Mon Sep 21, 2009 10:17 am
Location: Leicester
Has thanked: 35 times
Been thanked: 12 times

Re: Single bit to port A4 on 16F628A - HOW

Post by daveb0360 »

Hi Again,
Despite the code simulating correctly, I tried everything suggested on the hardware including pullup resistor but the output only blinked the LED for a few milliseconds when I pushed the trigger button so have modded the code and the board to use A7 instead which works fine so another lesson learned is not to use A4 for any critical signals it would seem.
Of course, it could be my code but tried various mods such as using masking on output and on my single input but nothing worked, I just couldn't get the led to do anything other than blink the few milliseconds.
Not to worry, the prototype is exactly that..........a prototype and, of course, we prototype for exactly this purpose.......wringing out any flaws before production.

At least Flowcode is working now and I am not tearing my hair out.
Strange thing is, when MS DEP is triggered by a suspect file, it is supposed to flag the event but didn't.....strange but expected with Microsoft I suppose.
Nevertheless, it might be an idea to include this potential issue in the flowcode documentation I think. In fact, why not include a debug guide that covers all of the issues in the forums.

Whilst I'm here, great thanks to the developers for their support, patience and overall great assistance in helping me sort this problem.....hopefully it won't rear it's ugly head again.
Dave

Post Reply