CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

PIC 16F877A + 3 state encoder (MC145026)

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
mke
Guest







PIC 16F877A + 3 state encoder (MC145026)
PostPosted: Thu Oct 13, 2005 2:01 pm     Reply with quote

Hi,

I'm working on a circuit for controlling a home garage using PIC 16F877A, a 3 state encoder (Motorola MC145026) and a RF transmitter. The objective is, instead of using DIP switches, to use the PIC to generate the 3-state logic output "1", "0" and "Z" (High, Low and Open/High impedance respectively. This corresponds to +5V, 0V and something between 1.5-2.5V).

The code has 8 different bits and I need another one as TE, so I'm using nine different pins of the PIC connected to nine different input pins of the encoder. I'm using PORT A (RAO-RA5) and PORT E (RE0-RE2) (I canīt not use PORT B and PORT D for some reasons).

For generating "1" I use output_high(), for "0" output_low() and for "Z" output_float(). I have a pullup resistor of 2K to +Vcc in PIN A4 (I know this pin is open drain).

I use PCW Compiler Version 3.227.

The problem is that I only get 0V (0.7V actually) as output voltage in PIC pins when I use output_float().

At the beginning, I managed to get 2V as output voltage in 7 of the 8 pins I was using for output_float() (except in PIN A4. For this pin I only got +5V or +0V). But now, and without any change in the code, I always get 0V for all the pins when using output_float() Confused . At any case, I need 2V for all the pins included, PIN A4 when usin output_float().

Maybe someone can give me any ideas. I post the interesting part of the whole code here. Thank you for your help.


For clarifying the program, input_code corresponds to the code required to open the door encoded in the following way:

"1" => 11
"0" => 00
"Z" => 01

Example: 10ZZ1110 => input_code= 50684 <=>(1100010111111100)

Main.h

#include <16F877A.h>
#device *=16
#use delay(clock=4000000)
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)



Main.c


void send_code(WORD16 input_code)
{

/* For generating outputs voltage levels for input encoder Motorola MC145026*/
/* PIC15F877A */
/* Bit0 => A0
Bit1 => A1
Bit2 => A2
Bit3 => A3
Bit4 => A4
Bit5 => A5
Bit6 => E0
Bit7 => E1
TE => E2
*/

byte8 ax,ax1; /* loop variables */


//BIT0
ax=(input_code>>(15-0))&1;
ax1=(input_code>>(15-1))&1;

if ((ax==1) && (ax1==1))
output_HIGH(PIN_A0);
else if ((ax!=1) && (ax1!=1))
output_LOW(PIN_A0);
else
output_FLOAT(PIN_A0);

//BIT1
ax=(input_code>>(15-2))&1;
ax1=(input_code>>(15-3))&1;
if ((ax==1) && (ax1==1))
output_HIGH(PIN_A1);
else if ((ax!=1) && (ax1!=1))
output_LOW(PIN_A1);
else
output_FLOAT(PIN_A1);

//BIT2
ax=(input_code>>(15-4))&1;
ax1=(input_code>>(15-5))&1;
if ((ax==1) && (ax1==1))
output_HIGH(PIN_A2);
else if ((ax!=1) && (ax1!=1))
output_LOW(PIN_A2);
else
output_FLOAT(PIN_A2);

//BIT3
ax=(input_code>>(15-6))&1;
ax1=(input_code>>(15-7))&1;
if ((ax==1) && (ax1==1))
output_HIGH(PIN_A3);
else if ((ax!=1) && (ax1!=1))
output_LOW(PIN_A3);
else
output_FLOAT(PIN_A3);

//BIT4
ax=(input_code>>(15-8))&1;
ax1=(input_code>>(15-9))&1;
if ((ax==1) && (ax1==1))
output_HIGH(PIN_A4);
else if ((ax!=1) && (ax1!=1))
output_LOW(PIN_A4);
else
output_FLOAT(PIN_A4);

//BIT5
ax=(input_code>>(15-10))&1;
ax1=(input_code>>(15-11))&1;
if ((ax==1) && (ax1==1))
output_HIGH(PIN_A5);
else if ((ax!=1) && (ax1!=1))
output_LOW(PIN_A5);
else
output_FLOAT(PIN_A5);

//BIT6
ax=(input_code>>(15-12))&1;
ax1=(input_code>>(15-13))&1;
if ((ax==1) && (ax1==1))
output_HIGH(PIN_E0);
else if ((ax!=1) && (ax1!=1))
output_LOW(PIN_E0);
else
output_FLOAT(PIN_E0);


//BIT7
ax=(input_code>>(15-14))&1;
ax1=(input_code>>(15-15))&1;
if ((ax==1) && (ax1==1))
output_HIGH(PIN_E1);
else if ((ax!=1) && (ax1!=1))
output_LOW(PIN_E1);
else
output_FLOAT(PIN_E1);
}

delay_ms(2000);
output_LOW(PIN_E2); //TE to low state in order to start transmission

delay_ms(500);

}


void main()
{

WORD16 input_code;

set_tris_a(0x00);
set_tris_e(0x00);

input_code=0b1100010101110011; //10ZZZ101
for(;;)
{

output_HIGH(PIN_E2); TE = 1 => No transmission
delay_ms(2000);
send_code(input_code);
delay_ms(30000);

}
Ttelmah
Guest







PostPosted: Thu Oct 13, 2005 3:27 pm     Reply with quote

First comment. You cannot use A4.
The voltage you get when a pin is 'floated', is dependant on what circuitry is applied externally. The pull up resistor will ensure this 'floats' to a logic high, and the 'float' state will not be detected properly.
You will not detect the 'float' voltage in normal use. The way that the chip works, is that it tries to pull the floated line high with current source, and sees if it goes high, then tries to pull it low, and sees if it goes low. If the line stay high in both cases it is assumed to be signalling a 'high', if the line goes low, it is assumed to be signalling a 'low', and if the line happily moves to both levels, it is assumed to be 'floated'. The driver always ends by trying to force the pin low, so the floating pins should normally be seen as 0v, with only a tiny pulse of 5v on them.

Best Wishes
mke
Guest







PostPosted: Thu Oct 13, 2005 3:59 pm     Reply with quote

So you mean that I can not get a "float" output (something between 1.5-2.5V) using the PIC in any case? Neither for A4 nor for the other pins (A0, A1,E0, E1,... or even using PORT C, B or D? So, I can not emulate a 3-state DIP switch via software? Crying or Very sad There should be anyway to get it, shouldn't it?

If it's only for A4 maybe I will be able to solve it, but if not...
Mad

Anyway, thank you for your collaboration.
Ttelmah
Guest







PostPosted: Fri Oct 14, 2005 2:08 am     Reply with quote

For the other pins, yes of course you can. The point is though, that you _won't_ 'see' 1.5 to 2.5v on the floated pins. The voltage on a floated pin is dependant on what is being done with it, and the detector in the chip you are using does not try to pull the pin to a midway voltage, but tries to pull it frst one way then the other. The floated pins will be left at 0v, slowly drifting to some arbitrary voltage depedant on the leakages round the circuit, and will not sit a the intermediate voltage you expect. The other pins will work fine, but not A4.

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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