News:

;) This forum is the property of Proton software developers

Main Menu

Invert Input

Started by Trikkitt, Jul 27, 2021, 03:15 PM

Previous topic - Next topic

Trikkitt


I've got an existing board using a PIC that took a 2400bps async signal where +5v means logic 1 and 0v means logic 0.  I've used the hardware serial port to do the data receive, which works perfectly and is mapped to an input pin using PPS.  Unfortunately I now need to reuse the same board but the input signal is inverted.  Looking at the component diagram that is generating the signal it uses an internal 30k pullup resistor and a transistor to drive the data pin to ground.  Unfortunately this setup doesn't seem suitable for making a simple NOT gate out of an NPN transistor as the base voltage is simply not enough.

I then thought, well I could change my code.  However while some serial functions appear to have an inverted option, it doesn't look like the hardware serial ports do on the receive side.  So that then made me look at the CLC for the first time and my head now hurts.  I thought sure lets make a CLC in to a NOT gate, but honestly I'm lost at the diagrams and documentation.  It feels like they've made something really powerful but is totally beyond my ability to understand.

Anyone got an example of configuring a CLC to run as NOT gate?  Or even a circuit that'll operate as a NOT gate?

I'm using a PIC16F15325

Thanks

Mike


trastikata

#1
Quote from: Trikkitt on Jul 27, 2021, 03:15 PMLooking at the component diagram that is generating the signal it uses an internal 30k pullup resistor and a transistor to drive the data pin to ground.  Unfortunately this setup doesn't seem suitable for making a simple NOT gate out of an NPN transistor as the base voltage is simply not enough.

If you are allowed using additional modification then put a simple 1 FET - 2 resistors inverter between the board and the component. If the signal is less than 3.3v then a logic FET will do perfectly.


tumbleweed

They have a CLC Designer Tool that might figure it out some.
It's now part of MPLABX (ugh), but you can still get a copy of the old standalone version at https://www.microchip.com/forums/download.axd?file=0;928693

There's a manual available at http://ww1.microchip.com/downloads/en/DeviceDoc/41597A.pdf

It hasn't been updated in a while, but it supports the PIC16F15325

Trikkitt

Quote from: tumbleweed on Jul 27, 2021, 04:32 PMThey have a CLC Designer Tool that might figure it out some.
It's now part of MPLABX (ugh), but you can still get a copy of the old standalone version at https://www.microchip.com/forums/download.axd?file=0;928693

There's a manual available at http://ww1.microchip.com/downloads/en/DeviceDoc/41597A.pdf


Yeah I can't even get the MPLabX bloatware to even open the CLC Designer window.  It just hung and never opened.  It really is horrific.  I tried the download link but it doesn't seem to work, possibly as I'm not a user on the forum?  I've registered, just waiting for them to active the account, then I'll try again.

Trikkitt

Quote from: trastikata on Jul 27, 2021, 03:42 PMIf you are allowed using additional modification then put a simple 1 FET - 2 resistors inverter between the board and the component. If the signal is less than 3.3v then a logic FET will do perfectly.



Thanks - not sure this is working either.  I'll have a play around with different resistor values and placement and see if I can get anywhere.  It is the 30k weak pull-up that is feeding the input that I suspect is the main issue. Not enough getting through to the gate given then combined 40k resistance.

trastikata

Quote from: Trikkitt on Jul 27, 2021, 05:18 PMThanks - not sure this is working either.  I'll have a play around with different resistor values and placement and see if I can get anywhere.  It is the 30k weak pull-up that is feeding the input that I suspect is the main issue. Not enough getting through to the gate given then combined 40k resistance.

The gate input resistance of a FET is in the order of several Giga Ohms - it will work for sure and you don't have to play with resistors. The 10k R2 on the gate is there only as protection and you can remove it if you wish.

tumbleweed

QuoteI tried the download link but it doesn't seem to work, possibly as I'm not a user on the forum?
Sorry about that... I didn't notice.

I downloaded it and put a copy on dropbox CLCDesignerTool_Ver3-0-0-4_I_4-6.zip

Trikkitt

Quote from: tumbleweed on Jul 27, 2021, 05:44 PMSorry about that... I didn't notice.

I downloaded it and put a copy on dropbox CLCDesignerTool_Ver3-0-0-4_I_4-6.zip

Wonderful.... that is so much easier to use.  I did finally get it to load in MPLab but my goodness that wasn't easy or quick.  This is instant!

Now for the next headache.  I can route RA3 in to the CLC, but I can't see a way to route the CLC output to the serial port peripheral without taking it external (which I can't do, as the board is made and it is all surface mount).  Or am I missing something.... for some reason thought I could route it :/

tumbleweed

I don't think there's a way of routing the uart RX input directly to a CLC output.
The RX input can come from the PPS, but that still specifies a pin.

Do you have any spare pins that are unconnected?
If so you could use that spare pin to connect the CLC out to RX in:

route RA3 -> CLCIN0PPS
set CLC1 to invert CLCIN0
CLC1OUT via PPS -> SPARE IO PIN
RX1INPPS <- SPARE IO PIN

Stephen Moss

Maybe I am missing something here but would not performing a bitwise compliment (~) on the received data effectively make the 5V a logic 0 and 0V a logic 1

Trikkitt

Quote from: Stephen Moss on Jul 28, 2021, 08:30 AMMaybe I am missing something here but would not performing a bitwise compliment (~) on the received data effectively make the 5V a logic 0 and 0V a logic 1

Sadly not, because the serial start and stop bits are flipped so the serial port gives a framing error.

Trikkitt

Quote from: tumbleweed on Jul 27, 2021, 06:53 PMI don't think there's a way of routing the uart RX input directly to a CLC output.
The RX input can come from the PPS, but that still specifies a pin.

Do you have any spare pins that are unconnected?
If so you could use that spare pin to connect the CLC out to RX in:

route RA3 -> CLCIN0PPS
set CLC1 to invert CLCIN0
CLC1OUT via PPS -> SPARE IO PIN
RX1INPPS <- SPARE IO PIN

I'm exploring that as an option.  For now just to eliminate anything else I've programmed up a spare 12F683 with a continual loop that acts as a NOT gate between the two devices.  At least that'll help me get it working that way, then I can try neater solutions.  I had potentially have two spare pins, although they're in-circuit for other stuff they aren't needed for this exact use.  So maybe I'll be able to do that via the CLC in the end.    Thanks for the pointers and ideas.

See_Mos

Previously I have used a comparator, but not on this device.

You will need access to an input and an output, the other input can be biased to the FVR

Trikkitt

Quote from: trastikata on Jul 27, 2021, 05:30 PMThe gate input resistance of a FET is in the order of several Giga Ohms - it will work for sure and you don't have to play with resistors. The 10k R2 on the gate is there only as protection and you can remove it if you wish.

I ended up getting it to work with an NPN transistor and some 4k7 pull-up resistors.  Looks like the 30k pull-up isn't enough for BC549 or the FETs that I had kicking around.  Thanks for the pointers.

trastikata

Quote from: Trikkitt on Jul 30, 2021, 12:05 AMI ended up getting it to work with an NPN transistor and some 4k7 pull-up resistors.  Looks like the 30k pull-up isn't enough for BC549 or the FETs that I had kicking around.  Thanks for the pointers.

Glad you made it working. I am not sure what you meant by "30k not enough for the FETs" since FETs have input bias current in the range of pA, but anyway you found a solution.

Trikkitt

Quote from: trastikata on Jul 30, 2021, 07:50 AMGlad you made it working. I am not sure what you meant by "30k not enough for the FETs" since FETs have input bias current in the range of pA, but anyway you found a solution.

The 30k pull-up resistor that my device had built in wasn't enough to drive the gate on the FET (or the NPN transistor).  When I added a 4.7k pull-up resistor it worked just fine (what I had to hand, will try a 10k when I've a moment).  I didn't have any small FETs kicking around, so that might have been a factor.

dr-zin

I think you found your problem.  Most "large" (TO-220 type) FETs require a gate turn-on voltage of 6-12 Vdc.  You need to use TTL-level FETs (2N7000/2N7002 or a few others) to get reliable performance from microcontrollers.  That zaps most of us when we start out.  Bipolar transistors work better than great for these applications.  Good luck!