 |
 |
View previous topic :: View next topic |
Author |
Message |
pekka1234
Joined: 28 May 2017 Posts: 105
|
Invert signal problem |
Posted: Tue Sep 23, 2025 3:19 am |
|
|
Hey, I'm making a new measuring instrument, with PIC16F886,
It measures a 200mm potentiometer.
It doesn't give enough accuracy, although I tried with 12 12-bit setup, but it works only every 4 bits.
Then I tried to use 12-Bit PIC18F26K80, but it doesn't give Invert in serial and
I do not have a new PCB. I also do not have a new PIC18F47K80 (44 Pin) that circuit PCB I have, but not a PIC18F47K80.
I have a PIC18F26K80 (26PIN), but it uses normal, not an inverted RS232 circuit.
What to do?
I tried to invert PC program, but it was not simple.
Then I found a new result, I inverted the PIC UART output and the ground.
I put a 1k resistor to the PIC output.
I think it will work.
Pekka Ritamaki |
|
 |
temtronic
Joined: 01 Jul 2010 Posts: 9583 Location: Greensville,Ontario
|
|
Posted: Tue Sep 23, 2025 5:05 am |
|
|
thinking out loud....
Do any of those PIC have PPS ( Peripheral Pin Select ) ?
If so you need to code that BEFORE the #USE RS232(....options..... ) statement.
If you don't then the compiler uses a big bang serial and not the hardware UART so 'invert' may not be allowed.
Also ,historically , you needed to put an 'MC1488' or 'MAX232' between the PIC TTL I/O pin and the PC or other receiving serial device. This inverts the signal for you. Today 'rs232' is a TTL level signal,so a simple inverter(say 1/4 of a 4011 ) could do the hardware inversion.
Others that use your PICs may be able to help.
I don't know why the 886 PIC didn't work for you,I'll see IF it actually has a 12 bit ADC. Most PICs(well older) actually have 10 bit ADC inside. time passes...
from the data sheet.
The Analog-to-Digital Converter (ADC) allows
conversion of an analog input signal to a 10-bit binary
representation of that signal.
need to see your code to see how you setup the ADC. |
|
 |
pekka1234
Joined: 28 May 2017 Posts: 105
|
|
Posted: Wed Sep 24, 2025 7:23 am |
|
|
Temtronic, thank you for your review
I have not tested that non-inverting measurement device.
When I tested it, it showed from ground to negative pulse,
It doesn't work.
I could put a diode and a 1k resistor to 12V internal power.
Will it work? I didn't try.
I have to put an NPN transistor on the serial output.
A 10k resistor to the transistor base and 1k to 5V from the collector and
base to ground.
Now it worked with 1-bit resolution.
3852
3852
3852
3852
3853
3852
3853
3853
3853
3853
3853
3853
3854
3853
3854
3853
3854
3853
3853
3852
3853
3853
3853
3852
3853
3853
3853
The software was not changed.
Code: |
#include <18F26K80.h>
#device ADC=12 // ADC=12
#fuses NOWDT, INTRC_IO, NOPROTECT, NOMCLR,WDT4096//, NOLVP
#use delay(internal=8000000,RESTART_WDT)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7 ) // ei invert PIC18 ei toimi
unsigned int16 measurement;
void measure ()
{
measurement= read_adc();
delay_ms(100); // smmll delay
printf("%Lu\r", measurement);
}
void main(void) {
setup_oscillator(OSC_8MHZ); // 8 MHz internal
set_tris_c(0b00000001); // RC0 (T1CKI) input
set_tris_c(get_tris_c() & ~0x02); // RC1 output blinks a LED.
setup_wdt(WDT_ON);
setup_adc_ports(sAN0 , VSS_VDD);
setup_adc(ADC_CLOCK_INTERNAL);
set_adc_channel(0);
printf("Lenght measurement 24.9.2025\r");
setup_adc_ports(ALL_ANALOG); // All pins analog (that can be)
while(TRUE) {
restart_wdt(); // Reset watchdog
measure ();
output_toggle(pin_c4);// show with LED swithing
delay_ms(900);
}
} |
|
|
 |
gaugeguy
Joined: 05 Apr 2011 Posts: 345
|
|
Posted: Wed Sep 24, 2025 11:35 am |
|
|
The 18F26K80 can invert the UART RX and TX polarity but it seems like your issue is more of a hardware problem.
Please post your hardware connections. |
|
 |
pekka1234
Joined: 28 May 2017 Posts: 105
|
|
Posted: Thu Sep 25, 2025 9:40 am |
|
|
Here is my invert and non-invert schematic
http;//probyte.fi/D.jpg
How can you show it will work?
Pekka |
|
 |
temtronic
Joined: 01 Jul 2010 Posts: 9583 Location: Greensville,Ontario
|
|
Posted: Thu Sep 25, 2025 11:17 am |
|
|
Where is the PIC sending the data to ? What device and connector ?
On a DE-9 connector pin 2 is receive, pin 3 is transmit, pin 5 ground.
On a DB-25 connector , 2 is transmit, 3 is receive, 7 is ground
However IF the receiving device has a real RS-232 comport, you must have a 'MAX232' chip between the PIC and the receiving device. |
|
 |
pekka1234
Joined: 28 May 2017 Posts: 105
|
|
Posted: Thu Sep 25, 2025 11:20 pm |
|
|
No, I only need output every second, but it must be very precise.
It will do a Display, and two Excel files, both of which also wth have graphics.
This works with the output transistor, but not with the inverted and turned (with no transistor output)
Here is a small output
http://probyte.fi/Measuring.jpg |
|
 |
temtronic
Joined: 01 Jul 2010 Posts: 9583 Location: Greensville,Ontario
|
|
Posted: Fri Sep 26, 2025 6:18 am |
|
|
To get better readings( more precise ), you should read the sensor several times then take an average.
One method is the 'Olympic average'. You take 10 readings, discard the highest
and lowest, add the remaining 8 left, then divide by 8.
Also I don't use that PIC but adc-clock_internal may not be a good option.
Others will know as they use 'newer' PICs. |
|
 |
pekka1234
Joined: 28 May 2017 Posts: 105
|
|
Posted: Fri Sep 26, 2025 2:22 pm |
|
|
A can also use an 11 measurement and leave the middle, but this sensor moves all the time. So I used only normal measurements.
Ok, I know that you don't like the internal clocks, but I have found that they work well with a serial measurement.
And if they don't work, I can quickly test like 9000 baud to 12000 baud.
But I always got good answers from here
Pekka |
|
 |
temtronic
Joined: 01 Jul 2010 Posts: 9583 Location: Greensville,Ontario
|
|
Posted: Fri Sep 26, 2025 5:09 pm |
|
|
It's the ADC clock that I was talking about. I downloaded the datasheet, ADC peripheral...section 23.5 has a chart for proper timing of the ADC. At CPU speeds > 1MHz, internal is NOT recommended as the ADC may not operate properly( bad results ).
I've used the CPU internal clocks for decades on projects that do NOT require accurate timing. They are pretty good ,at room temperature but for precise timing or 'real world' exposure( hot or cold) , always best to use a crystal and 2 caps.
As far as ADC readings not being accurate, getting perfect and consistent 12 bit readings requires a LOT of proper designs and construction ! 5 volts / 12 bits is a really,really small value, so PCB layout is important as well as hardware filtering( compromise speed vs accuracy ), EMI protection random glitches ) thermal effects. All carbon based 'pots' are scratchy,so noise is introduced when they are turned, that noise can create inaccurate readings. A lot of these errors can be minimized by 'over sampling'. The Olympic average is nice to use, there are 100s of others, and always best to take 2,4,8,.... 64 readings as it make for FAST averaging. Odd number of samples requires a LOT of CPU time do do the math. |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|