Raspberry Pico上有四個 ADC 可用
- ADC0 引腳 31 (GP26)
- ADC1 引腳 32 (GP27)
- ADC2 引腳 34 (GP28)
ADC 引腳的輸入電壓范圍為 0V ..3.3V
此外,還有另一個板載 ADC 輸入(ADC4),它連接到芯片上的溫度傳感器。
在lazarus建個控制臺應用
此示例說明如何讀取模擬引腳(ADC0)和內部傳感器(ADC4)。
program adc; {$MODE OBJFPC} {$H+} {$MEMORY 10000,10000} uses pico_gpio_c, pico_adc_c, pico_timer_c, pico_c; var milliVolts,milliCelsius : longWord; begin adc_init; // Make sure GPIO is high-impedance, no pullups etc adc_gpio_init(TPicoPin.ADC0); // Turn on the Temperature sensor adc_set_temp_sensor_enabled(true); repeat // Select ADC input 0 (GPIO26) adc_select_input(0); // For now we avoid floating point, there have been fixes done on FPC trunk which are yet to be verified milliVolts := (adc_read * 3300) div 4096; // Select internal temperature sensor adc_select_input(4); milliVolts := (adc_read * 3300) div 4096; //Temperature formula is : T = 27 - (ADC_voltage - 0.706)/0.001721 milliCelsius := 27000-(milliVolts-706)*581; busy_wait_us_32(500000); until 1=0; end.
對 ADC 進行編程時,或多或少只有一件事需要注意,引腳配置了它們的 GPIO 值(26、27、28),但在選擇 ADC 輸入時,我們需要按名稱引用 ADC 輸入
- ADC0 --> 0
- ADC1 --> 1
- ADC2 --> 2
- ADC4 --> 4

浙公網安備 33010602011771號