PDA

View Full Version : USB certification PIC18F



Pic2008
- 19th June 2010, 16:28
Since Picbasic does not support sleep mode and resume in USB, how can the PIC product be certified? I'm planning to use PIC18F. There is no external 5V power and the PIC18F draws its power from the computer USB port.

jellis00
- 25th June 2010, 00:11
[QUOTE=Pic2008;90933]Since Picbasic does not support sleep mode and resume in USB...., QUOTE]

Not sure your statement is really true. I also had thought that I could not put my 18F4550 USB application into sleep mode and awaken it when a USB plugin occurred....until Darrel Taylor set me straight. Here is info he provided me that enabled me to create an application using his DT_INTS-18 (specifically the USB_ACTV_INT) that would sleep until interrupted by an external interrupt or a USB plug-in. Here is Darrel's dialogue on the subject:
------------------------------------
What I did say before was that the ACTVIF was a signal to resume from suspend mode.
I probably shouldn't have used the word resume, because RESUME is another bit in UCON that wakes up the PC if it's in sleep mode.
What I meant was to take the USB module out of SUSPEND mode.

ACTIVIF's happen whenever there is activity on the USB bus (every millisecond).

The only thing you need to do in the ACTVIF handler is take the module out of suspend mode (if it's suspended).

So the handler might be something like this ...

ACTVIFhandler:
IF UCON.1 THEN UCON.1 = 0
@ INT_RETURN

ALL USB interrupts are handled (and cleared) by DT_HID in the USB_Handler.
So if you want to catch the ACTVIF, then the USB_ACTV_INT definition has to be BEFORE the USB_Handler in the INT_LIST.
Otherwise the flag would have already been cleared, and it will never see the ACTVIF.

Since the USB_Handler needs to see the ACTVIF's, you can't clear the flag in the USB_ACTV_INT.
And they happen every millisecond, so you don't want to have a PBP type interrupt, make it ASM.

ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler USB_ACTV_INT _ACTVIFhandler, ASM, NO ; first in the list
INT_Handler USB_Handler
INT_Handler INT2_INT, _Range, PBP, yes
INT_Handler HLVD_INT, _LowVolt, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
endasm

And the last part. Putting the module in Suspend mode before going to sleep.
I was saying in the forum that the IDLEIF is already being used to detect the un-plugged state.
When it sees an IDLEIF, it immediately sets the Plugged bit to 0.

So before you try to put the PIC to sleep, check the Plugged bit.
If it's un-plugged, set the Suspend bit (UCON.1), then put the PIC to sleep.
If the USB is still Plugged, there's no sense putting the PIC to sleep because it will just wake up again in 1ms or less.

The ACTVIE enable bit is already enabled by DT_HID.
You don't need to do anything with it before going to sleep.

So then this is the sequence ...
When the PIC is asleep, any enabled interrupts will wake the processor.
So when the USB cable is plugged in to a live bus, the USB module will generate ACTVIF's and wake the PIC.
It will vector to the ISR, where the USB_ACTV_INT handler takes the USB module out of suspend mode.
It will then take 20+ ms to enumerate with the PC, and when finished the Plugged bit will be set.
At this point, you are fully connected to the PC and can send/receive data.
Darrel Taylor

jellis00
- 25th June 2010, 19:37
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler USB_ACTV_INT _ACTVIFhandler, ASM, NO ; first in the list
INT_Handler USB_Handler
INT_Handler INT2_INT, _Range, PBP, yes
INT_Handler HLVD_INT, _LowVolt, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
endasm


Make sure you corect the USB_ACTV_INT line in above code by placing a comma after the USB_ACTV_INT element of the statement. In other words:

ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler USB_ACTV_INT, _ACTVIFhandler, ASM, NO ; first in the list
INT_Handler USB_Handler
INT_Handler INT2_INT, _Range, PBP, yes
INT_Handler HLVD_INT, _LowVolt, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
endasm