2016-09-30 09:22 AM
Since it seems like the DWT is not available for the F0 series, is the only way is to have a long loop for micro-second delay?
For example, if the F0 runs at 48MHz, if I have a loop like this: for (uint32_t idx = 0; idx<max_count; idx++) {} So approximately, what would be the value of max_count to get 1 micro-second? Thanks.2016-09-30 11:02 AM
You'd want the variable as a volatile so the compiler doesn't optimize it away. You'd need to benchmark the code, perhaps by toggling a GPIO, or counting cycles for the generated assembler.
You can program one of the TIM to clock at 1MHz and use that, or frankly use the TIM at 48 MHz, to calibrate the loop.2016-09-30 11:29 AM
Thanks for the reply.
Based on the assembly codes below, the loop takes 8 instructions. So assuming in a pipeline, each instruction takes (1/48MHz), 8 instructions in the loop would take 1.67e-7 sec. So 1usec would take 6 loop iterations. But as you suggested, using a timer is probably better. I guess the bottom line is with a 48MHz clock, there is not much resolution so it won't be that accurate anyway. 211: for (idx=0; idx < max_count; idx++) {}; 0x0800082C 9001 STR r0,[sp,#0x04] 0x0800082E 2000 MOVS r0,#0x00 0x08000830 9000 STR r0,[sp,#0x00] 0x08000832 1C40 ADDS r0,r0,#1 0x08000834 9901 LDR r1,[sp,#0x04] 0x08000836 9000 STR r0,[sp,#0x00] 0x08000838 4288 CMP r0,r1 0x0800083A D3FA BCC 0x080008322016-09-30 11:50 AM
while(count--); // might have finer granularity