[GoRK3288] 6. TSADC operation method, gork32886.tsadc

Source: Internet
Author: User

[GoRK3288] 6. TSADC operation method, gork32886.tsadc
Download the GoRK3288 open source library from https://github.com/tjcfeng/gork3288.

Rockchip RK3288 has a lot of ADC, HS-ADC (High Speed ADC), TS-ADC (Temperature Sensor ADC ).
The HS-ADC is mainly used to transmit data, such as the GPS data said in the manual; and TS-ADC as the name suggests, is to collect a variety of temperature sensor data.
Let's start with a simple one, so we try to use a TS-ADC to get a variety of temperatures.
Since the temperature sensor is integrated in the CPU, no external hardware module or Development Board is required in this experiment, and the results are obtained directly through the program.

Let's take a look at the sample program.



This time, the program is simpler. It is enough to simply use three statements. But is this code slightly different from the C language? There are actually two main points here, as mentioned earlier: Singleton mode and multiple return values.
 
1. Singleton mode:
In the design mode, the singleton mode is used to create a class only once during the running of the program, in this case, an existing instance is returned instead of being created again. Don't be held down by such advanced names. You just need to understand it as a global variable. In general static languages, this method is implemented in constructor. However, the Go language is a special case and it does not have constructor, so I can only use a common function to replace the constructor.
The reason for using TSADC classes as a singleton is that in RK3288, although TSADC has four channels, they only have one group of registers controlled by them, you cannot control each channel separately, that is, to start and stop the channel together. To avoid Operation conflicts between multiple instantiations, I think the singleton mode is more suitable for TSADC.

2. Multiple return values:
Multiple return values are a major feature of the Go language, which is not available in other static languages. In addition, for TSADC, data from the four channels is collected together and results can be obtained at the same time, rather than completed one by one. Therefore, it is easier to use multiple return values. In fact, this write is intended to highlight the language characteristics, and this was just changed before writing this section. The original method is to pass standard parameters to obtain the specified results. These two methods do not matter. If you are not used to them, you can add a function for the specified channel.

After talking about this, let's go back to the topic. In the code, RK3288.ITSADC () is an instance of the TS-ADC class, if there is no other place to use this instance, you can directly call the method function GetData ().
Look at the first half of the function. _, Data, _, _ is the variable that saves the result. _ is the result that you don't care about. You can leave the value empty, but it must be placeholder.
The meaning of the entire statement is to get the results of the TS-ADC 1st channel, get the results of the four channels should be written
Data1, Data2, Data3, Data4: = RK3288.ITSADC (). GetData ()
Is the Go language very interesting?

The following is simple, the TS-ADC is 12-bit, the result of Data storage is the ADC Data, the use of the GetTemperature function to convert this Data to the temperature value is the final result.
In fact, the change between the value and the temperature is not linear, so the manual provides a ing table.


The temperature can be obtained by converting the ing table. For more information, see TSADC. go.

Run the program and check the result.


The CPU temperature is 33. x, which is not accurate.

There is another problem. The manual shows that channel 1 is the CPU temperature and Channel 2 is the GPU temperature, but the data obtained from Channel 2 is always 0. I don't know why, if you have time, ask Firefly experts.



To sum up the methods of the TSADC class:
ITSADC: obtains the TASDC instance.
FreeTSADC: Release TSADC
GetData: Obtain ADC data (multiple return values)
GetTemperature: Convert the ADC data to a temperature value (retain one decimal part)

Download the GoRK3288 library at https://github.com/tjcfeng/gork3288.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.