PDA

View Full Version : What am I doing wrong? 16F628A



ERMEGM
- 16th January 2014, 16:47
Hi Guys,

It should be pretty straight forward, but I'm at a loss. Trying to use a 16F628A and tried searching online for similar issues, but have been unsuccessful in resolving the matter.

I wrote out a large amount of code. Found that one of the outputs on the PIC wasn't doing what it was suppose to do. To make a long story short, I wrote a small bit of code to test the outputs I wanted to control and it's still not working. I tried programming new chips, and get the same result.

My problem: porta.4 (pin 3) does not want to turn on. It stays low and does not activate to control a transistor. I replaced the transistor (in case it was bad), and get the same result. Can someone tell me what I'm missing.

Thanks,
Tony


#CONFIG
__config _INTRC_OSC_NOCLKOUT & _WDT_ON & _LVP_OFF & _CP_OFF & _PWRTE_ON & _MCLRE_OFF & _BOREN_OFF
#ENDCONFIG

Reset:

CMCON = 7 ' Analog comparators off
VRCON = 0 ' A/D Voltage reference disabled
TRISA = %11000001 ' sets pin as input (1) or output (0)
TRISB = %00110011 ' sets pin as input (1) or output (0)
PORTA = %00000000 ' sets outputs as high (1) or low (0)
PORTB = %00000000 ' sets outputs as high (1) or low (0)

' -----[ Variables ]-------------------------------------------------------

rightrelay var porta.1 ' right relay output
leftrelay var portb.2 ' left relay output

rightfet var porta.4 ' right fet output
leftfet var porta.2 ' left fet output

high leftrelay
high rightrelay

action:

low leftfet
high rightfet

pause 500

low rightfet
high leftfet

pause 500

goto action

aratti
- 16th January 2014, 17:25
PortA.4 is an open drain port. You must use a pullup resistor in order to drive your transistor.

Cheers

Al.

gadelhas
- 16th January 2014, 20:23
Hi;

To complement aratti answer, that information is on the Datasheet.

ERMEGM
- 17th January 2014, 00:47
I'm using an npn, so using a pull-up resistor turns on my transistor. Any other thoughts, or an equivalent chip to the 628A that does not have an open drain output?

Thanks,
Tony

mackrackit
- 17th January 2014, 01:20
Use the pullup and reverse your high and low. up is down and down is up...

HenrikOlsson
- 17th January 2014, 06:31
Or use a PNP, or invert the signal with another transistor or use an 16F88, 16F819, 16F1826 etc etc.
If buying new, go for the enhanced 16F1xxx series, cheaper and better in all respects I can think of.

Selecting 8-bit chips with 18 pins in the Microchip Advanced Part Selector (http://www.microchip.com/maps/microcontroller.aspx), gives 17 different parts, pick one and look at the datasheet.

/Henrik.

ERMEGM
- 17th January 2014, 10:23
Unfortunately, I'm using an npn to control a p-channel mosfet, so I can't change the layout. Thank you for the link. That is extremely helpful.

Tony