This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

delay in keil

hi , suppose i want to plot a sine wave of frequency 50hz in logic analyser of keil microvision 4 using any pin of corresponding adc1 input. FOR THIS to plot i have to set delay .can anyone tell me , how to calculate that delay time?? I am using stm32f103-eval

  • You'd pace the ADC with one TIM units, and record to an array with DMA. You'd want a sample rate sufficient to capture the input with the desired clarity. Do you want 10 points on each cycle of the sine wave, or 100?

  • hi , thank u sir, I am using dma interrupt to store adc value.my array size is 1024. i want to plot 1024 points in one second giving 50 hz sine wave. But I am getting at around 52 hz .I am using simple for() delay to reduce adc sampling rate. Is their any way to tackle adc sampling rate ?

  • Software spin loops are a very crude way of doing delays. You'd need to play with the iterations to get the rate you want, would suggest using a toggling GPIO to calibrate the delay if you insist on that route. You'd want the loop counter to be volatile so that the compiler does not eliminate the code.

    You need a sample rate of 51.2 KHz (50 Hz x 1024 samples), that's not cleanly divisible into 72 MHz, but would be into 64 MHz. One could trigger the ADC/DMA by using a period of 1250 ticks of the 64 MHz system clock.

  • hi sir ,
    Thanks again .I am asking a very silly question .I have taken the array size 1024. and for execution it is taking 1 sec .then my sampling rate must be 1024 .IS that so ??(I am giving input signal 50hz)

  • Requirement :- 50Hz
    No. of points to be plotted in 1 sec :- 1000 (taking a multiple of 50 to make calculations easier)
    Time delay after which each Start Of Conversion must triggered = 1mSec

    Now trigger the ADC conversion at 1msec time interval.

    Use a timer to generate delay (software delay is unreliable and stochastic). And in the timer interrupt, start ADC conversion.