A computer control device for various devices, the diagram of which is shown in Fig. 1, connects to the USB port of the computer, which is present in each of them today. The only chip of the device is a common microcontroller ATmega8. It is necessary for organizing communication via the bus. USB. Although it does not have a dedicated hardware module, this function is performed in software.
Picture 1
Resistor R1, connected between the positive terminal of the power supply and the USB D-bus line, switches it to low-speed LS mode with an exchange rate of 1.5 Mbit/s, which allows you to decrypt computer messages in software. Resistors R4 and R5 eliminate transients that occur during information exchange, which increases operating stability. Capacitor C1 blocks impulse noise in the power circuit, which also improves the stability of the device. Diodes VD1 and VD2 are used to lower the microcontroller supply voltage to approximately 3.6 V - this is required to match the levels with the USB bus.
Device control signals are generated at the outputs PB0-PB5 and PC0, PC1 of the microcontroller. High logic level - voltage about 3.4 V. Voltage low level close to zero. You can connect devices to the outputs that consume a current of no more than 10 mA (from each output). If required large values current or voltage, then matching nodes should be used.
The device is assembled on a breadboard, a printed circuit board has not been developed. MLT resistors are used, capacitors C2 and SZ are high-frequency ceramic capacitors, C1 is K50-35 or similar imported. Silicon diodes with a voltage drop across the junction of about 0.7 V.
The program for the microcontroller was developed in the environment Bascom-AVR versions 1.12.0.0. A library is used to work with the USB bus swusb.LBX, which performs software decoding of USB signals in real time. The resulting program code from a file with the HEX extension should be loaded into the FLASH memory of the microcontroller. The state of the microcontroller configuration bits must correspond to that shown in Fig. 2.
Figure 2
When you connect your device to your computer for the first time operating system will discover something new USB HID compatible device named " uniUSB" and will install the necessary drivers. After a few seconds, the device is configured and ready for use. The UniUSB program was created to work with it. It is available in two versions: for 32-bit (x86) and 64-bit (x64) operating systems of the Windows family. The 32-bit version has been tested on Windows 98, Windows XP, and Windows 7 operating systems, while the 64-bit version has been tested only on Windows XP x64.
Program UniUSB written in language PureBasic(version 4.31) using the library of user-defined functions HID_Lib, supporting work with USB HID devices. Appearance The program window is shown in Fig. 3.
Figure 3
In the same folder as its executable file there should be a file called UniUSB_KOfl.txt. This file stores the script for controlling external devices. When the program starts, data from the file is loaded into a table located in the main window, and when the work is completed, it is saved in the file. Left-clicking on table cells allows you to change their state: 1 - high logical level, 0 or empty - low logical level.
To add or delete a table column, you need to right-click on it and select the required action in the menu that appears. When you connect a device to a USB port, the program will detect it and activate the Start button located at the top of the window on the toolbar. Clicking this button starts the process of sorting through the table columns and setting the output states indicated in them. For greater clarity, to the left of the table the numbers of outputs on which this moment The logic level is set high. The search speed (time in milliseconds between transitions from column to column) is set in the "Speed, ms" field.
Please note, operating room Windows system- multitasking! This means that processor time is divided among many processes, sometimes hidden from the user, which are executed in turn, taking into account the priorities set in the system. Therefore, you should not expect great accuracy in maintaining time intervals of less than 100 ms.
To briefly stop sorting through columns, use the "Pause" button. Pressing it again will continue the search from where it stopped. The "Stop" button completely stops searching through the table columns. If the exchange of information between the computer and the device fails or the device is disconnected from the connector Computer USB, the program will report an error by displaying a corresponding message in the status bar.
Source: Radio No. 2, 2011
13-01-2014
Zakharov Denis, Ukraine
As you know, there are a sufficient number of interfaces through which a microcontroller (MCU) can communicate with external devices. If you need to connect the MK to a personal computer or laptop, then we can confidently say that it is best to use the RS-232 COM port interface.
The reason for this choice is obvious - almost all controllers have UART hardware modules, with which you can transfer information with minimal consumption of MK resources. In addition, there are many well-proven programs designed to work with the COM port. Since MK signals have TTL levels, a level converter is required to match with the RS-232 interface. It is often performed based on the affordable and popular MAX232 chip.
Picture 1. |
The presented device (Figure 1) is designed to control devices using any PC with a USB port. Modern computers and laptops have several of these ports. Using this complex you can control light, TV and other devices. Executing devices do not necessarily have to be in close proximity to the PC.
The device consists of quite accessible and common elements. Both microcircuits are ATtiny2313 family microcontrollers. The first controller is connected to the computer's USB port and serves as a USB-COM format converter. The second connects to the first and constantly scans commands that are sent from the PC through the terminal program Terminal v1.9b.
Resistor R4 connected to USB pin 2 switches the device to low-speed LS mode, which allows you to decrypt messages from a PC when exchanging data at a speed of 1.5 Mbit/s using the program.
With the help of resistors R2 and R3, transient processes are eliminated. Capacitor C5 blocks impulse noise in the power circuit. Zener diodes D1 and D2 are necessary to match the logical levels of the MK and the USB input of the PC. For error-free data transfer between controllers, the frequencies of the quartz resonators must be 12 and 4 MHz.
Pull-up resistors should be connected to the /RESET pins in order to subsequently avoid arbitrary reset of the MC due to the influence of interference and static voltages. In this diagram, all commands are displayed on LEDs connected to port B. To control any devices, you must connect the controller outputs to a relay (Figure 2).
You can assemble the device on a breadboard, although it’s still better to use a full-fledged one printed circuit board. The elements can be placed, for example, as shown in Figure 3.
The program for the U1 microcontroller was developed by a friend of GetChiper in the Bascom-AVR environment. A library is used to work with the USB bus swusb.LBX. With its help, software decoding of the USB protocol is performed in real time. For the device to work with a PC, you need to install the appropriate drivers by copying them to HDD. When you connect for the first time, the device will be recognized and will ask for a driver. Next you need to specify the path to the folder with the files, and everything will work.
The U2 microcontroller program was written by me in the AVRStudio environment in assembly language. The block diagram of the MK operation algorithm is presented in Figure 4. The UART hardware module should be configured to interrupt upon completion of data reception. The MK itself will not perform any functions until an interruption occurs. To reduce power consumption, you can use the sleep mode, but in this design this was not necessary. As soon as commands are sent from the PC terminal, the MK will instantly begin scanning them. Currently the controller supports the following system commands:
-on1, on2, on3, on4, on5, on6, on7, on8- commands for setting ports to “log. 1";
-off1, off2, off3, off4, off5, off6, off7, off8- commands for setting ports to “log. 0";
-ser - set all ports to the active “log” state. 1";
-clr- reset all ports to “log.0” state.
After finishing entering each command, you must press Enter. This way the MK will be able to determine the end of the command and begin scanning it. The controller will respond “ok” to every correct command. If you enter incorrect data, “error” will be returned to the terminal line. An example of the command execution is shown in Figure 5.
Firmware version 1.0. It is necessary to set fuses in accordance with Figure 6. The next version of the firmware is being developed, where the MK will self-learn and change the command systems in the terminal.
MK software, Proteus virtual model and driver for PC -
Data transfer protocol between MK and PC - download