This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Capture Qei position and send to usb

Hi
I want to draw graphs of position of 2-phased QEI versus time. so I want to capture QEI position every time period. time gap between to position pulses is at least 7.2 microseconds.
I think I have to choose one of these methods:

1-send position to USB during time overflow interrupt(TIM_INT)

2-send content of the timer when the situation changes. (I don't know if it is possible to sense the changes as an interrupt?)

I think there are some restrictions due to interrupt latancy. so what is the highest resolution for my system. and which method is better? How can I define interrupt for 2nd method?
can i send data to buffer and send batch buffer to USB? Is it help me Reduce interrupt latancy effects? HOW?
Please Help me
Best Regards

Parents
  • > I want to draw graphs of position of 2-phased QEI versus time.

    As of QEI unit of LPC17xx, an ENCLK_Int interrupt occurs at the every transition of the encoder. In this ISR, your firmware reads out a timer value, which runs freely, to know the interval of the every transition. Cortex-M3 NVIC has fixed interrupt latency of 12 cycle. You may get exact interval with this method.

    Erik,

    > When the encoder stop exactly over a border in the optical disc a minuscule vibration (which is there in any mechanical desogn) will cause a higher frequency of pulses.

    Such a noise is filtered by,
    1) R/C (or L/C) filter at the input pins of the QEI unit.
    And
    2) The integrated digital filter of the LPC17xx QEI unit.

    Tsuneo

Reply
  • > I want to draw graphs of position of 2-phased QEI versus time.

    As of QEI unit of LPC17xx, an ENCLK_Int interrupt occurs at the every transition of the encoder. In this ISR, your firmware reads out a timer value, which runs freely, to know the interval of the every transition. Cortex-M3 NVIC has fixed interrupt latency of 12 cycle. You may get exact interval with this method.

    Erik,

    > When the encoder stop exactly over a border in the optical disc a minuscule vibration (which is there in any mechanical desogn) will cause a higher frequency of pulses.

    Such a noise is filtered by,
    1) R/C (or L/C) filter at the input pins of the QEI unit.
    And
    2) The integrated digital filter of the LPC17xx QEI unit.

    Tsuneo

Children
  • thanks:

    Such a noise is filtered by,
    1) R/C (or L/C) filter at the input pins of the QEI unit.
    And
    2) The integrated digital filter of the LPC17xx QEI unit.

    Is it embedded in the IC or Should I do ?
    LPC_QEI->FILTER =???(What should i put??)

    As of QEI unit of LPC17xx, an ENCLK_Int interrupt occurs at the every transition of the encoder....
    I have written below codes to send the data to usb using usbhost lite.
    FILE_Open, FILE_Write & FILE_Close belong to USBHostlite part:

    void qei_main(){
            //Basic Configuration:
            LPC_SC->PCONP |= (1<<18);
            LPC_SC->PCLKSEL1  |= (0x01);
            //configuration for the pins:
            LPC_PINCON->PINSEL3 |=((1<<8)|(1<<14)|(1<<16));//PH A&B & index
            LPC_QEI->QEICONF =(1<<2);//PhA and PhB function as quadrature encoder inputs.(4x)
            LPC_QEI->QEICON = 0x02;//Control register: Reset position counter on index.(RESPI)
            LPC_QEI->INXCMP = 0x00;//QEI Index Compare register                                                                                                           LPC_QEI->QEILOAD = 0x00;//QEI Timer Reload register
            LPC_QEI->QEICLR = 0xFFFFFFFF;
            LPC_QEI->QEIIEC = 0xFFFFFFFF;
            LPC_QEI->QEIIES = 0x00000020;//enable ENCLK_EN
    }
    NVIC_EnableIRQ(QEI_IRQn);               /*enable the interrupt*/
    NVIC_SetPriority (USB_IRQn, 1);         /*2nd priority--is it correct??*/
    
    void QEI_IRQHandler(void){
            USB_INT32S  fdw;
            fdw = FILE_Open(FILENAME_W, RDWR);
            if (fdw>0) {
                    *UserBuffer=LPC_QEI->QEITIME;
                    FILE_Write(fdw,UserBuffer,4);
                    FILE_Close(fdw);
            }else{
                    return;
            }
            LPC_QEI->QEICLR = 0xFFFFFFFF;   // clear all interrupts
    }
    


    Is it correct set priority of USB to 0 and QEI to 1??

    kind regards

  • > LPC_QEI->FILTER =???(What should i put??

    The time constant of the passive input RC (LC) filter is determined by the PCLK frequency of QEI.
    It's much less than (1/8 - 1/16) of PCLK
    QEI FILTER register holds a minimum expected interval of encoder transition, counted in PCLK scale.

    > Is it correct set priority of USB to 0 and QEI to 1??

    QEI should have the highest priority (0), and USB is assigned to lower priority than QEI.

    > I have written below codes to send the data to usb using usbhost lite.

    FILE_Open, FILE_Write and FILE_Close are too slow to run in the QEI ISR.
    Also, it is efficient to write data of sector size at a time.

    In the QEI ISR, the timer value is written to a buffer of 1024 bytes.
    When the buffer holds 512 bytes (sector size) or more, one sector of data is written to the USB drive.

    Tsuneo

  • >The time constant of the passive input RC (LC) filter is determined by the PCLK frequency of QEI.
    It's much less than (1/8 - 1/16) of PCLK

    So, if i want to filter pulses less than 2us, what should i write?(clk=100mhz)
    LPC_QEI->FILTER =0xc8; /*200*/
    Is it correct?

    >When the buffer holds 512 bytes (sector size) or more, one sector of data is written to the USB drive.

    Oh, I am a beginner!
    I don't know how to access to the buffer. How can i get access to this Buffer?
    what should i write instead of *UserBuffer=LPC_QEI->QEITIME; ??
    can you help me with the codes?
    thanks

  • >When the buffer holds 512 bytes (sector size) or more, one sector of data is written to the USB drive.

    Thanks Dr Tsuneo Chinzei

    But how can i detect that number of bytes written in QEITIME is 512?
    And how to Empty the buffer after writing data?

    An other Question: Is it correct to write LPC_QEI->FILTER =0xc8; /*200*/ to filter less than 2us when clock is 100mhz?

    Best Regards?

  • I still haven't got answered my previous questions!
    I don't know how to get access to the buffer that included timer(QEITIME) values?

    another question:
    what is the practical difference between set register & enable register(QEISET & QEIIES)? Can you give me an example please?

    Amir
    hejazi1365[at]gmail[dot]com
    Best regards

  • Hi Dear Erik
    It seems that Tsuneo rarely comes here!
    due to low rate of USB functions, i must buffer data and send them in batch. And in the end, i should reset the timer.
    so how can i buffer the data? should i use an auxiliary register?
    how can i detect that number of bytes written in QEITIME(or auxilary Buffer) is 512?
    should i pend the interrupt to send the data(buffer) to USB? cause the usb functions are too slow?

    Amir
    hejazi1365[at]gmail[dot]com
    Best regards

  • I got really disappointed!!
    Any body couldn't help me with the buffer?

    thanks
    Amir
    hejazi1365[at]gmail[dot]com

  • I got really disappointed!!
    Any body couldn't help me with the buffer?

    not trying to 'disappoint' you but I can't simply because I have never worked with this specific issue (have no idea what QEITIME is)
    how can i detect that number of bytes written in QEITIME(or auxilary Buffer) is 512?
    for the usual buffer which is written by address[index] 'index', of course will hol;d the count.

    Erik

  • Maybe you would care to expand why you feel "really disappointed".

    It isn't like you are paying to get support from this web forum.

    The only way other Keil users can help you is by spending their time retrieving the available information and read it. The big question is why other people should invest their own, private, time to do that when they don't have any incentive to do so. That time could instead be spent listening to music, walking the dog or maybe earn $$$ by developing applications.

    You, on the other hand, should have specific incentives to spend time with the available sample source code, application notes and processor user manual.

  • >Aren't you a funny guy?

    >Maybe you would care to expand why you feel "really disappointed".

    I don't care you are an active user or a KEIL Employee. but is it your amusement to visit this forum to write such sentences?

    Some people usually share their information & knowledge through forum and some other ask (or even beg) other people to help them.
    I didn't forced Mr Tsuneo & Mr Erik to answer me! Both of them kindly answered some of my questions. And speaking about "disappointing" won't oblige them to answer and I think it does not contain any insults.

    Amir
    Hejazi.1365@gmail.com

  • What amusement do you find in the sentence "Maybe you would care to expand why you feel 'really disappointed'"?

    Did you _really_ read what I wrote?

    "Some people usually share their information & knowledge through forum and some other ask (or even beg) other people to help them."

    Share information requires that the helper already know the answer. If no one who reads your question knows the answer, then no one will be able to share that answer too, unless they invest own time to figure out the answer. And here is where you _do_ have to care about people just being other users of the Keil tools like your self, or if this is a payed support service where people are payed to supply help.

    By the way - all your posting of email addresses implies that you want answers sent directly to you instead of having the answers posted on this forum. Private answers do have the big disadvantage that they can't be picked up by Google. So they would not help anyone else.

  • >In the QEI ISR, the timer value is written to a buffer of 1024 bytes.[Tsuneo]

    When the buffer holds 512 bytes (sector size) or more, one sector of data is written to the USB drive.

    about one of my questions "the helper already know the answer." and i want to know whats the name of the buffer. is it direct or indirrect? but no body answered me.

    I said if they don't want to "share their information" for free and want to "earn $$$", I respectfully write my Email, to send me the price, Because I really need this buffer.

    Amir

  • "about one of my questions "the helper already know the answer.""

    Sorry, but you need to read more carefully.

    The text you mention said:

    In the QEI ISR, the timer value is written to a buffer of 1024 bytes.
    When the buffer holds 512 bytes (sector size) or more, one sector of data is written to the USB
    drive.
    

    If you write a QEI ISR, then it would be _you_ who knows the name of the buffer _you_ place the values in. And it would be _you_ who knows when you have 512 bytes of data in that buffer, so _you_ would know when you have enough to write one sector to the USB drive.

    If _you_ haven't written the QEI ISR, then it would still be _you_ who should locate the source of that ISR and look what buffer the data is stored in.

    Do you even know if there exists any QEI ISR?

  • Thanks
    So, I must read the GPDMA session from datasheet. and define a buffer.
    i'll working on it. and then ask the questions about it.

    Best Regards
    Amir

  • When using any peripherial that has the hardware support for it, you may be able to poll the device for data. Or configure the device to issue an interrupt for each data getting available. Or configure the device to hand off data to a DMA channel. This may be an SPI device, an UART, or maybe an ADC - the concept is still the same.

    So if this quadrature device supports DMA, then you need to configure one DMA channel to take the quadrature device as data source, and a buffer as data destination. The DMA channel can then generate interrupts to let you take care of received data and potentially supply new buffers to use. For DMA channels that supports it, it is often nice to have a buffer that is twice as large as the block size you want. So the DMA channel can interrupt when the buffer is half-full. Then you have ample time to take care of the already received data while the DMA channel continues to fill the other half of the buffer. And the ISR can tell the DMA what to do when the second half of the buffer gets full - i.e. that the DMA channel should restart from the beginning of the buffer again. So you basically double-buffer the transfer with a 2*n-sized buffer.

    If you don't have too high data rates, it is possible to ignore any DMA transfers and instead have one interrupt/sample. And have the ISR pick up a single value and put in a buffer. This is ok as long as the ISR doesn't consume too much time, and the ISR is guaranteed to pick up a value before the device have produced the next value.

    So Tsuneo Chinzei is talking about a concept, while leaving it to you to flesh out actual code to fulfill this concept. Note also that he wrote:

    As of QEI unit of LPC17xx, an ENCLK_Int interrupt occurs at the every transition of the
    encoder. In this ISR, your firmware reads out a timer value, which runs freely, to know the
    interval of the every transition. Cortex-M3 NVIC has fixed interrupt latency of 12 cycle. You
    may get exact interval with this method.
    

    That indicates the he isn't talking about any DMA transfers, but about the ISR handling individual samples. So that would obviously mean that _you_ would be the one who decides the name of the buffer, and you who decides how to keep track of amount of data in the buffer.

    So no way at all that anyone else can tell you the names that _you_ would decide to use when _you_ implement that ISR. So the reason no one gives you the answer to your questions is that it isn't possible for anyone to answer them. It's on your table to decide.