cancel
Showing results for 
Search instead for 
Did you mean: 

Triggering ADC 1 with Timer 1 (STM32F103)

nonestforum
Associate
Posted on October 05, 2016 at 08:42

 

 

The original post was too long to process during our migration. Please click on the attachment to read the original post.
2 REPLIES 2
nonestforum
Associate
Posted on October 05, 2016 at 12:11

It seems that I misinterpreted some things.

The scope shows the debug output pin set on compare and reset on EOC - but the conversion is actually started just before that with the PWM positive edge (as cited in previous post), not as intended on compare. Achieving the intended timing with CC2 seems to require it to be set to generate a rising edge to start AD conversion:

1.
TIM_OC_InitStructure.TIM_OCMode = TIM_OCMode_PWM1; 
// <--- !
2.
TIM_OC_InitStructure.TIM_OutputState = TIM_OutputState_Enable; 
// <--- !
3.
TIM_OC_InitStructure.TIM_OutputNState = TIM_OutputNState_Disable;
4.
TIM_OC_InitStructure.TIM_OCPolarity = TIM_OCPolarity_Low; 
// <--- !
5.
TIM_OC_InitStructure.TIM_OCNPolarity = TIM_OCPolarity_High;
6.
TIM_OC_InitStructure.TIM_OCIdleState = TIM_OCIdleState_Set; 
// <--- !
7.
TIM_OC_InitStructure.TIM_OCNIdleState = TIM_OCNIdleState_Reset;
8.
TIM_OC_InitStructure.TIM_Pulse = 511;

The timer output TIM1_CH2 is an alternate function on PA9, conflicting with USART1_TX. This would mean that there is no ''internal signal'', and that the reference manual is misleading in describing it as such:

TIM1_CC2 event

Internal signal from on-chip timers I could not find further information about this mysterious internal connection. The only mentions of ''

TIM1_CC2

'' or ''CC2 event'' are in that section. It probably should read ''TIMx_CCn output (TIMx_CHn) rising edge'' and ''output signal from on-chip timer''. I am a bit perplexed that it does not seem possible to start conversion directly on the actual CC event. I'd be grateful if someone could clarify and/or point to proper documentation. Here are other threads that seem to have the same issue: https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=https%3a%2f%2fmy%2est%2ecom%2fpublic%2fSTe2ecommunities%2fmcu%2fLists%2fcortex%5fmx%5fstm32%2fCannot%20for%20the%20life%20of%20me%20get%20TIM2%20to%20trigger%20ADC1&FolderCTID=0x01200200770978C69A1141439FE559EB4... https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=https%3a%2f%2fmy%2est%2ecom%2fpublic%2fSTe2ecommunities%2fmcu%2fLists%2fcortex%5fmx%5fstm32%2fActive%20ADC%20with%20TIM3%20not%20operate&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77... And this one specifically asks if the timer output has to be enabled to trigger the ADC - unfortunately, no conclusive answer: https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2Fcortex%5Fmx%5Fstm32%2FTriggering%20ADC%20from%20Timer%2E%20%20Does%20timer%20output%20have%20to%20be%20enabled&FolderCTID=0x01200200770978C69A1141439FE559EB459D758000... Another indicator that I might not be doing anything wrong, but that this is by design:

I used a STM32F103VC earlier and it had to be put in PWM mode (also not explained in the reference manual).

https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=https%3a%2f%2fmy%2est%2ecom%2fpublic%2fSTe2ecommunities%2fmcu%2fLists%2fcortex%5fmx%5fstm32%2fUse%20timer%20to%20trigger%20ADC%20sampling%20using%20STM32CubeMX%20generated%20code&FolderCTID=0x01200200770978C69A1...
Walid FTITI_O
Senior II
Posted on October 05, 2016 at 19:46

Hi none, 

Did you tried to run the example ''TIMTrigger_AutoInjection'' in the

http://www.st.com/content/st_com/en/products/embedded-software/mcus-embedded-software/stm32-embedded-software/stm32-standard-peripheral-libraries/stsw-stm32054.html

at this path:  STM32F10x_StdPeriph_Lib_V3.5.0\Project\STM32F10x_StdPeriph_Examples\ADC\TIMTrigger_AutoInjection

-Hannibal-