2014-10-29 06:09 AM
I have previously used a timer for triggering ADC for sampling using the standard peripheral library. I am now trying out the STM32CubeMX GUI and generating code from it to be used with Keil. I am working on the STM32F429DISCOVERY board.
I get the timer IRQ/ISR running, but the ADC is not triggered. I have read in the ref. manual that timer4 ch4 can be used to trigger a regular group conversion on the ADC. This is what I am trying to do.What kind of mode is needed to trigger ADC? I can not find any information about this in the reference manual... I used a STM32F103VC earlier and it had to be put in PWM mode (also not explained in the reference manual).Looking on page 577 in the STM32F429 ref. manual there is a figure ''Figure 134. General-purpose timer block diagram'' and as far as I can see there is no interrupt from the capture compare that can trigger the TRGO output that is connected to the ADC.But the ADC says that it can be trigger on a capture compare event.I have tried comparing with the STMF4 Standard Peripheral Library examples, but no luck.I have tried output compare mode, PWM and time base without luck.Anyone been able to use the STM32CubeMX to generate a working example? I would appreciate a .ioc file with a working setup or some more information if possible. I see this question has been asked before when using the standard peripheral library, but not using STM32CubeMX.2014-10-31 05:51 AM
Anyone been able to use the STM32CubeMX to generate a working example?
The CubeMX generates the initialization code, not the whole project. This has to be customized depending on your expected application case.Did you checked the examples provided in the STM32CubeF4 package?-Mayla-To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2014-11-03 08:46 AM
I know the CubeMX only does the initilaization code and that I have to e.g. do HAL_TIM_Start() and implement the callback functions etc, but this has nothing to do with the fact that it is not explained anywhere what mode the ADC/TIM has to be set to in order to use the timer to trigger ADC conversions...
I checked the examples. As far as I can see there is no example doing this, except using the TRGO.2015-02-27 05:14 AM
Hi Phataas,
The configuration from CubeMX of ADC triggered by timer is working correctly. You need to set: - ADC: - external trigger conversion edge: rising edge (or falling edge) - external trigger conversion source: TIM2 TRGO - Timer: - Trigger output update Please find attached an example running on STM32F4 discovery: - Files: CubeMx file (.ioc) and project files generated with IDE: IAR. Generated with CubeMX v4.4.0, FWSTM32Cube_FW_F4_V1.3.0 - Configuration: CubeMX is configuring the ADC and timer, I have added into user sections the execution functions: ADC start, timer start, leds toggle (led orange toggling on TIM2 time base set to 1s, led green is toggling every 100ms in main loop). I have also added ADC transfer by DMA: each conversion is done every 1 second, transferred by DMA into an array. DMa is circular: when transfer is complete, it starts to the beginning of buffer again. Best regards, Heisenberg. ________________ Attachments : Example_CubeMX_STM32F4Discovery_ADC_trig_timer_DMA.7z : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I0aG&d=%2Fa%2F0X0000000baq%2FhF5DLi0U7_YklgEO7eFK8Kk4j.xCnRY0XoREtbOLdGI&asPdf=false2015-05-25 10:51 PM
Thank you for sharing this!
Does the same apply if I want to read multiple ADC channels? If I have 8 channels to read then I could just define the buffer length as 8? I'm designing a BLDC motor driver and I should sense the back-emf voltages as well as user speed input, current measurements e.t.c. Also, how exactly does one configure the smart XOR'd hall-sensor reading using the timers? (for now Im' just waiting for an EXTI interrupt but it might be wiser to use that one instead, am I right?) Thank you very much, Heisenberg! Peace!