2018-10-11 12:32 PM
Hi,
I'm currently trying to create a software pulse for an ADC with an stm32 device which I'm pretty new to.
I have everything working and receive data clocked via HAL_SPI_Receive, but the pulse is created via a hardware trigger and this is the only configuration I can find regarding one pulse mode.
This is the ADC I am using
http://www.analog.com/media/en/technical-documentation/data-sheets/231116fa.pdf
I am trying to generate the CNV/acquisition pulse.
I want to call a function or set a bit, etc, which internally triggers a defined pulse for the CNV pin, something similar to HAL_TIM_OC_Start()
After this I will use HAL_SPI_Receive to clock through the data and do a few other things before wanting to initiate the next pulse.
At the moment the trigger is generated though a channel on TIM1, with PWM generation on CH2 and slave mode set as trigger mode with TI1FP1 as trigger source and clock source set to internal. I can create what ever pulse I like using a hard trigger on associated pin but I want to replace this with a software call. Or alternatively achieve the same outcome, i.e a pulse, some other way. I am new to STM programming and am working with others unfamiliar with coding so want to use the HAL if possible.
Thanks
2018-10-12 05:22 AM
> At the moment the trigger is generated though a channel on TIM1, with PWM generation on CH2 and
> slave mode set as trigger mode with TI1FP1 as trigger source and clock source set to internal. I can
> create what ever pulse I like using a hard trigger on associated pin but I want to replace this with a
> software call.
Simply enable the timer, by setting TIMx_CR1.CEN. This is the same what the slave-mode controller does when a trigger pulse arrives, when the slave-mode controller is set to trigger mode.
> want to use the HAL if possible.
I don't Cube/HAL, but in [STM32Cube_FW_F4_V1.15.0]\Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_tim.h I see:
#define __HAL_TIM_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1|=(TIM_CR1_CEN))
(the comment above it, saying " * @brief Enable the TIM peripheral.", is of course incorrect, as this enables only the counter within TIM, not TIM as such).
JW
2018-10-14 03:46 PM
Hi,
Thanks for the response, I have got software pulse triggering working using "__HAL_TIM_ENABLE(&htim1)".
I have a problem with using it in the code below.
HAL_TIM_OnePulse_Start(&htim1, TIM_CHANNEL_1);
volatile uint16_t array [300];
HAL_Delay(1000); // let ADC power up
while(1)
{
for(int n=0;n<300;n++) // acquisition loop
{
if (hspi1.State != HAL_SPI_STATE_BUSY_RX)
{
__HAL_TIM_ENABLE(&htim1); //send pulse
HAL_SPI_Receive(&hspi1,(uint8_t*)array[n],1,1); //clock data
HAL_Delay(1);
}
}
}
With the HAL_Delay(1); in the loop, the pulses look fine but for some reason the HAL_SPI_Receive function isn't initiated - there are no clocks. When I remove the delay, the clock is there but the pulse output is almost inverted being high most of the time, and even runs over the receive clock?
I don't quite understand what's going on as I have the != HAL_SPI_STATE_BUSY_RX there but I don't think it's working?
Thanks