cancel
Showing results for 
Search instead for 
Did you mean: 

TIM1 triggering ADC

tiago
Associate II
Posted on March 22, 2010 at 19:22

TIM1 triggering ADC

7 REPLIES 7
daviddavid94
Associate II
Posted on May 17, 2011 at 13:44

Assuming you are using the libraries :

If you have done ADC_Init(), with ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_CC1 (or whichever CC channel you are using).

And you have done :

ADC_ExternalTrigConvCmd( ADC1, ENABLE );

Then, if your SW trigger works, this should also - SW trigger working means you must have the ADC correctly set up, for the most part.

If you're already doing this, you will probably need to post some of your code.

daviddavid94
Associate II
Posted on May 17, 2011 at 13:44

Also - make sure TIM1's MOE is asserted.

tiago
Associate II
Posted on May 17, 2011 at 13:44

Hi Brian.

I'm not using ST Libraries, just using directly the registers.

I've compared some ST code examples and also that commands you just sent and I think everything is ok, my code and ST Libraries are doing the same thing. When I debug with IAR and inspect STM registers, everything is ok too.

As you mentioned, ADC is working properly and seems to me that the unique difference when triggering ADC by software or external sources is the EXTSEL field in ADC_CR2 register... So I suspect my error is on TIM1configuration, precisely on event generation that should trigger ADC.

Below the most important pieces of my code:

//######### Timer Configuration #########

    RCC_APB2ENR->TIM1EN = 1; //enable timer clock

    TIM1_CR1->CEN = 0; //disable counter

    TIM1_CR1->ARPE = 1; //auto reload

    TIM1_PSC = 500;    //Timer prescaler. clk = 10KHz

    TIM1_ARR = 0xFFFF;

    TIM1_CNT = 0xFFFF;

    //Configure channel

    TIM1_CCMR1->CC1S = 2; //IC1 mapped to CH2

    TIM1_CCMR1->IC1PSC = 0; //No prescaler

    TIM1_CCMR1->IC1F = 0; //No filter

    TIM1_CCER->CC1P = 0; //active on rising edge

    //Configure channel

    TIM1_CCMR1->CC2S = 1; //IC1 mapped to CH2

    TIM1_CCMR1->IC2PSC = 0; //No prescaler

    TIM1_CCMR1->IC2F = 0; //No filter

    TIM1_CCER->CC2P = 1;     //active on falling edge

    //Timer mode - PWM Input Capture

    TIM1_SMCR->TS = 6;     //trigger input

    TIM1_SMCR->SMS = 4;     //slave mode reset

    //Enable captures

    TIM1_CCER->CC1E = 1;

    TIM1_CCER->CC2E = 1;

    //Configure interruptions and DMA

    TIM1_DIER->CC2DE = 1; //CC2 DMA request enabled

As you suggested I enabled MOE bit, but I didn't understand why

this is needed. I'm using Input PWM mode and it seems to deal with

outputs. Sorry if I'm wrong. Anyway I tested with it and got no trigger.

    TIM1_BDTR->MOE = 1;

    //Enable timer

    TIM1_CR1->CEN = 1;

Thanks a lot for your attention.

Best regards.
daviddavid94
Associate II
Posted on May 17, 2011 at 13:44

I believe you will need to set up a compare channel (an additional one) as an *output* to trigger the ADC with. The trigger IS the output which requires MOE - I think. Not 100% sure; I have similar code to what you are doing, but I am generating a PWM signal, not detecting one, so I can trigger the ADC with my compare channel directly.

Good luck.

tiago
Associate II
Posted on May 17, 2011 at 13:44

Thanks a lot for your help Brian.

I founded other user with similar problem and he solved it like you sugested: using a pwm output. [DEAD LINK /public/STe2ecommunities/mcu/Lists/ARM%20CortexM3%20STM32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/ARM CortexM3 STM32/ADC ADC Watchdog Triggered by Timer&FolderCTID=0x01200200770978C69A1141439FE559EB459D758000626BE2B829C32145B9EB5739142DC17E&currentviews=754]See discution here.

The most weird thing it seems to be an information inexistent in datasheet...

Datasheet error? Bad interpretation?

If anyone could explain this many would be greatfull....

damh
Associate II
Posted on May 17, 2011 at 13:44

In general look at the images instead of the text in the stm datasheets. The text doesn't even mention many hard facts like this feature in this thread. The images have been ok for me yet. Nothing is so unspecific or changeable like the text says. Many hardware parts ONLY work in exactly ONE way. If you choose an other way, i doesn't work ;)

Tomas DRESLER
Senior II
Posted on May 17, 2011 at 13:44

Use the FW library and examples, if only for setup, it helps :)

When all is done, you can change anything in registers and avoid lot of troubles.