simple read port example request

General discussion on mikroC PRO for PIC.
Author
Message
aurbo
Posts: 67
Joined: 15 Feb 2008 02:44

simple read port example request

#1 Post by aurbo » 16 Aug 2014 05:19

Greetings

I'm tinkering with a cable tester idea that so far I'm not getting anywhere with.

Anyone have an example of writing out to a pin on PortA, and checking to see if the value is returned on any pin on PortB, and storing the result?

for a simple cable tester, would I write (LATA) on PortA and monitor PortB for the result?, check voltage? or is there another method

Not really sure how this is done.

Steve

paulfjujo
Posts: 1543
Joined: 24 Jun 2007 19:27
Location: 01800 St Maurice de Gourdans France
Contact:

Re: simple read port example request

#2 Post by paulfjujo » 16 Aug 2014 16:30

hello,
for a simple cable tester, would I write (LATA) on PortA and monitor PortB for the result?,
a very simple test , you write in sequence 1,2,4..128 on LATA
and check back on PORT B or D the status off each wire..
it's suppose you have pull-up resistance on each output PORTA.

You can store result test in a Eeprom 8K or 32K bytes or on a SDCard or send by Bluetooth to a terminal
add a test sequence number , maybe also Date & Time..etc
check voltage?
and this test is made with only 5V and less than 1mA of current..
it's depend of your application wich uses your cable..
if you want to test with higher voltage 24V DC or 230V AC ,it's need to add
interface on output , and galvanic insulation for PIC input..
or is there another method
You Know what it is for, not us !
Write a specsheet for what you want ..
Insulation test or just continuity ?
etc ...

aurbo
Posts: 67
Joined: 15 Feb 2008 02:44

Re: simple read port example request

#3 Post by aurbo » 17 Aug 2014 19:37

paulfjujo wrote:hello,
for a simple cable tester, would I write (LATA) on PortA and monitor PortB for the result?,
a very simple test , you write in sequence 1,2,4..128 on LATA
and check back on PORT B or D the status off each wire..
it's suppose you have pull-up resistance on each output PORTA.

You can store result test in a Eeprom 8K or 32K bytes or on a SDCard or send by Bluetooth to a terminal
add a test sequence number , maybe also Date & Time..etc
check voltage?
and this test is made with only 5V and less than 1mA of current..
it's depend of your application wich uses your cable..
if you want to test with higher voltage 24V DC or 230V AC ,it's need to add
interface on output , and galvanic insulation for PIC input..
or is there another method
You Know what it is for, not us !
Write a specsheet for what you want ..
Insulation test or just continuity ?
etc ...

Thanks for the reply,

Just continuity with ~5dvc.
For each pin (LATA) out, scan all pins in for the voltage, store results, step through each of the 8 pins, display which pin out corresponds to which pin(s) in, or none.



I'm tinkering with this code from Elektor from back in 2006, the 8 conductors are tested in pairs and the results are sent to an led if correct

I may have to replicate the entire project to understand it better then morph it into what I want.

Code: Select all

void TestSTCable() // Test straight-through cable
{
int8 pair;
PORTD = 0;
PORTB = 0;
for (pair = 0; pair < 4; pair++) // scan pairs
{
if (TestSTPair(pair) && bit_test(PORTA,pair)) // selected & connected?
bit_set(PORTB,pair+4); // turn on LED
delay_ms(500); // wait a bit
PORTB = 0;
}
}


int1 TestSTPair(int8 p)             // Test traight-through pair p
{
   int address;
   address = p<<1;
// First half
   bit_set(PORTD,address);          // test High
   if (!bit_test(PORTC,address))
      return 0;
   bit_clear(PORTD,address);        // test Low
   if (bit_test(PORTC,address))
      return 0;
// Second half
   bit_set(PORTD,address+1);        // test High
   if (!bit_test(PORTC,address+1))
      return 0;
   bit_clear(PORTD,address+1);      // test Low
   if (bit_test(PORTC,address+1))
      return 0;
   return 1;
} 

paulfjujo
Posts: 1543
Joined: 24 Jun 2007 19:27
Location: 01800 St Maurice de Gourdans France
Contact:

Re: simple read port example request

#4 Post by paulfjujo » 19 Aug 2014 18:42

hello,

Why testing by pair ?

is it for cable 4 pairs
if any kind of cable , you can test individual wire
8 wires ..8 leds..

if you don't have enough INP ans OUT on your PIC
you can use MCP23017 16 bits I2C expander
to test multiwires cable

3 expander to test cable with 16 wires ..
16 inp
16 out
16 leds

aurbo
Posts: 67
Joined: 15 Feb 2008 02:44

Re: simple read port example request

#5 Post by aurbo » 19 Aug 2014 18:50

Did not plan on testing by pair, the code posted was the only example close to what I want to do..

just using it as a base to modify.

Yes, I have 2 ports (16 pins) on the 18F4620 set aside specifically to test wire by wire.


I'm open to any suggestion at this point as i still don't quite understand the whole method.

Sparky1039
Posts: 1179
Joined: 24 Nov 2005 20:07
Location: Colorado, USA

Re: simple read port example request

#6 Post by Sparky1039 » 19 Aug 2014 19:11

Besides direct continuity do you have provision to test for wire to wire short?

aurbo
Posts: 67
Joined: 15 Feb 2008 02:44

Re: simple read port example request

#7 Post by aurbo » 19 Aug 2014 22:44

Honestly, no.

But it makes sense to check for wire to wire shorts while checking continuity.

paulfjujo
Posts: 1543
Joined: 24 Jun 2007 19:27
Location: 01800 St Maurice de Gourdans France
Contact:

Re: simple read port example request

#8 Post by paulfjujo » 24 Aug 2014 17:26

hello,

in fact, if you test every wire one by one for contnuity, you can alse detect a short between 2 wires !
because result must tell bad test !
you send 1,2,4,8,16,32,64,128 via PORTD to test the wire 1,2,3,4,5,6,7,8
and on feed back ,PORTB, you receive1,2,4,8,16,32,64,128
if all is OK

global comparaison on 8 bits , could show short between wires..

Try this.. i did not test in reality

Code: Select all

unsigned char SendValue,BackValue;
int i,j;


j=0;
do
{
WaitPushButtonTostart();    // use an input (Port A ou C) , to decide to start the test
SendValue=0;
LATD=SendValue;
printf("Test ON cable #%03d \r\n",j);
dr=0;
for (i=0;i<7;i++)
 {
   SendValue=1<< i ;   // so sendvalue is 1,2,4,8,16,32,64,128
   LATD=Sendvalue  ; // LAT if PIC18F or PORT if 16F 
   BackValue= PORTB; // read the feedback
   // test continuity, wire by wire, bit per bit
   if ((BackValue  & SendValue ) != SendValue)
   {
    printf("Probleme sur ce cable #% 3d, fil # %02d coupé \r\n",j,i);
    dr=1;
    }
   // test short between wires 
   if (SendValue !=BackValue)   // test all 8 wires status
   {
    printf("Probleme Cable #% 3d , court jus entre fil %3d et autre fil \r\n",j,i);     // wire in test
    printf("Send : % 8b       \r\nBack  : %8b",SendValue,BackValue);  // see in binary, more easy to detect problem
    dr=1;
   } 
 }
 if(dr=0)
 {
   printf("RAS sur ce cable #% 3d\r\n",j;
 }  
 // Wait for push button to decide the follow ..
 if (PushButton_STOP) Break;
 j++;
}
while(1);
Short is tested with only 5V.. not enough to have a warranty with nominal Voltage supply
wich could be 100V DC or 300V AC ..

Sparky1039
Posts: 1179
Joined: 24 Nov 2005 20:07
Location: Colorado, USA

Re: simple read port example request

#9 Post by Sparky1039 » 24 Aug 2014 18:37

@Paulfjujo,
Actually this won't work (not the code but the hardware arrangement). The reason is because those pins on the driving port that are not active are held in a low state which in the case of a wire to wire short will be driving against the pin driving high. This will create a short circuit condition at the PIC which is bad and potentially damaging. The way to do this correctly is this...

1. Apply pull down resistors on both the driver and receiver port pins (value not critical 4.7k-10k is a good start). Resistors should be located right at the PIC. The pull downs are necessary in the event of "open" wire conditions on either side of the cable whereby no input is left floating.
2. At code start up configure both driver and receiver port pins to inputs (tris registers to 0xFF).
3. At the start of the continuity test configure a single driver port pin as an output and set high. All other driver port pins remain inputs, doing so avoids the 2-output logic contention in the event of a wire to wire short.
4. Scan the receiver port for single continuity of selected wire AND if there are any shorts between wires. A wire to wire short will show up as an additional receiver port pin going high.
5. Scan those driver port pins that are inputs for a wire to wire short in case the wire is open somewhere before the connection to the receiver port.
6. At the end of single wire check (pass/fail) set driver pin back to input. Select next port pin to check, set this as output and repeat steps 4-6.

This method covers all possible states that could be encountered, continuity, open, wire to wire short without creating a logic state contention.
Last edited by Sparky1039 on 25 Aug 2014 05:26, edited 1 time in total.

aurbo
Posts: 67
Joined: 15 Feb 2008 02:44

Re: simple read port example request

#10 Post by aurbo » 24 Aug 2014 23:58

Thanks for the input Paul and Sparky

I actually understood what Sparky was describing which is both scary and exciting.. :D

I've adding pull downs to all 16 pins on PortB and PostC in Proteus and slowly working my way through all steps Sparky posted.

I'm assuming this has been done before by the way Sparky laid out the logical steps.

aurbo
Posts: 67
Joined: 15 Feb 2008 02:44

Re: simple read port example request

#11 Post by aurbo » 29 Aug 2014 01:18

What did I miss?

Code: Select all

char txt1[] = "Menu1";
char txt2[] = "Option1";
Lcd_Out(1, 1,(txt1," ",txt2));
This will only print out the txt2 overwriting txt1 and " "

Sparky1039
Posts: 1179
Joined: 24 Nov 2005 20:07
Location: Colorado, USA

Re: simple read port example request

#12 Post by Sparky1039 » 29 Aug 2014 02:33

Each string requires its own command.

Code: Select all

char txt1[] = "Menu1";
char txt2[] = "Option1";
....
Lcd_Out(1, 1, txt1);
Lcd_Out(1, 6, " "); // also can be Lcd_Chr (1, 6, ' '); // note the single quotes for a single character
Lcd_Out(1, 7, txt2);

aurbo
Posts: 67
Joined: 15 Feb 2008 02:44

Re: simple read port example request

#13 Post by aurbo » 29 Aug 2014 02:58

Thanks again

aurbo
Posts: 67
Joined: 15 Feb 2008 02:44

Re: simple read port example request

#14 Post by aurbo » 29 Aug 2014 21:19

Back to the continuity test..

Anyone have an example of a single test (one output pin) that will scan the input pins for both continuity and cross wire shorts?

aurbo
Posts: 67
Joined: 15 Feb 2008 02:44

Re: simple read port example request

#15 Post by aurbo » 01 Sep 2014 04:21

For something that should be relatively simple to make, I've not found a recent example of how to test a cable using a PIC..

Still looking tho..

Post Reply

Return to “mikroC PRO for PIC General”