A computer control device for various devices, the diagram of which is shown in fig. 1 plugs into the computer's USB port, which is in every one of them today. The only chip of the device is a common microcontroller ATmega8. It is necessary for the organization of communication on the bus USB. Although it does not have a specialized hardware module, this function is performed by software.
Picture 1
Resistor R1, connected between the positive output of the power supply and the USB D-bus line, puts it into low-speed LS mode with an exchange rate of 1.5 Mbps, which allows you to decrypt computer messages programmatically. Resistors R4 and R5 eliminate transients that occur during the exchange of information, which increases the stability of the work. Capacitor C1 blocks impulse noise in the power circuit, which also improves the stability of the device. Diodes VD1 and VD2 serve 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 - the voltage is about 3.4 V. The low level voltage is close to zero. The outputs can be connected to devices that consume a current of not more than 10 mA (from each output). If large values of current or voltage are required, then matching nodes should be used.
The device is assembled on a prototyping board, a printed circuit board was not developed. MLT resistors, capacitors C2 and C3 - high-frequency ceramic capacitors, C1 - K50-35 or similar imported ones are used. 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. The library used to work with the USB bus swusb.LBX, which performs real-time software decoding of USB signals. The program code obtained as a result of compilation 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
The first time you connect your device to your computer, the operating system will detect a new USB HID compatible device named " uniUSB" and install the necessary drivers. In a few seconds, the device is configured and ready for use. The UniUSB program was created to work with it. It is presented 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, Windows 7, and the 64-bit version has been tested only on Windows XP x64.
Program UniUSB written in language PureBasic(version 4.31) using the user-defined functions library HID_Lib supporting work with USB HID devices. The appearance of 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 is started, the data from the file is loaded into the table located in the main window, and when the work is completed, it is saved in the file. Clicking the left mouse button on the table cells allows you to change their state: 1 - high logical level, 0 or empty - low logical level.
To add or remove a table column, right-click on it and select the required action from the menu that appears. When you connect a device to the USB port, the program will detect it and activate the "Start" button located at the top of the window on the toolbar. Pressing this button starts the process of iterating through the columns of the table and setting the states of the outputs indicated in them. For greater clarity, the numbers of outputs that are currently set to a high logic level are highlighted to the left of the table. The search speed (time in milliseconds between transitions from column to column) is set in the "Speed, ms" field.
Please note that the Windows operating system is multitasking! This means that the 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, one should not expect great accuracy in maintaining time intervals of less than 100 ms.
To briefly stop iterating through columns, use the "Pause" button. Pressing it again will continue the iteration from where it stopped. The "Stop" button completely stops iterating over the columns of the table. If the communication between the computer and the device fails or the device is disconnected from the computer's USB connector, the program will report an error by displaying an appropriate 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 the microcontroller (MC) can communicate with external devices. If you need to connect the MK to a personal computer or laptop, then we can say with confidence 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-established programs designed to work with the COM port. Since MK signals have TTL levels, a level converter is required to match the RS-232 interface. It is often performed on the basis of 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. With the help of this complex, you can control the light, TV and other devices. Executing devices do not have to be in close proximity to the PC.
The device consists of quite affordable and common elements. Both microcircuits are ATtiny2313 microcontrollers of the . The first controller is connected to the computer's USB port and functions as a USB-COM format converter. The second connects to the first and scans all the time commands that are sent from the PC through the terminal program Terminal v1.9b.
Resistor R4 connected to USB pin 2 puts the device in low-speed LS mode, which allows decoding messages from a PC when exchanging data at a speed of 1.5 Mbps using the program.
With the help of resistors R2 and R3, transients are eliminated. Capacitor C5 blocks impulse noise in the power circuit. Zener diodes D1 and D2 are needed to match the logic 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 equal to 12 and 4 MHz.
Pull-up resistors should be connected to the /RESET pins in order to avoid arbitrary reset of the MK in the future due to the influence of interference and static voltages. In this scheme, all commands are displayed on the LEDs connected to port B. To control any devices, it is necessary to connect the controller outputs to the relay (Figure 2).
You can assemble the device on a breadboard, although it is better, nevertheless, on a full-fledged printed circuit board. Elements can be placed, for example, as shown in Figure 3.
The program for the U1 microcontroller was developed by GetChiper in the Bascom-AVR environment. The library 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 your hard drive. The first time you connect, 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 MC operation algorithm is shown in Figure 4. The UART hardware module should be configured to interrupt when data is received. The MK itself will not perform any function until an interrupt occurs. To reduce power consumption, you can use the sleep mode, but in this design it was not necessary to do this. As soon as commands follow from the PC terminal, the MK will instantly move on to scanning them. The controller currently supports the following command system:
-on1, on2, on3, on4, on5, on6, on7, on8- commands for setting ports in "log. one";
-off1, off2, off3, off4, off5, off6, off7, off8- commands for setting ports in "log. 0";
-ser - set all ports to active state "log. one";
-clr- reset all ports to "log.0" state.
After finishing entering each command, press Enter. Thus, the MK will be able to determine the end of the command and start scanning it. For each correct command, the controller will respond with “ok”. If you enter incorrect data, then "error" will be returned to the terminal line. An example of command execution is shown in Figure 5.
Firmware version 1.0. It is necessary to set the fuses in accordance with Figure 6. The next firmware version is being developed, where the MC self-learning and changing the command systems in the terminal will take place.
MK software, Proteus virtual model and PC driver -
Data transfer protocol between MK and PC - download