博客首页 | 排行榜 |

设计我最赞的博客

个人档案
博文分类
着手于PIC USB的连通性(Get Started with PIC USB Connectivity)  2008-10-16 18:47
You can add USB to your next project with Microchip Technology‘s new array of parts.The 8-, 16-, and 32-bit microcontrollers will complement your designs with USB peripheral support, embedded hosting, and dual-role and OTG capabilities.

Many of us are just coming to grips with the idea of supporting a USB interface as the communications medium of choice for our product designs. PC manufactures have eliminated the DE9 (standard for years on every PC) and replaced it with USB (and FireWire) connectors. We‘ve been forced to learn more about the protocols than we ever wanted to know. Unless my product incorporates PC-type architecture, I can't take advantage of all the peripherals out there. So, I can forget about adding a storage device, keyboard,or other USB peripheral to my project. Microcontrollers just don‘t have the room to handle a USB host's responsibilities.

USB On-The-Go (OTG) technology was announced on December 18, 2001,by the USB Implementers Forum (USBIF)。Let‘s see, that's about seven years ago. You‘d think by now that we would have access to all of those USB products that have shipped to date-at least that was the promise made back then. About all that comes to mind is some high-priced digital camera that supports downloading directly into a printer. That's hardly what I would call utopian connectivity.

Well, stand back, because the tools to make this a reality are finally here. Microchip Technology has released 16- and 32-bit microcontrollers that support embedded hosting, dual-role, and OTG capabilities, complementing the original 8-bit microcontrollers with USB peripheral support (see Photo 1)。Let‘s look a little closer at the supported USB capabilities.


USB (AS WE KNEW IT)

We know the PC as a USB host device consisting of complex software applications with an operating system and processor. The host must manage and control all USB functions. It initiates all data packet activity on the bus, managing data flow and doing error checking. The host must detect peripheral insertion (enumerate the device and match it with a particular class driver)and extraction (close and clean up after itself)。 It also provides power to the peripheral. (For more information about USB and its inner workings,refer to my columns listed at the end of this article.)


A USB connection is made via a cable with differentiated plugs (see Photo 2)。 The host is mated using a type-A plug/receptacle while the peripheral is connected with a type-B plug/receptacle. Some peripherals have a micro type-B plug/receptacle to save space.



A USB peripheral responds only to a host and does not have the capability to initiate data transfers. It must be concerned with power consumption and check for errors in the data from the host.

EMBEDDED HOST
An embedded host is defined as a product with limited host capabilities. That is, while it must provide management and control of the bus, it can support only the peripherals that it was designed for. This can be as specific as a peripheral or class of peripherals. An embedded host will have a full-size type-A receptacle. The embedded host may optionally support SRP.(I‘ll present more on the power conservation session request protocol a bit later.)


ON THE GO
OTG technology has its own limitations and extensions. An OTG device has a dual-role capability: it can act as an embedded host or a peripheral. It is designated by the use of one micro type-AB plug/receptacle. The receptacle can accept either a micro type-A plug or a type-B plug. OTG devices must support both HNP (Am I the host or peripheral negotiation protocol?) and SRP.

DUAL ROLE
This term can be confusing depending on how it is used. An OTG device can be considered a dual-role device. A dual-role device needs both a standard A connector and one of the B-type connectors. However, there are applications that might require an embedded host device to serve as a host to one peripheral and as a peripheral to another host.

NEW PROTOCOLS
The ability to host a connection brings with it a new complexity for the interface circuitry as the device‘s role changes from that of a peripheral, and that includes new protocols (see Figure 1)。 The HNP protocol enables the OTG devices to negotiate whowill be the boss when the two are connected. Let's assume you have an OTG camera and an OTG PDA. An OTG cable (micro-type-A to micro-type-B) connects the two. Each device can be a host to, say, a printer. When connected together, the cable determines which device will begin as the host.
点击查看Figure 1

This OTG cable has a fifth connection with pin 5 connected to ground on the type-B side. Ra_PLUG_ID is 10 Ω max and Rb_PLUG_ID is 100 kΩ min. The type-A side becomes the host and must supply power,at least 8 mA, to the type-B peripheral. The host will identify its peripheral as an OTG device and can allow the peripheral to ask for a swap in functionality. (You may remember that a peripheral can indicate its operating speed as full by attaching a pull-up on the D+ line. New interface circuitry enables a device to enable/disable functions so it can act as a host or a peripheral.)

Once the device at the type-B end of the cable takes over, it can relinquish control back to the type-A side, if necessary, by the same procedure. With this approach, you never have to worry about which end of the cable to plug into which OTG device. It‘s all automatic.

One of the main concerns with embedded hosts and OTG devices is power consumption because most are battery powered. The second new protocol SRP addresses this concern. OTG hosts are allowed to turn off VBUS in the USB connection when the bus is idle. Even with no VBUS on the USB connection, the peripheral device can ask for service when necessary. This is done by first toggling D+ with its pull-up. If the host monitors the data lines, it can respond by turning on VBUS and initiating a session. In this case, the peripheral will see VBUS and abort its SRP. If the host doesn't respond to the data toggling,the peripheral toggles VBUS (8 mA of current max)。 If the host monitors VBUS, it can respond by turning on VBUS and initiating a session. OTG devices are the only ones required to use SRP,although it can be (optionally) supported by any device. Detailed signal information for HNP and SRP can be found at www.usb.org/developers/docs /USB_OTG_1-3.pdf.

TPL
Although an OTG device must support some host qualities, it is limited to a specific set of support peripherals designated by the designer. OTG devices require a targeted peripheral list (TPL) to decide whether a connected peripheral is supported or not.

The TPL requires a manufacturer,model number, and description of those peripherals it can handle. If the peripheral is not in the TPL, the OTG device is required to indicate the problem to the user in some fashion, preferably in an error message(e.g., an LED or a beep)。 Class support is not part of OTG. Although there is no reason it couldn‘t be used, that would void OTG certification.(This should be revisited by the USB-IF.)


CLASS SUPPORT
The USB-IF standard classes supported for an embedded host are listed in Table 1. With memory at a premium for embedded devices, supporting every class would be virtually impossible. Designing for a class minimum makes sense. This at least enables your product to continue functioning with any manufacturer‘s widget of that class.



A BIRD IN THE HAND
There is something about having a product in your hands to assure you it's real. But that‘s just the start. Microchip Technology's parts get you thinking about how completely they support USB. The 8-bit PIC18F14K50(20-pin), PIC18F4550 (40-pin), and PIC18F66J50 (64-pin) function as USB peripherals. The 16-bit PIC24FJ256GB110 (100-pin)supports USB embedded hosting,peripheral, and OTG functions. The 32-bit PIC32MX460F512L (100-pin)also supports USB embedded hosting, peripheral, and OTG functions.

While these parts just hint at all of the USB variants available, they demonstrate the extensive products supported that use a single (free)integrated development environment. Common software libraries provide an easy migration path across all devices. Each of the parts has a development, demo, or starter kit available for under $60. Let‘s take a quick look at these offerings.

COMMON FEATURES
The chips I'm covering feature onchip transceivers and are USB 2.0- compliant. They support low-speed (LS,1.5 Mbps) and full-speed (FS, 12 Mbps)connections and all four types of transfer: control, interrupt, isochronous,and bulk. Table 2 compares these side by side.
点击查看Table 2

The 8-bit chips can source/sink 25 mA through their I/O pins, while the 16- and 32-bit chips can handle 18 mA. All of the chips support dedicated edge-triggered interrupts as well as interrupt-on-change (with internal pull-ups) on some or all of their I/O pins.

In terms of on-chip peripherals,each chip includes one or more capture/ compare/PWM modules, some with enhanced PWM features. The enhanced PWM features include dual- (half-bridge) and quad-PWM(full-bridge) outputs with selectable polarity, dead time, and auto shutdown/ restart. The master synchronous serial port (MSSP) module supports four modes of SPI and both master and slave I2C modes. An enhanced USART supports RS-232/485 as well as LIN 1.2/2.0 and IrDA interfaces in some cases. The 10-bit ADC module has automatic acquisition and conversion during sleep capability. Analog comparators offer rail-torail operation and independent input multiplexing.

Each microcontroller‘s external crystal/ clock input can run the oscillator up to 48 MHz (32 MHz on the PIC24FJ256GB110)。 A 4× phase-locked loop (PLL) can boost input when necessary for the USB. The system clock can come from the USB block, one of two alternate internal RC oscillators, or the optional low-frequency RTC clock.(Timer1 uses an external 32.768-kHz crystal.) There is even a failsafe clock monitor that allows for shutdown in the event of an oscillator failure. There are also an RTC oscillator and a watchdog timer that operate independently of the CPU. The watchdog timer runs from the 31-kHz internal RC oscillator source.

Each chip includes an internal regulator that can operate the core logic. Power is managed through three or more states: Run, Idle, and Sleep. Brown-out reset (BOR) and power-on reset (POR) functions are implemented as well as optional two-speed startup that allows execution from the internal oscillator. The oscillator start-up timer (OST) waits for the mandatory 1,024-cycle delay of the external oscillator.

PIC18F14K50
The 8-bit PIC18F14K50 is the smallest member of the group with a 20-pin package (PDIP, SSOP, or SOIC)。 It is geared toward low-cost, tiny devices that need USB connectivity. It has some special features to support such devices, including interrupt on change for D± (detect connection)。 The slew rate on each output port can be reduced as an aid to EMI reduction. A 1.024-V fixed internal reference for the ADC is available.

This part has a 3.6-V internal voltage regulator derived from a 5.5-V input. The LF version operates from a 3.6-V maximum input voltage and does not have the regulator. Both versions can run down to 1.8 V (without the internal regulator).

The low-pin-count development kit(DV164126) was created with the USB novice in mind. It includes a selfdirected course and lab material designed to ease the learning curve associated with adding USB connectivity to embedded systems. The kit contains two development boards, one fully populated and one unpopulated spare development board, one PIC18F14K50 debug header, a CD containing the user guide, course materials,and product documentation. In addition, a PICkit 2 (and USB cable) is included for debugging and programming. The PIC18F14K50 costs $2.50 per unit and the demo board costs $60.

PIC18F66J50
The 8-bit PIC18F66J50 is for costsensitive applications that need more I/O support. It comes in a 64-pin TQFP package and includes an 8-bit parallel master port/enhanced parallel slave port for communicating with external devices like QVGA and memory.

This part has a 2.5-V internal voltage regulator derived from a maximum 3.6-V input (it has 5.5-V tolerant digital I/Os) and can run down to 2 V (without the internal regulator).

The PIC18F87J50 FS USB plug-in module (PIM) is a full-speed USB demonstration board (MA180021).While the PIM is made for use with the HPC explorer board, it can be used on its own. The PIM comes with preinstalled application software that demonstrates how to use a PIC18F87J50 as a HID peripheral mouse. You can use your ICD2 or PICkit 2 to debug and program the microcontroller on this board. The PIM ships with a CD-ROM containing example USB projects that can be used directly with the board. The PIC18F66J50 costs $3.50 per unit and the demo board costs $40.

PIC18F4550
The 8-bit PIC18F4550 is the oldest member of this group. A streaming parallel port (SPP) can be used in conjunction with the USB port for rapid data movement to and from an external device.

The PIC18F4550 operates from a power supply of 3 to 5.5 V. There is aF version that operates down to 2 V. In addition to BOR and POR, this chip includes high/low voltage detect(HLVD) functions.

The PICDEM FS_USB demonstration board(DV163025) isn new. In fact, Ie had mine for years. While the board comes preloaded with code to access a temperature sensor, a potentiometer,LEDs, and switches via a PC application,it was the bootloader that I found most useful. The onboard serial port is also helpful in making the jump from a serial RS-232 connection to USB. You can use your ICD2 to debug and program the microcontroller on this board. However, the PIC18F4550 can be reprogrammed in circuit without an external programmer when using a bootloader. The PIC18F4550 costs $4.50 per unit and the demo board costs $60.

PIC24FJ256GB110
The 16-bit PIC24FJ256GB110 is the least expensive member of the group that offers OTG capability. It has several useful peripheral functions that don appear on the other chips. A CTMU supports capacitive touch applications. With peripheral pin select, you can remap the I/Os of many peripherals in real time. It also has a hardware RTCC and a programmable cyclic redundancy check (CRC)generator. External devices like QVGA and memory can be controlled through the 8-bit parallel master/slave port (PMP/PSP).

The PIC24F starter kit(DM240011) contains everything needed to begin exploring the high performance and versatility of the PIC24F microcontroller family (see Photo 3)。 This inexpensive kit includes an integrated in-circuit debugger and programmer,a USB device and host connectors, a tricolor LED, a capacitive touch pad, and an OLED display. Menu-driven demonstration software supports CIRCUIT CELLARata logging, a thumb drive, and graphics applications to test the PIC24F microcontroller.


The PCB includes integrated hardware debug and programmer circuitry to develop, program, and test applications on the board PIC24F microcontroller. A USB connection to a host computer supplies communications and power to the board. No additional external power supply is needed. The kit comes with preinstalled application software that demonstrates the interactive, menu-driven display using a parallel master port (PMP), capacitive touch sensing with the charge time measurement unit (CTMU), time and data display using the real-time clock and calendar (RTCC), RGB LED control with three PWMs and peripheral pin select (PPS), a USB flash drive interface (USB embedded host), real-time data graphing using the ADC, display multitasking, and real-time data capture using multitasking(USB embedded host).

The kit contains a PIC24F board with an integrated debugger, a USB cable, and the MPLAB starter kit CD containing an MPLAB IDE, an MPLAB C compiler for PIC24 MCUs, application notes, and sample programs. The PIC24FJ256GB110 costs $6 per unit and the demo board costs $60.

PIC32MX460F512L
The high-performance 32-bit PIC32MX460F512L is for applications that need a lot of local computing power in addition to the USB OTG capability and other peripheral functions. It also has a hardware RTCC. External devices like QVGA and memory can be controlled through the 16-bit parallel master/slave port(PMP/PSP).

The PIC32MX460F512L has a 256-byte prefetch module that speeds the execution of the execution unit(EU) while delivering the fastest context switch and interrupt response possible. There are four channels of DMA for remarkable throughput without EU intervention. Atomic bit manipulation provides separate registers for each I/O register to clear, set, and invert any bits of that I/O register.

The PIC32 USB starter board (DM320003)provides the easiest and lowest-cost method to experience the USB OTG family of PIC32 microcontrollers(see Photo 4).You can develop USB embedded host,device, dual-role, or OTG applications by combining this board with Microchip‘s free USB software. The USB starter board has an expansion connector and can be used with the PIC32 I/O expansion board and PICtail Plus daughter cards. The starter board comes with a standard type-A to micro-type-B cable for the built-in debugger,a standard type-A to micro type-B cable for USB application development,and a quickstart card directing users to web-based instructions for software download and installation. No software is provided in the box.


The free 32-bit software resources available include USB host and device stacks, a graphics and audio library, a TCP/IP stack with SSL, 16- and 32-bit file system support, and CAN software. The PIC32MX460F512L costs $7.50 and the demo board costs $50.

SUPPORT
Obviously, just offering the OTG hardware in a microcontroller to handle a USB host is not a total solution. Originally intended as a replacement for serial and parallel connections on a PC to connect mice, keyboards, and printers, USB has grown to be the standard interface between a PC and its many and varied peripherals. With the addition of an embedded host and OTG, the interface has expanded to any product that would benefit from its features,like audio devices (digital file sharing,audio and MP3 connectivity), handheld scanners and meters (download data), and industrial control and medical monitoring (upgrade software,download diagnostics for analysis)。 To help you integrate USB into your product, Microchip offers a three-step USB solution. First, it offers a wide variety of 8-, 16-, and 32-bit USB MCUs for basic, low-cost applications to complex and highly integrated systems. Second, Microchip offers free license software libraries (including source code)。 Finally, they have a variety of low-cost and full-featured development tools and a free IDE, so you can quickly integrate USB functions into your existing application using a single microcontroller, reducing total system cost, development risk, and time to market.

Table 3 lists USB-related technical briefs and application notes presently found on the Microchip web site. Microchip‘s "MCHPFSUSB Framework v2.2" and "USB Device and Embedded Host Stack for PIC32 v1.03"-which cover PIC18/24 and PIC32 devices-are two files that contain a variety of USB-related firmware projects, drivers, and other resources. Microchip also has Web- Seminars that you can view on the site. Archived USB-related broadcasts include "Emulating RS-232 Over USB Using the PIC18F4550" and"Tutorial for the MPLAB Starter Kit for PIC24F."


USB-IF
To use the USB logo, a product must pass compliance testing as defined by the USB-IF. For instance,OTG-compliance testing includes the physical inspection of the microcontroller- AB receptacle and user interface display, signal quality as a host and as a device, OTG electrical test (OET), OTG protocol test (OPT),interoperability with all devices listed on the targeted peripheral list,and submission of a completed USB OTG compliance checklist. The compliance tests ensure that your product plays well with others. Visit www.usb.org for more information about compliance testing.

HORIZONTAL MARKET STRATEGIES
Up to this point, "plays well with others" has meant the PC. Although there will still be many products that must connect to a PC, OTG devices may never need to connect to a PC. They may never have to deal with a standard or custom Microsoft driver. For instance, the camera/printer OTG pairing makes a happy couple and requires no PC intervention.

The temporary and permanent storage and exchange of audio, video,and data files is thriving thanks to solid-state storage media. By far, the most popular function for USB is the moving of data. USB has made the thumb drive common place. I see them around necks, on key chains,and hanging up in groups waiting their turn in a rotational game of daily system backups. A product that supports MSD may never need to connect to anything other than a thumb drive.

One of the features that flash memory microcontrollers have brought to products is the ability to update their own operating systems. Back in Circuit Cellar 200, I used a USB MSD device in a logger for my electric bicycle project ("Embedded USB Breakthrough," 2007)。 When a thumb drive was plugged in, the files were searched for a particular file name. If it found a file with that name, it used the bootloader to read in the file (a new operating system)

and reboot. This, however, is cause for the USB-IF to sit up and take notice because this may violate compliance. The USB-IF states that if any changes are made to the product, creating"significant differences"between the production product and the product samples tested, retesting is required. They state that as long as the PCB hasn‘t changed and the USB function code remains unchanged,retesting is not required.

I'm predicting that the sensor market will take up USB with open arms. Up to this point, USB peripheral developers have been wearing blinders. Products were developed only if the PC could make use of it. With full support for embedded hosting and OTG, I think we will see smart sensors being developed for embedded hosts. Smart sensors provide their hosts with the information necessary to make use of the sensor without any manual configuration.

Microchip has readied itself for the USB onslaught. It can provide you with the parts, tools, and information to make it happen (see Photo 5).



Jeff Bachiochi (pronounced BAH-key-AH-key) has been writing for Circuit Cellar since 1988. His background includes product design and manufacturing. You can reach him at jeff.bachiochi@imaginethatnow.com or www.imaginethatnow.com.


RESOURCES
J. Bachiochi, "Accessing the USB Framework: A Quick Transition from UART to USB," Circuit Cellar 195,2006.

---, "Create a USB Hybrid Hub,"Circuit Cellar 170, 2004.

---, "Embedded USB Breakthrough,"Circuit Cellar 200, 2007.

---, "USB DMX," Circuit Cellar 172,2004.

---, "USB in Embedded Design,"Parts 1 and 2, Circuit Cellar 165 and166, 2004.

Microchip Technology, Inc.,"PIC18F87J50 Family Data Sheet:64/80-Pin High-Performance, 1-Mbit Flash USB Microcontrollers with nanoWatt Technology," DS39775B,2007.

---, "PIC32MX3XX/4XX Family Data Sheet: 64/100-Pin General Purpose and USB 32-Bit Flash Microcontrollers,"DS61143D, 2008.

K. Otten, "Tutorial for MPLAB StarterKit for PIC24F," Microchip Technology,Inc., 2008, http://techtrain.microchip.com/webseminars/documents/PIC24FStrKit_031708.pdf.

R. Rojvanit, "Emulating RS-232 over USB with PIC18F4550," Microchip Technology,
2004, http://techtrain.microchip.com/webseminars/documents/EmulatingRS-232overUSB_121004.pdf.

SOURCE
PIC18F14K50, PIC18F4550, PIC18F66J50,PIC18F87J50, PIC24FJ256GB110, and
PIC32MX460F512L Microcontrollers,DM164127 development kit,DM240011 starter kit, DM320003 starter board, DV163025 demonstration board, and PICkit 2 development
programmer/debugger
Microchip Technology, Inc.
www.microchip.com
类别:信号处理 |
上一篇:天空导航(Navigating the Heavens) | 下一篇:可控硅(Triac Behavior)
以下网友评论只代表其个人观点,不代表本网站的观点或立场