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 support@ccsinfo.com

[SOLVED,Thanks!] Set all ports floating when powering up
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
ELCouz



Joined: 18 Jul 2007
Posts: 427
Location: Montreal,Quebec

View user's profile Send private message

[SOLVED,Thanks!] Set all ports floating when powering up
PostPosted: Sat Dec 08, 2012 2:47 pm     Reply with quote

Hi,

I have on a board a PIC18F4685 (12mhz xtal) connecting to a 16 relay board module ----> (datasheet)

This module is using a LOW level input (High being off and low ON)

The problem i have is the module is keeping the lines high (normal) and this make the PIC gets power from the module inputs pins to the pic output pins (PORT B & D) (which i don't want!) !!

But then the pic ground the pins at power up and this makes all the relays ON (No good)

1. Is there a way to manage this unwanted power?
2. Is there a way to have all ports in floating mode at power up?

Is that me or i find that counter intuitive to make a relay board driven by low logic?

Thank you very much!
_________________
Regards,
Laurent

-----------
Here's my first visual theme for the CCS C Compiler. Enjoy!


Last edited by ELCouz on Sun Dec 09, 2012 3:47 pm; edited 1 time in total
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Sat Dec 08, 2012 2:56 pm     Reply with quote

Normal mode for the PICs I've used is for ALL I/O pins to be configured as input on power up.

So to get peripherals in the correct state you simply pull in the required direction with a resistor.

Mike
Ttelmah



Joined: 11 Mar 2010
Posts: 19329

View user's profile Send private message

PostPosted: Sat Dec 08, 2012 3:03 pm     Reply with quote

Yes, in fact this is one of the guaranteed things in the data sheet of the PIC.

If however the pins are set to output, by setting TRIS, then they will drive high (default for the output latches is '11111111'. So you as a programmer, must set the output latch before changing TRIS.

Best Wishes
ELCouz



Joined: 18 Jul 2007
Posts: 427
Location: Montreal,Quebec

View user's profile Send private message

PostPosted: Sat Dec 08, 2012 3:06 pm     Reply with quote

Thank you everybody, i can figured out the power issue...

I need to apply power to the PIC first then relay board after!

Do you have a shorter code which replace:


Code:

output_float(pin_b0);
output_float(pin_b1);
output_float(pin_b2);
etc...


for an entire port?

thanks!
_________________
Regards,
Laurent

-----------
Here's my first visual theme for the CCS C Compiler. Enjoy!
Ttelmah



Joined: 11 Mar 2010
Posts: 19329

View user's profile Send private message

PostPosted: Sun Dec 09, 2012 1:47 am     Reply with quote

set_tris_b(0xFF);

This is the default on power up.

Best Wishes
Ttelmah



Joined: 11 Mar 2010
Posts: 19329

View user's profile Send private message

PostPosted: Sun Dec 09, 2012 4:56 am     Reply with quote

Or power at the same time.
All pins on a chip like the PIC, have effectively 'protection diodes', preventing them being taken more than about 0.6v above the supply pin. If power is applied to the relay board first, then with the Vdd of the PIC board at 0v, all the pins will be prevented from going above 0.6v...
This sounds like bad design. If the two boards are powered independently, then there should be an output_inhibit input to the relay board, which if held low, prevents the drivers from coming on.

Best Wishes
ELCouz



Joined: 18 Jul 2007
Posts: 427
Location: Montreal,Quebec

View user's profile Send private message

PostPosted: Sun Dec 09, 2012 8:09 am     Reply with quote

Thanks for the instruction Ttelmah Smile!

Quote:
This sounds like bad design. If the two boards are powered independently, then there should be an output_inhibit input to the relay board, which if held low, prevents the drivers from coming on.


The problem is that is held HIGH (pull-ups) on the relay board (driven by low level) and when i measure from ground to relay board input pins i get 4.5v

If the line is held low the relay will engage... optocouplers are held at 5v with a resistor network

Take a look at the schematic of the board:






The input pins of the relay board are directly wired to the PIC pins.
Should i need another pull ups near the pic but i think its redundant because the optocoupler is already held HIGH.

What would be your solution to prevent power leeching?

Many thanks!
_________________
Regards,
Laurent

-----------
Here's my first visual theme for the CCS C Compiler. Enjoy!
ELCouz



Joined: 18 Jul 2007
Posts: 427
Location: Montreal,Quebec

View user's profile Send private message

PostPosted: Sun Dec 09, 2012 8:11 am     Reply with quote

Quote:
All pins on a chip like the PIC, have effectively 'protection diodes', preventing them being taken more than about 0.6v above the supply pin. If power is applied to the relay board first, then with the Vdd of the PIC board at 0v, all the pins will be prevented from going above 0.6v...


Btw, should i put the BROWNOUT (2.1v) fuse to help ?
_________________
Regards,
Laurent

-----------
Here's my first visual theme for the CCS C Compiler. Enjoy!
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Sun Dec 09, 2012 1:25 pm     Reply with quote

Your schematic explains nothing to me.

Your description adds nothing either.

Please, simply show the connections for one channel only.

Mike
ELCouz



Joined: 18 Jul 2007
Posts: 427
Location: Montreal,Quebec

View user's profile Send private message

PostPosted: Sun Dec 09, 2012 1:35 pm     Reply with quote

Alright

Here's the chinese 16 relay board complete schematic:



-----> LINK PDF DOWNLOAD <---------

Here's my layout for interfacing with the board:

Code:

         GND ---> Connector ---> Wire ---> Relay Board GND
                   
___     PIN     
| 1 |----B7--> Connector ---> Wires ---> Connector---> Relay Board Input #1
| 8 |
| F |
| 4 |
| 6 |
| 8 |
| 5 |
|__|


I hope I've cleared any confusions Smile
_________________
Regards,
Laurent

-----------
Here's my first visual theme for the CCS C Compiler. Enjoy!
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Sun Dec 09, 2012 1:43 pm     Reply with quote

No. I said SCHEMATIC for ONE CHANNEL only, please.

Mike
ELCouz



Joined: 18 Jul 2007
Posts: 427
Location: Montreal,Quebec

View user's profile Send private message

PostPosted: Sun Dec 09, 2012 1:46 pm     Reply with quote

I don't understand Mike...

You want me to redraw the manufacturer schematic to display one channel ?
_________________
Regards,
Laurent

-----------
Here's my first visual theme for the CCS C Compiler. Enjoy!
Ttelmah



Joined: 11 Mar 2010
Posts: 19329

View user's profile Send private message

PostPosted: Sun Dec 09, 2012 2:54 pm     Reply with quote

I think you are missing the point. The PIC _does not_ take it's outputs low when it is switched on. It's outputs _wake up_ floating.
However when the PIC board is switched off, the processor will act as a load to 0v, till it's power appears. You need to power the PIC from the same 5v supply as the relay board. If the PIC is switched off, your relays will be on. No code can affect this.

Best Wishes
ELCouz



Joined: 18 Jul 2007
Posts: 427
Location: Montreal,Quebec

View user's profile Send private message

PostPosted: Sun Dec 09, 2012 3:04 pm     Reply with quote

Thank you Ttelmah!

You explained the problem easily... i've learned something Smile

Before you posted this i kinda find a (very dirty) way to fix this problem:

- Added BOR46 fuse (because I've noticed the voltage is between 3v and 3.4v when pic power supply is off and the relay board leaks power to the pic)

- Switched the relay board power with a high logic relay

This caused the PIC to reset itself and all the output too so it would cut the high driven relay thus stopping the power going to the 16 relay board!

I will try powering directly from the relay board ... like you said... it should fix the problem!
_________________
Regards,
Laurent

-----------
Here's my first visual theme for the CCS C Compiler. Enjoy!
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Sun Dec 09, 2012 3:36 pm     Reply with quote

OK. So you understand I'd like to see a schematic for one channel only.

I think it looks a bit like this for channel 0:-
Code:

                              OPTO ISOLATOR
                           ---------------------               12V
           Part of PR1    |                     |               |
+5V ----------WWWWW------------              --------5V         C
                          |    |             |C |               C Relay   
                          |  ----         | /   |               C  Coil
                          |  \  /         |/    |               C
                          |   \/          |\    |               |
                          |  ----         | \   |               |
                          |    |             |E |            | /C
PIC O/P -----------------------               ---------------|/ 
                          |                     |            |\
                           ---------------------               \E
                                                                |
                                                                |GND
                                                        Part of ULN2083

As I understand it you have these two states:-
Code:

 -------------------------------------------------------------
| PIC O/P | OPTO DIODE | OPTO O/P | ULN2083 Collector | RELAY |
 -------------------------------------------------------------
|  LOW    |    ON      |   ON     |       LOW         |   ON  |
 -------------------------------------------------------------
|  HIGH   |    OFF     |   OFF    |       HIGH        |   OFF |
 -------------------------------------------------------------

I'm assuming the 5V for the Opto is derived on the relay board.

Please confirm that I have the logic correct.

What supplies the 5V for the input side of the opto?

Is it the relay board or the PIC board?


Mike

EDIT

Ttelmah has hit the nail on the head.

You have several options:-

1) Power the PIC from the relay power board (like Ttelmah says).
2) Power the Opto inputs from the same 5V as the PIC.
3) Use open collector/drain devices to drive the optos rather than the PIC directly.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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