Hi,
USB, OK, never played with that myself. But anyway, are you sending one single measurment from the PIC to the PC each time the PIC is polled? If you reliably can get a poll rate of say 20Hz and you need 500 measurments per second you need a buffer in the PIC of atleast 500/20=25 measurements (bytes or words?) but I'd probably add some margin to that.
Now, depending on how the rest of the code is set up, ie. if interrupts are used etc using the local buffer can be more or less complicated. Assuming that no interrupts are used to put data INTO the buffer all your main program has to do keep track of where in the buffer to put the next byte using a pointer variable
Code:
BufferSize CON 25
LocalBuffer VAR BYTE[BufferSize]
Ptr VAR BYTE
Ptr = 0
Each time you get a new measurment to put in the buffer you do something like
Code:
LocalBuffer[Ptr] = NewMeasurment
Ptr = Ptr + 1
If Ptr = BufferSize THEN GOTO BufferOverFlow ' Buffer not emptied in time.....
The routine that sends the data to the PC when polled then just have to send any data that's in the buffer. I'm using HSEROUT here since I don't know how you're doing it with USB
Code:
If Ptr > 0 'Only do this of there's any new data in the buffer
For i = 0 to (Ptr - 1)
HSEROUT [LocalBuffer[i], 10,13]
NEXT
Ptr = 0 ' Reset pointer
ENDIF
Something like that, perhaps.
If you're not using interrupts then obviosuly the PIC can't read data and put into the buffer at the same time that it's sending data but I don't know exactly how that works when using USB. If you're using interrupts to fill the buffer, ie. the routine that sends data to the PC can be interrupted by the routine putting data into the buffer you'll need to resort to a circular buffer.
/Henrik.
Bookmarks