the new pic16f62x series flash micro controller from microchip packs a lot of bang

Upload: sridhar-chandrasekaran

Post on 07-Apr-2018

218 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/4/2019 The New PIC16F62X Series Flash Micro Controller From Microchip Packs a Lot of Bang

    1/6

    The new PIC16F62X series flash microcontroller from Microchip packs a lot of bang-for-the-buck, and the cost per controller "even in small quantities" is considerably less thanthe older PIC16F84 controller.

    Cost Comparison:

    The PIC16F628-04/P normally runs around $3.63 each in single quantity. The older

    PIC16F84-04/P runs around $6.88 each in single quantity. The 16F628 has 2K programcode space, whereas the 16F84 has only 1K. The 16F628 has additional hardwareperipherals not available on the 16F84 series as well.

    Note: Prices will change like the wind depending on where you buy microcontrollers, sothese prices are only estimates based on several sources at the time of putting togetherthis article.

    The PIC16F628 is kind of like a baby version of the popular PIC16F877, but in an 18-pinDIP package instead of the larger 40-pin DIP package. It doesn't have all the features ofthe larger F877, but it's a 100% improvement over the 16F84.

    Just imagine a PIC16F84 with:

    2K program memory (instead of 1K)224 x 8 Data RAM128 x 8 EEPROM data memory15 I/O-pins (instead of 13)Internal or external oscillator (instead of external only)Capture, Compare, PWM (CCP) ModuleHardware USARTAnalog comparator module

    Now. Imagine paying $3.25 less for this microcontroller than the PIC16F84, and youhave the PIC16F628. Not a bad deal, and they're simple to use.

    For the hobbyist or embedded systems engineer - a difference of $3.25 per controller

    adds-up pretty quickly and the additional program memory, data RAM/EEPROM, andhardware features, make the 16F628 pretty much a no-brainer when selecting an 18-pinflash PIC microcontroller for that next project.

    Two primary things to consider when replacing the 16F84 with the 16F628 are the port Acomparators, and the internal 4MHz oscillator available on the 16F628.

    Port A comparator module:

  • 8/4/2019 The New PIC16F62X Series Flash Micro Controller From Microchip Packs a Lot of Bang

    2/6

    Unlike the 16F84, the 16F628 Port A pins (A0, A1, A2, A3) default to comparator inputson power up. The comparator mode control register CMCON controls the comparator

    input and output multiplexers, and will also turn OFF the onboard comparator module toallow Port A pins to be used as normal I/O-pins.

    An external or internal reference can be used depending on the comparator operatingmode. The analog signal present on VIN- is compared to the signal at VIN+, and thedigital output of the comparator is adjusted as shown below.

    For a detailed explanation of using the onboard comparator module download thePIC16F628 datasheet from the Microchip web site.

    There are several options for configuring the comparators that require the datasheet asa reference guide, and detailed info on using the comparator module goes well beyondthe scope of this article.

    Using the Port A comparator pins for normal I/O.

    The lower 3-bits (CM2, CM1 and CM0) of the CMCON register control thecomparator MODE. Out of eight possible modes, a value of "7" loaded into CMCON turnsthe comparators OFF, and allows all of Port A to function as normal digital I/O.

    Writing a value of 7 (binary 00000111) to CMCON turns OFF the comparators. UsingPicBasic Pro, you simply add the following line of code to the beginning of your programto turn OFF the comparators, and use these pins as normal digital I/O-pins:

    CMCON = 7

    Using assembly language, turning OFF the comparator module can be accomplished by:

    MOVLW 0x07 ; Load 7 into W registerMOVWF CMCON ; CMCON = contents of W register 7h

    Port A.0, A.1, A.2, and A.3 will now operate as normal I/O-pins with comparators turnedOFF.

    Using the internal 4MHz Oscillator

  • 8/4/2019 The New PIC16F62X Series Flash Micro Controller From Microchip Packs a Lot of Bang

    3/6

    Depending on the PIC device programmer you're using, there should be an option forsetting the configuration-bits. The example shown below is what you'll see on screenwhen using the PicStart Plus programmer from Microchip.

    Note: If you have an older version of the PicStart Plus you may need to upgrade thePicStart Plus firmware for support of the newer PIC16F62x series.

    The firmware upgrade is worth the investment, and you'll save considerably more $$than the cost of the firmware upgrade when using the 16F62x series microcontroller asopposed to the older "more expensive", and less capable 16F84.

    If you're using the EPIC programmer, click the drop-down menu for configuration, thenoscillator, and select the following oscillator configuration shown below:

    Note: Notice the oscillator selection INTRC (IN) with the EPIC, and Int RC with thePicStart Plus..? The oscillator pins on the 16F628 are RA.6, and RA.7.

    Tip #1: One nifty little un-documented trick when using the PicBasic Pro compiler is toplace the following line in the head of your program code file: @ deviceINTRC_OSC_NOCLKOUT

    This tells the PicBasic Pro compiler to compile your code using the internal oscillatorautomatically, and you never need worry about it again.

  • 8/4/2019 The New PIC16F62X Series Flash Micro Controller From Microchip Packs a Lot of Bang

    4/6

    Port-pin RA.6 can be programmed to output a clock signal 1/4 the oscillator frequency,or it can function normally as an additional bi-directional digital I/O-pin. Running on the

    internal 4MHz oscillator, RA.6 can output a 1MHz clock signal by selecting (INTRCClockout), or RA.6 may be used for normal digital I/O by selecting INTRC (IN).

    You cut down the required number of external components (no crystal/capacitors orceramic resonator), and gain two additional I/O-pins in the process......

    Tip #2: Notice on the PicStart Plus configuration bits picture above that the MasterClear (MCLR) selection has been disabled. This eliminates the need for the external 4.7Kpull-up resistor on RA.5 you'll see in most other PIC circuits.

    Not really a big-deal, but it does reduce the parts-count even further by eliminating thisresistor from MCLR (RA.5) to Vcc.

    Multitasking

    One H-U-G-E benefit of using the onboard hardware features of the PIC16F628 is theability to have [TRUE] multitasking. Once you have configured the onboard hardware

    registers, and turned on the hardware peripheral feature, it runs in the backgroundwithout further program code requirements or outside intervention.

    A line of code or sub-routine that's required to make something happen, written in C,BASIC, assembly, or whatever; simply is not multitasking. Background hardwareoperation "on its own" is.

    Below is a code sample showing how to use hardware PWM with the PIC16F628 &PicBasic Pro. To use this code, connect three LEDs (as shown below) to each port-pinB.0, B.1, and B.2 through 470-ohm series resistors to ground.

    Connect an oscilloscope to PortB.3 to view the PWM signal of approximately 38.5KHzoutput on B.3 using internal hardware PWM.

    Here's a peek at what the hardware PWM signal looks like using the internal oscillatoroption:

  • 8/4/2019 The New PIC16F62X Series Flash Micro Controller From Microchip Packs a Lot of Bang

    5/6

    If you really want to get fancy, and see how multitasking works when using internalhardware features, try sending tons of serial data in a tight loop, and watch the PWMsignal.

    It's totally un-affected by anything until you physically modify the control registers.

    CMCON = 7 ' PortA = digital I/O

    VRCON = 0 ' A/D Voltage reference disabled

    TRISB = %11110000 ' B.3=PWM,B.0,B.1,B.2 blink LEDs

    PR2 = 25 ' Set PWM for approximately 38KHz

    CCPR1L = 13 ' Set PWM Duty-Cycle to 50%

    CCP1CON = %00001100 ' Mode select = PWM

    T2CON = %00000100 ' Timer2 ON + 1:1 prescale

    begin:

    high PortB.0

    pause 50

    low PortB.0

    pause 50

    high PortB.1

    pause 50

    low PortB.1

    pause 50

    high PortB.2

    pause 50

    low PortB.2pause 50

    goto begin

    If you own the PicBasic Pro compiler, try programming this code into the PIC16F628, and

    setting the oscillator as internal. Next try setting it as external, and use a 4MHz ceramicresonator or external crystal. This will give you an idea of how the internal oscillatortiming compares to an external oscillator.

    This will give you a good look at why you may want to use an external oscillator fortiming critical applications as well.

    If you don't own the PicBasic Pro compiler or just prefer to do it the easy way, I havepre-compiled a couple files here for you.

  • 8/4/2019 The New PIC16F62X Series Flash Micro Controller From Microchip Packs a Lot of Bang

    6/6

    ClickHEREfor INT-PWM.TXT (Save as INT-PWM.HEX)ClickHEREfor EXT-PWM.TXT (Save as EXT-PWM.HEX)

    INT-PWM.HEX uses the internal oscillator. The other uses an external oscillator @ 4MHz.Both files will output a 38.5KHz PWM signal on PortB.3 - while port-pins B.0, B.1, andB.2 blink three LEDs.

    Note: INT-PWM.HEX will be slightly OFF-frequency due to the internal oscillator beingused. A slight fudge-factor normally will be necessary to get a precise PWM signal usingthe internal oscillator, and it will vary from PIC-to-PIC due to process variables.

    Your mileage may vary .....!

    ClickHEREto stock-up on PIC16F628 or F627 micros.ClickHEREto purchase PicBasic Compilers - and hardware.ClickHEREto learn more about the PicBasic compiler.ClickHEREto return to the PicBasic projects page.

    Until the next project - have fun, don't blow anything up, and thanks for stopin by...;o]

    http://www.rentron.com/Files/int-pwm.txthttp://www.rentron.com/Files/int-pwm.txthttp://www.rentron.com/Files/int-pwm.txthttp://www.rentron.com/Files/ext-pwm.txthttp://www.rentron.com/Files/ext-pwm.txthttp://www.rentron.com/Files/ext-pwm.txthttp://www.rentron.com/Products/PIC-Micro.htmhttp://www.rentron.com/Products/PIC-Micro.htmhttp://www.rentron.com/Products/PIC-Micro.htmhttp://www.rentron.com/PicBasic/PBP.htmhttp://www.rentron.com/PicBasic/PBP.htmhttp://www.rentron.com/PicBasic/PBP.htmhttp://www.rentron.com/PicBasic2.htmhttp://www.rentron.com/PicBasic2.htmhttp://www.rentron.com/PicBasic2.htmhttp://www.rentron.com/PicBasic1.htmhttp://www.rentron.com/PicBasic1.htmhttp://www.rentron.com/PicBasic1.htmhttp://www.rentron.com/PicBasic1.htmhttp://www.rentron.com/PicBasic2.htmhttp://www.rentron.com/PicBasic/PBP.htmhttp://www.rentron.com/Products/PIC-Micro.htmhttp://www.rentron.com/Files/ext-pwm.txthttp://www.rentron.com/Files/int-pwm.txt