What am I doing wrong? 16F628A
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
Code:
#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
Re: What am I doing wrong? 16F628A
PortA.4 is an open drain port. You must use a pullup resistor in order to drive your transistor.
Cheers
Al.
Re: What am I doing wrong? 16F628A
Hi;
To complement aratti answer, that information is on the Datasheet.
Re: What am I doing wrong? 16F628A
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
Re: What am I doing wrong? 16F628A
Use the pullup and reverse your high and low. up is down and down is up...
Re: What am I doing wrong? 16F628A
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, gives 17 different parts, pick one and look at the datasheet.
/Henrik.
Re: What am I doing wrong? 16F628A
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