Case

The successful case of the application of PADAUK Technology microcontroller PS173 microcontroller

In the case of the successful application of the PADAUK Technology single-chip microcontroller PS173 microcontroller as an encoder counter, by reading when each signal changes and tracking which signal changes first, the counting on the encoder can accurately increment or decrement.


Even in the field of microcontrollers, a microcontroller with a single unit of $0.03 is very strange. It is extremely cheap. The cheapest single-piece microcontroller that you can find in online distributors such as Digikey or Mouser usually has to reach thousands in the area below 1. Topushit. From an angle, it is an unknown smart phone in a 6inaworldof.
Thoughts


The author spent about two days in total to become familiar with the functions and debug the code. If used frequently, programming and soldering the IC can be shortened to a few hours.


For the author, having such an extremely cheap microcontroller as a general-purpose IC is very useful and can replace more specialized components or devices. The author likes it because it is cheap, easy to solder, easy to understand, and program.

The successful case of the application of PADAUK Technology microcontroller PS173 microcontroller(图1)

A few years ago, the author studied these ICs and made some explorations to explore their uses. Since then, there has been better documentation in the IDE, the cost of the IC has increased by 4 times (!), and the open-source toolchain (SDCC) has become more mature.


This time, the author wants to use this IC as an encoding counter.

The successful case of the application of PADAUK Technology microcontroller PS173 microcontroller(图2)

PADAUK Technology single-chip microcontroller PS173 counting signal. Tracking encoder counts is an important activity. Encoders are often used to track angular positions, and this information is used to track information such as the speed at which the wheel is rotating or the distance the print head of the printer has advanced.


However, encoder counting is also very busy. Imagine that you have to stare at the screen that displays two variables of 1 or 0. By tracking the frequency and sequence of the appearance of 1 or 0, you can know the position of the encoder and its rotation direction. You can stare at the screen all day, which means you can't do anything else... or you can set a notification to tell you when each variable changes.

The successful case of the application of PADAUK Technology microcontroller PS173 microcontroller(图3)

Microcontrollers do not use notifications, but use interrupts to ensure that they do not miss counts. However, counting hundreds of times per second, besides servicing the interrupt, you may not be able to perform any other operations, which is why some (read: expensive) chips have dedicated encoder modules, which can free the main controller to perform other operations, such as reading control signals or sending data.


Not all microcontrollers have this module, which is where the Padauk microcontroller comes in.


PADAUK Technology single-chip microcontroller PS173 input/output


Concept


This concept is very simple: use the Padauk microcontroller to complete the tedious work of reading the encoder, and then provide a simple way for another microcontroller to access the count.

The successful case of the application of PADAUK Technology microcontroller PS173 microcontroller(图4)

The author decided to adopt two methods to read the count. SPI obtains precise counts from the microcontroller, and a 2-pin count/direction control scheme suitable for applications with lower position requirements: The Padauk microcontroller will output a pulse through one pin when it detects the rotation of the encoder and indicates the direction of the rotation of the encoder using another pin of the encoder.


The working principle of the PADAUK Technology single-chip microcontroller PS173 rotary encoder.

The successful case of the application of PADAUK Technology microcontroller PS173 microcontroller(图5)

The rotary encoder works by outputting Gray code. It is a pair of signals that indicate the number of turns of the knob and the direction.

The successful case of the application of PADAUK Technology microcontroller PS173 microcontroller(图6)

By reading when each signal changes and tracking which signal changes first, the count on the encoder can be accurately incremented or decremented.

The successful case of the application of PADAUK Technology microcontroller PS173 microcontroller(图7)

The wiring of the encoder is also quite simple, and there are pull-up resistors on each channel.


PADAUK Technology single-chip microcontroller PS173 encoding simulation IC


The author tested the code on the Padauk simulator. The author found that the debugging experience was very useful for fixing some errors in the logic. When you step through, the Padauk IDE will automatically display all registers and their current states, as well as the variable values in each section of the code.

The successful case of the application of PADAUK Technology microcontroller PS173 microcontroller(图8)

Because the instruction set of the Padauk IC is very small, all contents can be displayed on the IDE. One thing the author doesn't like is that the documentation of Mini-C is scattered in the application notes in the IDE and the data sheet of the IC.


In the code, the author sets up two interrupts to read the Gray code from the encoder and store it in the global variable. This global variable can be incremented and decremented.


Binary complement


The PADAUK Technology single-chip microcontroller PS173 Mini-C has no concept of negative numbers, and negative numbers are usually implemented in the form of binary complement.


The successful case of the application of PADAUK Technology microcontroller PS173 microcontroller(图9)This method is consistent with the logic of binary and arithmetic operations, so it is a very useful way to represent negative numbers. However, since the author is more interested in the relative position of the encoder, negative values are not needed, and another way to achieve this purpose is to initialize the value in the middle of the range.

The successful case of the application of PADAUK Technology microcontroller PS173 microcontroller(图10)

If the authors started from scratch and did not implement the binary complement, the value would roll back from 0 to 100, which is not desirable. Instead, the author starts the value from the middle of the range, which allows it to decrease and increment normally. All the author has to do is track the initial value and reset it before it flips.


Programming the IC


When you click on "Programming", Padauk's programmer saves the binary file to the programmer's memory so that you can use it as a stand-alone device or trigger the download process from the computer.


The successful case of the application of PADAUK Technology microcontroller PS173 microcontroller(图11)

The PFS173 used by the author supports multiple times programming (MTP), and it performs the operation according to the instructions on the cover, allowing multiple programming. There are also other Padauk ICs that can only be programmed once, such as PMC150.

The successful case of the application of PADAUK Technology microcontroller PS173 microcontroller(图12)

Put all the content together

In this process, the author added some other functions, such as the board being able to act as the main controller, not just interpret the encoder signal, and being able to save the last set PWM value when turning off or on. When the author was quite satisfied with the result, the author moved it to the dedicated board of the author's main project.


The successful case of the application of PADAUK Technology microcontroller PS173 microcontroller(图13)

Thoughts


The author spent about two days in total to become familiar with the functions and debug the code. If used frequently, programming and soldering the IC can be shortened to a few hours.


For the author, having such an extremely cheap microcontroller as a general-purpose IC is very useful and can replace more specialized components or devices. The author likes it because it is cheap, easy to solder, easy to understand, and program.


Categories

News

Contact Us

Contact: Tianheng Technology

Phone: +8613265876004

Tel: +8675583041117

E-mail: jaycha5574842@qq.com

Add: Shenzhen City, Guangdong Province, China