THE DESIGN CYCLE
POWERED_STATE)
{
mLED_Only_1_On();
}
else if(USBDeviceState ==
DEFAULT_STATE)
{
mLED_Only_2_On();
}
else if(USBDeviceState ==
ADDRESS_STATE)
{
if(led_count == 0)
{
mLED_1_Toggle();
mLED_2_Off();
}//end if
}
else if(USBDeviceState ==
CONFIGURED_STATE)
{
if(led_count==0)
{
mLED_1_Toggle();
if(mGetLED_1())
{
mLED_2_Off();
}
else
{
mLED_2_On();
}
}//end if
}
It’s nice to be able to look at the LEDs and determine
all of the other enumeration states. However, what you
really want to see is LED1 and LED2 alternately blinking
on your USB Trainer.
found in the usb_descriptors.c file.
I shorted the PIC24FJ256GB106’s AN0 ADC input to
ground before issuing the 0x37 command. As you can see
in the Read area of Screenshot 3, the ADC returned the
command value followed by the ADC value of 0x0000.
Screenshot 4 returned the 10-bit value of 0x3FF as I applied
+ 3. 3 volts to the ADC input before issuing the command
to take a reading from the potentiometer’s wiper. The
code used to read the potentiometer is relatively simple
and is provided for us in the main.c demo application:
WORD_VAL ReadPOT(void)
{
WORD_VAL w;
#if defined(EDTP_PIC24F_PIC32MX_TRAINER)
AD1CHS = 0x0; //MUXA uses AN0
// Get an ADC sample
AD1CON1bits.SAMP = 1; //Start sampling
for(w.Val=0;w.Val<1000;w.Val++);
//Sample delay, conversion start automatically
AD1CON1bits.SAMP = 0; //Start sampling
for(w.Val=0;w.Val<1000;w.Val++);
//Sample delay, conversion start automatically
while(!AD1CON1bits.DONE); //Wait for
//conversion
//to complete
#else
#error
#endif
w.Val = ADC1BUF0;
return w;
}//end ReadPOT
MAGIC SMOKE STATION TEST
Since I’m writing this paragraph, you and I can get up
on our donkeys and proclaim success! I’ve applied power via
the USB portal and programmed the PIC24FJ256GB106. If
you were here in the shop with me, you would see LED1
and LED2 going to town in an alternating manner and the
POWER LED operating without a struggle.
Remember that analog input I mentioned
earlier? Well, I can’t show you blinking LEDs
but since we included the pot macros, I can
show you data acquired from the
PIC24FJ256GB106’s ADC. I’ll use the
Kadtronix UsbHidDemo application to send
the command and receive the data.
Screenshot 2 confirms that our
PIC24F/PIC32MX USB Trainer has been
recognized as a HID device by the
UsbHidDemo application (which is running on
my laptop). The EDTP Device Name was
gleaned from the modification we made to the
product string descriptor in the
usb_descriptors.c file. The VID (1240) and PID
(63) belong to Microchip and can also be
Note that branding comes in handy once again as the
ADC commands are particular to the PIC24F/PIC32MX
USB Trainer. The ReadPOT function defines the analog
port to read and, in this case, it is AN0. The ReadPOT
■ SCREENSHOT 2. The Device Name is taken from the
product descriptor string we modified. The VID and PID
are also found in the usb_descriptors.c file.
June 2010 63