wwfeldman
Advanced Member level 4
- Joined
- Jan 25, 2019
- Messages
- 1,125
- Helped
- 232
- Reputation
- 463
- Reaction score
- 302
- Trophy points
- 83
- Activity points
- 8,806
Hello,
I want to setup a 1MHz timer with STM32F767. I picked TIM4 (APB1 Timer Clock=108MHz; APB1 Peripheral Clock=54MHz) for this purpose, based on my calculation prescaler should be 108-1, and a counter period 2-1. But I get maximum 113.64kHz. So, does anyone have an idea to set as 1MHz?
i am not very familiar with STM32F767
please explain notation 108-1 and 2-1 in
calculation prescaler should be 108-1, and a counter period 2-1.
please explain your calculation that got you to these values from wherever you started (108MHz or 54MHz ?)
fclock_cnt=108MHz/107+1=1MHz
Counting period=(1+1)*(1/1MHz)=0.2us period
* I get the formulas from a source book (Embedded Systems by Yifeng Zhu)
Are you using STM32 cubeMX?
SPI4 set as Full-duplex Master
SPI4 NSS as Hardware output
RCC as High Crystal Clock
In clock settings, 8MHz, HSE, PLLCLK, and SYSCLK as 160MHz.
In SPI4 configuration, Motorola, 16 bits, MSB, 4, 20Mbits/s, Low, 1 edge, sequentially.
DMA is not enabled.
SPI4 global interrupt enabled.
Variables:
uint8_t i; // The index number of the testdata_in array
uint16_t Sample;
float volt=0; // Decimal value of the conversion
uint8_t ADC_Buf[2]; // Output of ADC
float testdata_in[60]; // 16 different ADC values in this array
Main code calls in main.c file,
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
HAL_SPI_Receive_IT(&hspi4,ADC_Buf, 2);
while(HAL_SPI_GetState(&hspi4) != HAL_SPI_STATE_READY);
Sample = (((uint16_t) ADC_Buf[1]) << 8 | ADC_Buf[0]) & 0x0FFF;
volt = (float)(Sample * (3.3 / 4096.0)); //
testdata_in[i++]=volt;
i %= 60;
}
void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef *hspi)
{
printf("End InterrupTXRX\r\n");
}
/* USER CODE BEGIN 2 */
spidata[0]=0x00; // Set everything up before you start the exchange
spidata[1]=0x00;
HAL_SPI_TransmitReceive_DMA(&hspi4,spidata,ADC_Buf,2);
Sample = (((uint16_t) ADC_Buf[1]) << 8 | ADC_Buf[0]) & 0x0FFF;
volt = (float)(Sample * (3.3 / 4096.0)); //
testdata_in[i++]=volt;
i %= 60;
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?