cancel
Showing results for 
Search instead for 
Did you mean: 

How to create delay in nanosecond?

MDeva.1
Associate II

Hello,

I am working on Nucleo-H745ZIQ board. My cortex M7 running on 400MHZ and My Cortex M4 work on 200MHZ. I am interfacing the ADS7046 for that I need 450ns delay for conversion. The systick generate delay in millisecond. How I create delay in nanosecond .

5 REPLIES 5
Danish1
Lead II

I've just had a quick look at the data-sheet for that device. Conversions don't seem to take a specific time-duration, but rather a certain number of clock-cycles from a clock that you have to provide.

Is that ADC interfaced over SPI? If so, each 16-bit SPI read would trigger a conversion and return the result of the previous conversion.

The only timing you need to do is set up the clock for SPI.

If you do want to create a delay in ns, then a TIM block is best. But I don't think you need to.

Hope this helps,

Danish

Can't use interrupts.

Could use spin loops looking at how a maximal free running TIM count advances or same with DWT CYCCNT​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Hello,

Yes it is SPI compatible ADC.I need to read the 15bits data. Maximum frequency of SPI is 60MHZ and ADC Sampling freq is 3 MHZ.I set the SPI baudraete of

37Mbits/second .But the cs falling and rising edge according to I calculate I required 485ns.How I given this time to it. In SPI function HAL_SPI_Receive(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size, uint32_t Timeout) the last parameter of timeout how much time I have to assign can you please help me

Danish1
Lead II

Do you know what that timeout parameter actually does? I think it aborts the transfer if it is taking much longer than expected, so it isn't needed under "normal" operation.

My guess is that since the timing of SPI is entirely driven by the SPI clock and you're in control of that, you don't need to set any timeout i.e. put in 0.

The first time you call HAL_SPI_Receive() you will get a dummy value. You need to call it a second time to get the ADC conversion as the ADC's reply is always one sample behind.

(It's different if e.g. you're using I2C, where a different bus master might be hogging the bus so your stm32 might be waiting forever).

Hope this helps,

Danish

I am make the configuration below is it right or I have to making the changes

float ADS7046Setup(void)

{

uint16_t ADC_Value;

const float maxAdcBits = 4095.0f; // Using Float for clarity

const float maxVolts = 3.3f;   // Using Float for clarity

const float voltsPerBit = (maxVolts / maxAdcBits);

HAL_GPIO_WritePin(GPIOF, ADC_IS_CS_N_Pin, GPIO_PIN_RESET);

if(HAL_OK!=HAL_SPI_Receive(&hspi5,(uint8_t *) &ADC_Value, 1, 0))

{

  printf("Error In SPI_5 Receiving\n\r");

}

HAL_GPIO_WritePin(GPIOF, ADC_IS_CS_N_Pin, GPIO_PIN_SET);

float ADCVoltage = ADC_Value * voltsPerBit;

  return ADCVoltage;

}

0693W00000HoZ8XQAV.png0693W00000HoZ7yQAF.png