function is called from the 0x37 case statement that is
rolling around in the main.c file:
case 0x37://Read POT command. Uses ADC to
measure an analog voltage on one of the ANxx I/O
pins, and returns the result to the host
{
64
June 2010
■ SCREENSHOT 3. The PIC24FJ256GB106’s AN0 input is
grounded when I sent the 0x37 command. Note the PIC’s
ADC converter returned 0x0000.
WORD_VAL w;
if(!HIDTxHandleBusy(USBInHandle))
{
mInitPOT();
w = ReadPOT();//Use ADC to read
the I/O pin voltage.
ToSendDataBuffer[1] = w.v[0];
//Measured analog voltage LSB
ToSendDataBuffer[2] = w.v[1];
//Measured analog voltage MSB
USBInHandle =
HIDTxPacket(HID_EP,(BYTE*)&ToSendDataBuffer[0],64
);
}
}
break;
The mInitPOT() macro has its roots in the TRAINER.h
file. The ReadPot function as well as the 0x37 case code
are part of main.c.
KEEP UP WITH SERVO MAGAZINE
If you’re a SERVO reader, you already know that with
minimal hardware and firmware modifications you can
plug the PIC24F/PIC32MX USB Trainer into the expansion
project hardware we assembled over there. Just in case
you missed it, the SERVO expansion board project added
an RS-232 portal, a 2 x 16 LCD, and an XBee-Pro
transceiver to the ZeroG - PIC24FJ128GA006 Trainer.
With the exception of the PIC24FJ256GB106’s USB
capability, the ZeroG Trainer’s base hardware is identical
to that of the PIC24F/PIC32MX USB Trainer. The ZeroG
Trainer and the USB Trainer hardware similarities allow the
reuse of code, as well. For instance, the LCD can easily be
incorporated into a PIC24F/PIC32MX USB Trainer design
as the hardware hookup, and the LCD driver firmware
have been proven on the PIC24FJ256GA006.
In the end, the ability to reuse technology in your
projects saves time and money. Having 16-bit USB
knowledge in your Design Cycle isn’t bad either. Be here
next time as we’ll replace the PIC24F/PIC32MX USB
Trainer’s PIC24FJ256GB106 with a PIC32MX575F512H. NV
EDTP Electronics, Inc.
PIC24F/PIC32MX USB
Trainer
ZeroG - PIC24FJ128GA006
Trainer
www.edtp.com
SOURCES
Microchip
PIC32MX575F512H
PIC24FJ256GB106
PIC24FJ256GA006
MPLAB C for PIC24 MCUs
www.microchip.com
Fred Eady can be contacted via email at fred@edtp.com.
■ SCREENSHOT 4. This shot shows the results of applying
+ 3. 3 volts to the PIC24FJ256GB106’s AN0 input. Just as expected,
its 10-bit ADC returned the maximum reading of 0x03FF.