Open hywing opened 6 months ago
board : psoc6-evaluationkit-062S2 bsp : PSOC62-IFX-EVAL-KIT 1.1.1 rt-thread : 5.0.1 RT-Thread Studio : 2.2.6
rt_thread_t Adc_thread = RT_NULL;
static void Adc_entry(void* paremeter);
int main(void) { Adc_thread = rt_thread_create("adc1", Adc_entry, RT_NULL, 512, 16, 20); if(Adc_thread != RT_NULL) rt_thread_startup(Adc_thread); else return -1; }
static void Adc_entry(void paremeter) { rt_adc_device_t adc_dev; rt_uint32_t value,vol; rt_err_t ret = RT_EOK; adc_dev = (rt_adc_device_t)rt_device_find(ADC_DEV_NAME); if (adc_dev == RT_NULL) { rt_kprintf("adc sample run failed! can't find %s device!\n", ADC_DEV_NAME); } ret = rt_adc_enable(adc_dev, ADC_DEV_CHANNEL); if(ret == RT_EOK) { rt_kprintf("adc sample run success! find %s device!\n", ADC_DEV_NAME); } while(1) { value = rt_adc_read(adc_dev, ADC_DEV_CHANNEL); rt_kprintf("the value is :%d \n", value); vol = value REFER_VOLTAGE / CONVERT_BITS; rt_kprintf("the voltage is :%d.%02d \n", vol / 100, vol % 100); rt_thread_delay(500); } }
The ADC config is initialized as 12-bit resolution and I connect ADC0 (P10_0) with VDD
The return value (2047) is not right which is half of 4096 (3.3V)
The truth is that function cyhal_adc_read_uv gets the right value of 3.3V instead of cyhal_adc_read
Environment
board : psoc6-evaluationkit-062S2 bsp : PSOC62-IFX-EVAL-KIT 1.1.1 rt-thread : 5.0.1 RT-Thread Studio : 2.2.6
I had a problem when I tried to run this code below
include
define DBG_TAG "main"
define DBG_LVL DBG_LOG
include
include
include
define ADC_DEV_NAME "adc1"
define ADC_DEV_CHANNEL 0
define REFER_VOLTAGE 330
define CONVERT_BITS (1 << 12)
rt_thread_t Adc_thread = RT_NULL;
static void Adc_entry(void* paremeter);
int main(void) { Adc_thread = rt_thread_create("adc1", Adc_entry, RT_NULL, 512, 16, 20); if(Adc_thread != RT_NULL) rt_thread_startup(Adc_thread); else return -1; }
static void Adc_entry(void paremeter) { rt_adc_device_t adc_dev; rt_uint32_t value,vol; rt_err_t ret = RT_EOK; adc_dev = (rt_adc_device_t)rt_device_find(ADC_DEV_NAME); if (adc_dev == RT_NULL) { rt_kprintf("adc sample run failed! can't find %s device!\n", ADC_DEV_NAME); } ret = rt_adc_enable(adc_dev, ADC_DEV_CHANNEL); if(ret == RT_EOK) { rt_kprintf("adc sample run success! find %s device!\n", ADC_DEV_NAME); } while(1) { value = rt_adc_read(adc_dev, ADC_DEV_CHANNEL); rt_kprintf("the value is :%d \n", value); vol = value REFER_VOLTAGE / CONVERT_BITS; rt_kprintf("the voltage is :%d.%02d \n", vol / 100, vol % 100); rt_thread_delay(500); } }
My Config
The ADC config is initialized as 12-bit resolution and I connect ADC0 (P10_0) with VDD![image](https://github.com/RT-Thread/rt-thread/assets/119030662/e325907c-4a28-4d4b-af85-0fd994cc4327)
Result
The return value (2047) is not right which is half of 4096 (3.3V)![image](https://github.com/RT-Thread/rt-thread/assets/119030662/2e79ca79-204b-463f-b4a5-87d7a97d47b4)