Expanding the Outputs of micro

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 5.
To post in this forum you must have a registered copy of Flowcode 5 or higher.

Moderator: Benj

Post Reply
User avatar
fotios
Posts: 458
Joined: Mon Feb 08, 2010 10:17 am
Location: Greece
Has thanked: 109 times
Been thanked: 117 times

Expanding the Outputs of micro

Post by fotios »

I had a problem with the inadequate of I/O ports of P16F1937 that i use in my recent project. The problem arises from the use of 8 double coil Latching relays (also known as power saving relays) which require double control lines (set and reset respectively) compared to common type relays. The only solution i had was to expand the number of output ports of 16F1937 using the SPI interface of micro and two multiplexers. Later i thought that the use of a second micro of 28pin as slave was a better solution as its cost of 2GBP is just 0.5GBP more than two multiplexers plus the extra capabilities that offers like interrupts etc. Indeed, with the use of just one output of master micro it is possible the control of slave micro which in sequence manages a range of 8 Latching relays. With a small conversion of the code of slave micro it is possible the management of 16 common type relay. The activation of relays is executed in a circular manner to the right. The momentary switch simulates the control line that comes from the master micro. I selected the Port RB.4 to connect it because i had a custom made e-block with 2 "active low" momentary switches connected by default at RB.4 and RB.5 of EB-006 programmer, so as to i will have the possibility to test the code on actual hardware. The row of green led represents the set coils while the red the reset coils. It should be noted that though a 15ms pulse is enough to trigger the relay to change state, i have selected some big delays so as the "change state" will be visible. Later these big delays will be removed. As target device i selected the P16F1936. The code is tested on actual hardware and works without mistakes. Special care has been taken into code so that can stores the last data (i.e. the last activated relay) in EEPROM and so if any power failure or BOR or any other reset would occurs, after power restoration will activate again the same relay and a new command from the master micro will activate the next relay, i.e. the code does not start from the relay Nr.1 by default. During programming of micro the PPP compiler also erases all EEPROM data by writing in all of 256 addresses 0xFF. So when the program is first time launched, the variable "switch" gets the same value 0xFF which does not match with any of the branches of Decision "switch-SWITCH" and so program flow directly pass thru the "No" branch of the next decision "If switch < 0x07" and gets the value 0x00 which is appropriate for the normal program execution furthermore.
I know that many of you would prefer the use of SPI or I2C periferal of micro for this project. To be sincere, i know few things about these serial interfaces and i haven't time to study them carefully. On the other hand, in this project just one line needed for the communication between master-slave micro instead the 3 required by SPI. And of course few instructions which are offered almost ready by FLOW CODE! :D :D :D
Thank you
Attachments
PORT EXPAND.fcf
(29.7 KiB) Downloaded 272 times
Best Regards FOTIS ANAGNOSTOU

Post Reply