hey can anybody provide me with the sample code for configuring interrupt endpoints for periodic sampling of adc...
sir, acctually i am given the whole project on the usb related firmware side to be implemented in 5 days....on lpc214x kit and i have been provided with exported library functions ... i implemented the same for adc() and rtc() using bulk endpoints, understood the code flow and callback functions for the same and the next job is to implement periodic sampling of adc() using interrupt endpoints....i am finding it difficult to get the exact reading material and not getting proper sample codes for the same...kindly help me out sir for the same....??
> i implemented the same for adc() and rtc() using bulk endpoints, .. and the next job is to implement periodic sampling of adc() using interrupt endpoints
Wny don't you implement ADC data transfer over the bulk endpoint? Usually, a bulk IN endpoint is better for ADC data streaming. It's because bulk can carry much more data (19 x 64 bytes) than interrupt transfer (1 x 64 bytes) per 1ms USB frame. And then, you may assign higher ADC sampling rate or more ADC channels.
Maybe, you picked up interrupt transfer, because it is "periodic". As ADC sampling is also periodic, ADC data streaming would fit well on interrupt transfer. But it's a wrong idea.
Interrupt transfer may be "periodic", but its periodicity is different from ADC sampling rate. The periodicity of interrupt endpoint is determined by the host side, by host controller of the PC. On the other hand, the sampling clock of the ADC is locally provided by a crystal on the board. Even if you would generate "the same" interval on your MCU, it slightly differs from bus clock interval of USB, because clock source is different. If you would assume these intervals are "the same", you should see buffer over-/under-flow, and data drop.
ADC data streaming is implemented as follows. - In the ADC ISR, ADC data is written to a buffer (array). The write position (index of the array) increments for the next ISR call. - In the main loop, another task polls the number of data on the buffer. When the buffer holds 64 bytes or more, one packet (64 bytes) of the data is written to the bulk endpoint.
To keep these tasks running, the buffer should be cyclic - when the write (and read) index reaches to the end of the butter, the indices wrap around to the start (0). Also, the buffer size should be greater than one packet, to escape from overwrite before transfer.
On the host side, your PC application reads out the bulk endpoint, by the size of 64 bytes x N, for example, 1024 bytes. Greater read size gives faster transfer speed, until the bus bandwidth saturates. When a read call completes, the PC application should immediately put another read call. Asynchronous (OVERLAPPED) read fits well for this scheme.
Tsuneo
great idea SIR...i will implement for the same...!!!