Free Print Subscription Printer-friendly version Email to a Friend

Unused port adds a PWM/analog channel to a microcontroller

( 01 Feb 2010 )
By Vishwas Vaidya, Tata Motors Ltd, Pune, India

Low-cost, 8-bit, single-chip microcontrollers are stingy when it comes to on-chip PWM (pulse-width-modulation) resources. The use of a PWM resource often forces a designer to sacrifice a capture/compare or timer channel because the PWM channel shares the same on-chip hardware. This Design Idea describes how you can use an on-chip unused synchronous serial port to generate PWM signals and convert them to a slow-moving analog signal (Figure 1). Many microcontroller-based stand-alone electronic units don’t use the synchronous serial port. Thus, you can use the microcontroller’s baud-rate generator and parallel-to-serial-converter blocks to generate bit patterns to form a 256-bit PWM pattern. You can then filter the PWM output with an RC filter to extract an analog signal (Reference 1). The synchronous communication is devoid of the start and stop bits of asynchronous mode, so the bit pattern can generate long periods of high or low level.

You can generate raw data with a decimal value of 165 using this concept (Figure 2). A PWM-conversion cycle consists of generating 256 bits—that is, 32 bytes. The number of “on” bits corresponds to the value of the raw data to convert into PWM. Hence, for 165 bits as the raw data, 165 bits are on and 91 bits are off. To generate a 165-bit on-period, the first 20 bytes—that is, 160 bits—transmit as 0×ff on-state bytes. The trick lies in judiciously composing the 21st, or transition, byte. This byte has some of its LSBs (least significant bits) as ones and the rest as zeros to form the required length of the on-period. In this case, the circuit needs five more on bits: 160+5=165. Hence, the transition byte should have a 00011111b pattern (byte=0×1f).

Figure 3 illustrates the process in flow-chart form. You can tailor the PWM frequency to your application by selecting a crystal, PLL (phase-locked loop), and baud rate. A simple RC filter can convert the PWM into a slow-moving analog value. Although this idea describes an 8-bit PWM, you can increase or decrease resolution by changing the total bits per PWM cycle. You correspondingly increase or decrease the conversion time.

Listing 1 provides a sample code for illustrating the concept. The code uses the Microchip PIC18F4525, which has a 4MHz crystal and 10kHz baud rate for the synchronous serial communication, yielding 10,000/256=39.31 Hz of PWM frequency. You can filter it with a 0.1s RC filter, which is sufficient for slow-moving analog signals, such as speed setpoints for motion-control applications. By using a 20MHz crystal, you can achieve synchronous serial baud rates greater than 1.5MHz and PWM frequencies of a few kilohertz.


Figure 1



Figure 2



Figure 3



Reference
1. Mitchell, Mike, “Make a DAC with a microcontroller’s PWM timer,” EDN, Sept 5, 2002, pg 110.

 
Free Print Subscription Printer-friendly version Email to a Friend
 
Article Rating 
Average Rate: No rating yet
 
Poor Quite Good Good Very Good Excellent
 
 
ADVERTISEMENT
 
Related Content 
 
 
LIVE WEBCAST

ON-DEMAND WEBCASTS

RESOURCE CENTER
 
 
Highest Rated  
Feedback Loop  

ADS BY GOOGLE 
 
 
 
ADVERTISEMENT
Press Release 
 
TECHNOLOGY NEWS
 
 
 
PRODUCT NEWS
 
FEATURED SPONSORS
 
 
 
DESIGN CENTERS
 
ADVERTISEMENT
     
Reference Designs 
   
     
 
 
 
 
 
 

RSS
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   

POLL
What type of environmental regulation do you think will be most beneficial for the tech industry?
Proper recycling and disposal
Push for power efficiency and energy conservation
Chemical/lead regulation
View results


     
Power Technology E-newsletter 
Dual-input, Single-output Power Supply Selector Switch Reduces System Size while Improving Integrity EDNA, February 08
Analog Devices completes sale of CPU voltage and PC thermal monitoring business to ON SemiconductorEDNA, January 08
Fairchild’s Green FPS Power Switches Increase Efficiency, Reduce EMI in Power Supply Designs EDNA, December 07
 
Test and Measurement E-newsletter 
Agilent Technologies and Anite Announce Strategic Partnership to Deliver 3GPP LTE Test Solutions for Wireless R&D EDNA, November 07
WiMAX Technology Leaders Aeroflex and Sequans Partner to Speed Product Development and Deployment of WiMAX Test EDNA, October 07
Tektronix’ IMS Solution Proves Successful in Industry Forum Tests EDNA, September 07
 
     
 
KNOWLEDGE CENTER
 
Texas Instruments: DaVinci™ Technology
 
Texas Instruments: Safe Bet Series
 
 
INDUSTRY LINKS
 
Photonics Association (Singapore)
Singapore Industrial Automation Association (SIAA)
Taiwan Semiconductor Industry Association (TSIA)
 
 
 
 
OUR SPONSORS
 






Keithley Instruments
With more than 60 years of measurement expertise, Keithley Instruments has become a world leader in advanced electrical test instruments and systems from DC to RF (radio frequency). Our products solve emerging measurement needs in production testing, process monitoring, product development, and research...
 
 
ADS BY GOOGLE
 
 
     
 



Canon Communications Asia
EDN India | EDN Taiwan | EDN Korea | EDN Japan | EDN China | EDN | EDN Europe

 
ABOUT EDN Asia | FREE SUBSCRIPTION | CONTACT US
   
© 2010 Canon Communications
All rights reserved. Use of this web site is subject to its Terms and Conditions of Use. View our Privacy Policy.