A simple question about generating us delay

⚠️
Hi there.. thanks for coming to the forums. Exciting news! we’re now in the process of moving to our new forum platform that will offer better functionality and is contained within the main Dialog website. All posts and accounts have been migrated. We’re now accepting traffic on the new forum only - please POST any new threads at//www.xmece.com/support. We’ll be fixing bugs / optimising the searching and tagging over the coming days.
2 posts / 0 new
Last post
sentimental
Offline
Last seen:2年12个月前
加入:2016-11-28 15:55
A simple question about generating us delay

Hello Dialog,
I'd like to use adc at around 500~1k Hz sampling rate, which requires ~1us level time delay. The code snippet is kind of:

adc_init(GP_ADC_SE, 0, GP_ADC_ATTN3X);
adc_enable_channel(ADC_CHANNEL_P01);
for-loop:
int data = adc_get_sample();
排队(数据);
delay(1us);

Previously I use the software timer app_easy_timer but I found the minimum delay of the easy timer is 10ms which is too large. When I search for timer0 I found they are mainly for PWM, audio, etc. My question is 1) How can I generate ~1us delay? If using timer0, are there any code snippets? 2) Does timer0 work during extended sleep mode? Thanks!

Device:
MT_dialog
Offline
Last seen:3 months 13 hours ago
工作人员
加入:2015-06-08 11:34
Hi sentimental,

Hi sentimental,

Timer0 has an interrupt functionallity and you will be able to sync the ADC read using that interrupt feature, regarding how to set up the timer0 interrupt function, you can use the timer0_general example. Regarding the 1us delay (500Hz to 1KHz is 2ms and 1ms period not 1us) you can configure the timer0 to generate an interrupt with that period. Regarding the sleep, all the peripherals are shut down including the timers and the adc.

Thanks MT_dialog