timestamp from a microcontroller in millisecond

Status
Not open for further replies.
Hi


when i am checking the timestamp with receivers software, it`s showing 1 event is missing. From the original file i made some change and i put them in bold letters here. but i can't
figure it out why it's missing a event.


i only posted here the part of firmware i modified. Sorry for post a big code but i need some help with this.

Code:
Code (C):

typedef struct FifoStack
{
u16 u16EventTimeStampMSPart;        //This variable have only the ms part!!!
    u32 u32EventTimeStamp;                    // This variable have only the s part!!!
    u8 u8EventInput;
} SFIFO_STACK;

// Private function prototypes -------------------------------------------------
void UsbConnect(void);
void StackPush(u32 u32EventTime, u16 u16EventTimeMS, u8 u8Input);
u8 StackPop(SFIFO_STACK *psFifoStack);
void GetMessage(u8 *pu8Buffer);
void TaskFilter(void);

// *****************************************************************************
/// @brief        Function that saves an event in cell
/// @fn            void StackPush(u32 u32EventTime, u16 u16EventTimeMS, u8 u8Input)
/// @param[in]    u32EventTime    @brief Hora do evento
/// @param[in]    u16EventTimeMS  @brief Hora do evento, ms part ASIF
///    @param[in]    u8Input            @brief Número da entrada que gerou o evento
// *****************************************************************************
void StackPush(u32 u32EventTime, u16 u16EventTimeMS, u8 u8Input)
{
    if ((s16StackWriteIndex + 1) != s16StackReadIndex)                                    // verifica se há espaço na pilha
    {
        sFifo[s16StackWriteIndex].u16EventTimeStampMSPart = u16EventTimeMS;        //ASIF salva o time stamp na pilha, part MS

        sFifo[s16StackWriteIndex].u32EventTimeStamp = u32EventTime;                        // salva o time stamp na pilha
        sFifo[s16StackWriteIndex].u8EventInput = u8Input;                                // salva a entrada digital na pilha
        s16StackWriteIndex++;                                                            // incrementa o índice de escrita
        if (s16StackWriteIndex >= STACK_SIZE)                                            // torna o índice de escrita circular
            s16StackWriteIndex = 0;
    }
}

// *****************************************************************************
/// @brief        Function that retrieves a cell event
/// @fn            u8 StackPop(SFIFO_STACK *psFifoStack)
///    @param[out]    psFifoStack        @brief Evento
/// @retval        TRUE, se ok
// *****************************************************************************
u8 StackPop(SFIFO_STACK *psFifoStack)
{
    if (s16StackReadIndex != s16StackWriteIndex)                                        // verifica se há dados na pilha
    {
        psFifoStack->u16EventTimeStampMSPart = sFifo[s16StackReadIndex].u16EventTimeStampMSPart;    //ASIF busca o time stamp da pilha, part MS

        psFifoStack->u32EventTimeStamp = sFifo[s16StackReadIndex].u32EventTimeStamp;    // busca o time stamp da pilha
        psFifoStack->u8EventInput = sFifo[s16StackReadIndex].u8EventInput;                // busca o número da entrada digital da pilha
        s16StackReadIndex++;                                                            // incrementa o índice de leitura
        if (s16StackReadIndex >= STACK_SIZE)                                            // torna o índice de leitura ser circular
            s16StackReadIndex = 0;
        return TRUE;
    }
    else
        return FALSE;
}



// *****************************************************************************
/// @brief        Task of filtering the digital inputs
/// @fn            void TaskFilter(void)
// *****************************************************************************
void TaskFilter(void)
{
    u8 n, u8DigInp;
    static u8 u8DigInpOld;
    static u32 u32FilterTimer[INPUT_NUMBER], u32EventTime[INPUT_NUMBER], u16EventTimeMS[INPUT_NUMBER], u32FilterSample;
    static ESTATE_FILTER eFilterState[INPUT_NUMBER];
//  u32 u32Counter[2];
    if (TimeDiff(u32FilterSample) == 0)
        return;
    u32FilterSample = ReadSysTime();
    u8DigInp = ReadDigInp();                                                            // lê as entradas digitais
    for (n = 0; n < INPUT_NUMBER; n++)
    {
        switch (eFilterState[n])
        {
            case STATE_ACTIVE_EDGE:
                if ((u8DigInp & (1 << n)) ^ (u8DigInpOld & (1 << n)) != 0)                // verifica se houve mudança no nível da entrada
                {
                    if ((sInputFilter[n].u8ActiveEdge << n) == (u8DigInp & (1 << n)))    // verifica se a transição corresponde à borda ativa
                    {
                      u32EventTime[n] = u32Time;                                                // This is exact moment of event, but only in seconds
//                        u16EventTimeMS[n] = TimeDiff(u32Prescaler);                // ASIF This is exact moment of event, but in ms inside the second

                        u32FilterTimer[n] = ReadSysTime();                                // carrega o temporizador do nível ativo
                        eFilterState[n] = STATE_ACTIVE_LEVEL;                            // passa para o estado de verificação do nível ativo
                    }
                }
                break;
            case STATE_ACTIVE_LEVEL:
                if ((sInputFilter[n].u8ActiveEdge << n) != (u8DigInp & (1 << n)))        // verifica se o nível da entrada mudou para o nível inativo
                    eFilterState[n] = STATE_ACTIVE_EDGE;                                // volta para aguardar uma nova transição
                if (TimeDiff(u32FilterTimer[n]) > sInputFilter[n].u16ActiveTime)        // verifica se passou o tempo mínimo de nível ativo
                    eFilterState[n] = STATE_INACTIVE_EDGE;                                // passa para o estado de verificação da borda inativa
                break;
            case STATE_INACTIVE_EDGE:
                if ((u8DigInp & (1 << n)) ^ (u8DigInpOld & (1 << n)) != 0)                // verifica se houve mudança no nível da entrada
                {
                    if ((sInputFilter[n].u8ActiveEdge << n) != (u8DigInp & (1 << n)))    // verifica se a transição corresponde à borda inativa
                    {
                        u32FilterTimer[n] = ReadSysTime();                                // carrega o temporizador do nível inativo
                        eFilterState[n] = STATE_INACTIVE_LEVEL;
                    }
                }
                break;
            case STATE_INACTIVE_LEVEL:
                if ((sInputFilter[n].u8ActiveEdge << n) == (u8DigInp & (1 << n)))        // verifica se o nível da entrada mudou para nível ativo
                {
                    u32FilterTimer[n] = ReadSysTime();                                    // carrega o temporizador do nível ativo
                    eFilterState[n] = STATE_ACTIVE_LEVEL;                                // passa para o estado de verificação do nível ativo
                }
                if (TimeDiff(u32FilterTimer[n]) > sInputFilter[n].u16InactiveTime)        // verifica se passou o tempo mínimo de nível inativo
                {
                   u16EventTimeMS[n]++; // = TimeDiff(u32Prescaler);                // ASIF This is exact moment of event, but in ms inside the second

                    StackPush(u32EventTime[n], u16EventTimeMS[n], n);                                        //ASIF salva o evento na pilha
                    eFilterState[n] = STATE_ACTIVE_EDGE;                                // aguarda o próximo evento
                }
                break;
        }
    }
    u8DigInpOld = ReadDigInp();                                                            // salva o nível atual das entradas digitais
}


// *****************************************************************************
/// @fn            void TaskMain(void)
/// @brief       Task control system
// *****************************************************************************
void TaskMain(void)

{
    if (TimeDiff(u32Prescaler) >= 1000)                    // atualiza o relógio
    {
        u32Prescaler = ReadSysTime();
        u32Time++;
    }
    TaskFilter();                                        // processa o filtro das entrads
    ReadAD();                                            // lê os canais analógicos
    CommLed();                                            // atualiza os LEDs da recepção e transmissão
    BlinkControl();                                        // atualiza o pisca-pisca
    UsbStateControl();                                    // controla o estado da conexão SUB
    if (IsUsbConnected() == TRUE)                        // verifica se está conectado à USB
    {
        SysLed(IsBlink());                                // se há, pisca o LED sinalizador
        if (TimeDiff(u32UsbTimer) > USB_COMM_TIME)        // verifica se passou o período de envio
        {
            u32UsbTimer = ReadSysTime();                // renova o temporizador
            SendUsb(SendMessage());                        // envia os dados pela a interface USB
        }
    }
    else
        SysLed(TRUE);                                    // se não há, liga o LED
}
 

Attachments

  • event.jpg
    275 KB · Views: 266
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…