Skip to main content
maximmalenko
Associate
April 20, 2016
Question

Stm32f429 GPS PPS measuring

  • April 20, 2016
  • 13 replies
  • 3157 views
Posted on April 20, 2016 at 09:38

Hi! I try to measure GPS PPS (pulse per second) duration by TIM2. Setting code:

TIM_TimeBaseInitTypeDef TimeBaseInitStruct;
TIM_ICInitTypeDef ICInitStruct;
TimeBaseInitStruct.TIM_Prescaler = 0;
TimeBaseInitStruct.TIM_ClockDivision = TIM_CKD_DIV1;
TimeBaseInitStruct.TIM_CounterMode = TIM_CounterMode_Up;
TimeBaseInitStruct.TIM_Period = 0xFFFFFFFF;
TimeBaseInitStruct.TIM_RepetitionCounter = 0;
TIM_TimeBaseInit(PPS_IN_TIM, &TimeBaseInitStruct);
TIM_SelectInputTrigger(PPS_IN_TIM, TIM_TS_TI1FP1);
TIM_SelectMasterSlaveMode(PPS_IN_TIM, TIM_MasterSlaveMode_Enable);
TIM_SelectSlaveMode(PPS_IN_TIM, TIM_SlaveMode_Reset);
ICInitStruct.TIM_Channel = TIM_Channel_1;
ICInitStruct.TIM_ICPolarity = TIM_ICPolarity_Rising;
ICInitStruct.TIM_ICSelection = TIM_ICSelection_DirectTI;
ICInitStruct.TIM_ICPrescaler = TIM_ICPSC_DIV1;
ICInitStruct.TIM_ICFilter = 0;
TIM_ICInit(PPS_IN_TIM, &ICInitStruct);

TIM2 clk:180Mhz. In interrupt value of CCR1 stored in array. Result: 0690X000006038gQAA.jpg What caused this behavior?I apologize for not being word-perfect in English)
    This topic has been closed for replies.

    13 replies

    Walid FTITI_O
    Visitor II
    April 20, 2016
    Posted on April 20, 2016 at 11:59

    Hi malenko.maxim, 

    The description of the issue is not clear enough . Please share the hole Timer initialization code and related main function parts.Which input pin you are using (PA8 ? PE9?) and pin configuration ?. Have you configured the NVIC for timer interruption ?

    The hardware you are using and if there is any external connections ?

    -Hannibal

    Tesla DeLorean
    Guru
    April 20, 2016
    Posted on April 20, 2016 at 12:09

    I believe it is showing you the frequency and drift rate of the receivers local clock wrt the PLL clock.

    What make/model GPS receiver are you using?

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    maximmalenko
    Associate
    April 20, 2016
    Posted on April 20, 2016 at 12:34

    GPIO setting:

    #define PPS_IN_TIM TIM2
    #define PPS_IN_TIM_Handler TIM2_IRQHandler
    #define PPS_TIM_IRQn TIM2_IRQn
    #define GNSS_PPS_GPIO GPIOA
    #define GNSS_PPS_PIN GPIO_Pin_5
    #define GNSS_PPS_PIN_SOURCE GPIO_PinSource5
    #define GNSS_PPS_AF GPIO_AF_TIM2
    GPIO_InitTypeDef GPIO_InitStructure;
    GPIO_PinAFConfig(GNSS_PPS_GPIO, GNSS_PPS_PIN_SOURCE, GNSS_PPS_AF);
    GPIO_InitStructure.GPIO_Pin = GNSS_PPS_PIN;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_Init(GNSS_PPS_GPIO, &GPIO_InitStructure);

    Full timer setting:

    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2,ENABLE);
    RCC_TIMCLKPresConfig(RCC_TIMPrescActivated);
    TIM_TimeBaseInitTypeDef TimeBaseInitStruct;
    TIM_ICInitTypeDef ICInitStruct;
    TimeBaseInitStruct.TIM_Prescaler = 0;
    TimeBaseInitStruct.TIM_ClockDivision = TIM_CKD_DIV1;
    TimeBaseInitStruct.TIM_CounterMode = TIM_CounterMode_Up;
    TimeBaseInitStruct.TIM_Period = 0xFFFFFFFF;
    TimeBaseInitStruct.TIM_RepetitionCounter = 0;
    TIM_TimeBaseInit(PPS_IN_TIM, &TimeBaseInitStruct);
    TIM_SelectInputTrigger(PPS_IN_TIM, TIM_TS_TI1FP1);
    TIM_SelectMasterSlaveMode(PPS_IN_TIM, TIM_MasterSlaveMode_Enable);
    TIM_SelectSlaveMode(PPS_IN_TIM, TIM_SlaveMode_Reset);
    ICInitStruct.TIM_Channel = TIM_Channel_1;
    ICInitStruct.TIM_ICPolarity = TIM_ICPolarity_Rising;
    ICInitStruct.TIM_ICSelection = TIM_ICSelection_DirectTI;
    ICInitStruct.TIM_ICPrescaler = TIM_ICPSC_DIV1;
    ICInitStruct.TIM_ICFilter = 0;
    TIM_ICInit(PPS_IN_TIM, &ICInitStruct);
    TIM_Cmd(PPS_IN_TIM, ENABLE);
    TIM_ITConfig(PPS_IN_TIM, TIM_IT_CC1, ENABLE);
    NVIC_InitTypeDef NVIC_InitStructure;
    NVIC_InitStructure.NVIC_IRQChannel = PPS_TIM_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 11;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStructure);

    Test handler:

    uint32_t debug[128];
    uint16_t dbgCnt = 0;
    void PPS_IN_TIM_Handler()
    {
    static uint32_t ccr = 0;
    if (TIM_GetFlagStatus(PPS_IN_TIM, TIM_FLAG_CC1) == SET)
    {
    ccr = TIM_GetCapture1(PPS_IN_TIM);
    debug[dbgCnt++] = ccr;
    dbgCnt &= 0x7F;
    }
    TIM_ClearITPendingBit(PPS_IN_TIM, 0xFFFF);
    }

    I use Stm32f429 Discovery. GLONASS receiver MNP-M7, but if measure pulse from AGF3022C result exactly the same.
    Tesla DeLorean
    Guru
    April 20, 2016
    Posted on April 20, 2016 at 13:00

    You see the saw tooth on your other equipment? The output is the same as what?

    I don't see a specification for the rms error in the 1pps. I'm thinking it is not very tight. What clock drift and bias measurements is the receiver outputting with respect to the local clock?

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    maximmalenko
    Associate
    April 20, 2016
    Posted on April 20, 2016 at 13:24

    I also use Tektronix AGF3022C to generate PPS and  got the same saw tooth in debug array. 

    Tesla DeLorean
    Guru
    April 20, 2016
    Posted on April 20, 2016 at 17:55

    I can't explain why the AFG3022C would give you the saw-tooth profile.

    What is clocking the STM32F429?

    I might try to replicate this with a Nucleo-144 F429ZI and an u-Blox M8N later.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    Tesla DeLorean
    Guru
    April 20, 2016
    Posted on April 20, 2016 at 22:11

    Ok, so had a F446 to hand, 180MHz, APB1/TIM2 running at ~90MHz, measuring 1PPS from u-Blox M8 receiver.

    89998948
    89998945
    89998945
    89998947
    89998945
    89998945
    89998945
    89998947
    89998945
    89998947
    89998945
    89998945
    89998945
    89998947
    89998946
    89998945
    89998947
    89998945
    89998945
    89998947
    89998945
    89998946
    89998947
    89998945
    89998945
    89998947
    89998946
    89998945
    89998948
    89998945
    89998946
    89998947
    89998945
    89998945
    89998948
    89998945
    89998946
    89998947
    89998945
    89998946
    89998948
    89998945
    89998946
    89998947

    Varies perhaps 4 or 5 cycles, not saw-toothing over 70
    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    AvaTar
    Senior III
    April 21, 2016
    Posted on April 21, 2016 at 07:41

    Reviewing the number of seen satellites and quality of reception might be helpful. The accuracy of the PPS will surely degrade with fewer satellites.

    As a side note, I used to live in AT not far from the swiss border. When politicians met in Davos, GPS accuracy was always seriously degraded, almost unusable.

    maximmalenko
    Associate
    April 21, 2016
    Posted on April 21, 2016 at 12:36

    clive1, could  you send me your setting code(including sysclk) on maximmalenko@mail.ru? 

    Tesla DeLorean
    Guru
    April 21, 2016
    Posted on April 21, 2016 at 22:26

    Reviewing the number of seen satellites and quality of reception might be helpful. The accuracy of the PPS will surely degrade with fewer satellites.

    Technically you only need one to understand the performance of the local clock (TCXO, crystal, or whatever). Even a relatively mediocre GPS receiver design can keep a 1PPS signal within a 100ns rms.

    Where one might expect the saw-tooth is the placement ability of the receiver, ie the granularity on the clock (10MHz 100ns), and it's drift, so it walks off, and periodically gets slewed back via one, or half a clock cycle of the internal synchronous machine.

    In specialized timing receivers, where you can discipline the local clock, you can pull the drift to zero effectively, and you have a time source down in the ppb range.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..