程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Software use cases in micropython kernel development notebook: ADC related experiments

編輯:Python

Jane Medium : This paper gives MicroPython Kernel Development Notes : Experimental tasks are embedded in the book Medium ADC Some contents of software use cases .

key word MicroPython,MM32F3277

The contents of the manuscript Objective record
Contents
Basic experiments ADC,DAC Joint experiments total junction Existing problems

 

  • The contents of this manuscript belong to MicroPython Kernel Development Notes : Experimental tasks are embedded in the book The content in .

Software use case :
This part of the manuscript includes :
1.
2.

  • Position in manuscript :

 

§01 book Draft content


stay MM32F3277 in ADC in total Yes 16 Channels , The corresponding external ports are :

ADC The port corresponding to the channel :
CH0~7:PA0 ~ PA7
CH8,CH9: PB0, PB1
CH10~CH13:PC0 ~ PC3
CH14,CH15:NULL

One 、 Basic experiments

1、 Read ADC0 voltage

The following code reads ADC0 passageway , Corresponding PA0 Voltage on the pin . Please note that , first ADC When initializing , Need to put init=True Parameters are substituted into .

Read ADC The conversion value is through read_u16() function , It returns 0 ~ 0xffff Value between , Corresponding ADC Input voltage from 0V To Reference voltage (3.3V) Value between .

from machine import Pin,ADC,DAC
import utime
adc0 = ADC(0, init=True)
while True:
print(adc0.read_u16())
utime.sleep_ms(200)

Through potentiometer , Manual adjustment PA0 Voltage of pin , Observe the value output by the program , It can be seen that as the input voltage increases , ADC Convert values from 0 To 0xffff change .

2、ADC Conversion rate

In the application ,ADC Conversion rate is a key parameter . The following code reads 1024 individual ADC Conversion value , Measure the total time required , Can be determined ADC Maximum conversion rate .

from machine import ADC
import time
adc0 = ADC(0, init=True)
BUF_LENGTH = 1024
buf = [0] * BUF_LENGTH
startc = time.ticks_cpu()
for i in range(BUF_LENGTH):
buf[i] = adc0.read_u16()
endc = time.ticks_cpu()
print(endc - startc)
while True:
pass

The program runs , The output is 25. This shows that through MicroPython collection 1024 individual ADC The number About the cost 25ms. therefore , The highest sampling frequency can reach 40kHz about .

Two 、ADC,DAC Joint experiments

The following code demonstrates how to start from ADC After reading the data , And then through DAC The channel outputs the signal .

from machine import DAC,ADC
import time
adc = ADC(0, init=True)
dac = DAC(0)
print("ADC to DAC .")
nowtime = time.ticks_ms()
while True:
dac.write_u16(adc.read_u16())
while True:
if time.ticks_ms() != nowtime:
nowtime = time.ticks_ms()
break

In the code time Read system time , The control sampling frequency is 1kHz.

Use a signal source , stay PA0 Pin input The frequency is 100Hz, The peak to peak is 1V, The mean for 1.5V The sine wave signal of . The input signals are shown below ADC Signals and outputs DAC The signal .

▲ chart 1.2.1 Input ADC Acquisition signal and output DAC The signal

Through the above waveform , You can see in the sine wave A cycle (10ms) Completed in 8 Time AD,DA transformation , This experimental result also verifies , At present MicroPython The kernel time There is a systematic error in the delay . The actual delay time needs to be multiplied by 1.25 times .

 

※ total junction ※


Ben This paper gives MicroPython Kernel Development Notes : Experimental tasks are embedded in the book Medium ADC Some contents of software use cases .

One 、 Existing problems

In the second experiment , Because of the need to use time Read system time , Will find , Now in this version time There is a systematic error in the reading time . The difference between the actual time 1.25 times , It is estimated that it is still in the kernel implementation , about CPU The internal reference frequency constant is not set correctly .


■ Links to related literature :

  • MicroPython Kernel Development Notes : Experimental tasks are embedded in the book

● Related chart Links :

  • chart 1.2.1 Input ADC Acquisition signal and output DAC The signal

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved