import substitution from improvised materials


introductory

I needed a simple programmable timer, also known as a time relay. A simple contraption that closes contacts at a specified time. In a word, nothing complicated.

But with the onset of sanctions, even such simple laboratory equipment became impossible to buy. Here is a good example: http://www.optimum-lab.ru/product/tajmer-laboratornyj/. An excellent laboratory device, but as the seller almost directly writes, it is not so easy to buy it now. Another case: https://www.chipdip.ru/product/at8n-24-240v-ac-dc. Not as convenient and attractive development as the previous version, but available. But for some reason it costs indecently a lot, when an ordinary relay and a timer are enough for such a task. And this option: https://www.chipdip.ru/product0/8002563209 combines unhealthy price and unhealthy delivery times.

Finding quality equipment is getting harder and harder.

Finding quality equipment is getting harder and harder.

It is clear why it is – to transport across the border for a long time and difficult, at each stage the price of the goods rises, and there is always the possibility that the product will not be imported for an unexpected reason, and all risks are included in the price. However, the import substitution trend is gaining momentum. Domestic manufacturers are thinking about how to scale the production of new chips from silicon, new domestic manufacturers appear (albeit with hieroglyphs in the name), and I decided to join this trend.

I don’t want to spend money on a device that I don’t need often and don’t really want to, and therefore I decided to make it myself, from improvised components, without investing excessively. What is needed for a time relay? Actually, relay and time. And an interface to control the time of this relay. The device should not be expensive, should contain a minimum of sanctioned components (or not contain them at all) and correctly perform its function. Accordingly, materials and components that are produced or have domestic analogues must be selected for development. I found MCS-48 in mine. And already in several forms: the original 8049 and KR1816BE39. A great option for my device: already available, no redundancy in capacity. Of course, KR1816BE39 was produced in Kyiv, and has already been discontinued, but I’m sure that the technologies have remained somewhere in the Academy of Sciences, which means that at any time the production of popular processors can be resumed in Russia.

An important feature is that regardless of the presence of an internal ROM, this family switches to the external ROM mode when the EA foot is pressed to the power supply. It is very fortunate that I also have various kinds of ROM!

Components

The brain I found is MCS-48. It remains to decide on the input and display interface. Since I wanted the device to be efficient not only economically, but also in terms of user convenience, I decided to limit the input interface to two buttons:

  1. Changes the selected option

  2. Entering or exiting setup mode

This microcontroller has three outputs, the status of which can be checked with a single conditional jump instruction! But there are only two buttons, so we use only two of them: T0 and T1. This means that with one button we enter the settings mode and switch in turn between all the parameters to be changed, and with the second we directly change them. At the same time, immediately after starting, the settings mode is activated so that the relay does not work when it is not necessary. There is not much to configure – the current time and the activation time of the relay (the activity time can be made hard-coded).

The indication should also be as user-friendly as possible, so for it I decided to use a two-line display with an interface compatible with the HD44780. The display has a synchronous parallel interface, which suits us.

It was logical to power all this from the popular source of five volts – USB. Unfortunately, this microcontroller does not support the USB protocol, otherwise it would be possible to significantly expand the functionality of the device.

Please note that all devices used have almost direct, almost domestic counterparts. Alas, not all the parts I used were domestic production, but this will be easily corrected when scaling. This means that this development will remain relevant in the context of total import substitution, and the project turns out to be very compact in terms of procurement difficulties and budgetary in terms of spending. For minimal money and time, you can get such a functional device!

Development

The memory bus, data bus and GPIO in the case of the MCS-48 are all one bus. And what is displayed on it must be determined by the state of the ALE and PSEN outputs. More precisely, this microcontroller does not have GPIO in the usual sense, but there is something better. These are Quasi bi-directional ports. Of the features – there is no hard zero and one at the output, and when a certain value is written, it gives out a high current for a short period, and then gently pulls it up. Exactly what you need: almost impossible to burn and a minimum of complexity in design and configuration.

So the general scheme is:

General scheme of the device

General scheme of the device

There is nothing complicated. Since the internal memory is beyond my control, but you can make it work with external memory if you apply a high signal to the EA input.
The way to access external memory is simple: P20-P23 contains 4 bits of address A8-A11, D0-D7 first contains 8 bits of address A0-A7, and then receives 8 bits of data D0-D7. Auxiliary pins are used: ALE, PSEN. There is also a WR, RD pin for using external RAM, but I will not do this.

Algorithm for reading data from external memory:

  1. ALE rises in 1

  2. The address is set on the address bus

  3. ALE goes down to 0

  4. External device reads the address

  5. PSEN goes down to 0

  6. An external device outputs data to the data bus

  7. PSEN rises to 1

  8. MCU reads data from data bus

Programming and production

Programming this controller is as simple as it is illogical. I don’t see the point in describing this stage in detail, but I want to note several features.

  • An unexpected set of commands, and in particular separate commands for starting / stopping the timer, enabling individual interrupts and conditional transitions based on the state of certain pins.

  • Stack inaccessible to the user. More precisely, you can modify the data from it yourself, but only by accessing the same memory area. There is nothing like PUSH/POP here. By the way, here the stack pointer consists of three bits.

  • Lack of commands for working with trigonometric functions. Alas, a good PID controller will not be so easy to make.

  • Almost all registers are stored in memory, and there is an instruction that switches the register bank (the base address of the register file in memory). Handy for interrupt handling.

  • There is no power-on-reset here, and when power is applied, the microcontroller starts from an indeterminate state. But the Reset input has a built-in Schmidt trigger, and if you hang a thicker capacitor on it, then when you turn it on, you get this same power-on-reset.

Since this is still a prototype, I assembled the device on a breadboard. What I love about breadboards is their aesthetics! No need to guess where the track goes, just take and pull the wire.

Bundle of wires on a breadboard

Bundle of wires on a breadboard

From the front side, the device turned out to be no less pretty! You may think that there are too many components for such a trifling task. And you will be right: two microcircuits can be safely excluded, they are needed only for debugging. Yes, this controller can be debugged, and the debugger is already built into it: if between ALE pulses a low level is applied to SS, the device will stop the program execution, leaving the address of the next instruction on the bus. It remains to arm yourself with a multimeter – and you can know what is happening inside!

Unfortunately, I had nothing to flash the ROM with. I checked the firmware on the computer as best I could, since the compiler comes with a very good simulator. Buying a flash driver for parallel flash drives is not cheap, and given that I only need it once, it’s also pointless. So I decided to re-assemble the device from improvised components, which will solve the problem. Of course, there was a desire to apply MCS-48 here too, but there is a chicken and egg problem. And I didn’t want to spend a whole 32-bit microcontroller on such a spitting task. Therefore, the following solution was developed:

Universal Parallel Memory Programmer

Universal Parallel Memory Programmer

This is a device for manual control of the sewing process. Since I value UX above all else, I limited myself not only to clickers at the outputs of the microcircuit, but also to conveniently located switches and address / data indicators. The device itself is designed for more popular flash drives of the 010 series (AT010, SST010), but any other device can be connected to it through an adapter. For example, my HN462732.

Since I use a special ROM that is erased by ultraviolet, you need to erase it before flashing it. I don’t have an erasing lamp, but I do have a powerful UV flashlight that does the job just fine:

Chip erasing

Chip erasing

After this procedure (about twenty minutes, but possibly less), the ROM is erased – all bits are set to ones. Also, data can be damaged even from sunlight, so the window must be sealed with a special sticker. I was lucky, I found such stickers on sale, they even immediately indicate the numbers so that you can version version by writing different versions of the firmware to different ROMs.

Now you can flash it. Having assembled a simple adapter for my flash drive (addresses are thrown, +25 volts and E are brought out to a toggle switch with a diode), I set to work. It took some time.

So, here’s what I got:

Now you need to test it in conditions close to combat. In the test, I tritely connected a multimeter to the switched connector in ringing mode. In order to roughly estimate the accuracy of the timer, I put a clock in the frame.

As you can see, the device worked exactly as it should. Yes, you need to separate the board for serial production, find where to buy parts, optimize the firmware a little, but these are trifles. The main work is done, the device works, and even when it is not needed as a laboratory timer, it can work as a clock.

I think this startup is doomed to success, I plan to go with him to the Seliger business incubator. If there are those who want to become partners and finalize the device or help calculate the economic part of a startup, send pull requests to the repository with the scheme and verification: https://github.com/aleaksah/absolutely-normal-time-relay

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *