Crystals & Resonators

Discussion in 'General Electronics Chat' started by Mazaag, Mar 18, 2006.

  1. Mazaag

    Thread Starter Senior Member

    Oct 23, 2004
    Hey guys,
    I just purchased both a 3pin 4.00MHz Ceramic Resonator (CST4.00MGW) aswell as a 20MHz "Crystal for MPU Clock" (20.000m-hc49). I want to connect one of them up to my PIC16F877 as a clock. Now my question is as follows:

    For the CERAMIC RESONATOR : DO i need additional circuitry ? if not , is there polarity on the resonator? ie: do i need to connect them in a specific way to my CLK in CLK out ? and is the middle pin the ground pin ?

    Same for the Crystal , do i need any additonal capacitors or resistors ? is there polarity ?

    One more question.
    Lets say I output a logical 1 to one of the ports on my PIC, say RA0, does that mean the PIC gives a VOLTAGE at that pin ? or is it a current? and how much (voltage or current) ? what is the name of this parameter ?

    thanks guys
  2. Ron H

    AAC Fanatic!

    Apr 14, 2005
    That resonator is a hard part to find a datasheet for. I did find the following quote at this site:

  3. Papabravo


    Feb 24, 2006
    Generally speaking when using a crystal there will be some small (15-30pf) capacitors from each lead of the crystal to ground. This provides some load in parallel with the crystal for the inverting amplifier inside the chip which goes from CLK_IN to CLK_OUT. The crystal manufacturer should specify on the data sheet the amount of load capacitence required.

    A microprocessor, as well as most digital logic parts have four numbers which describe the capabilities of an output. An ideal specification would give a minimum value , a typical value, and a maximum value for each of those four numbers. Real data sheets will may not have all three numbers.

    Vol (V-sub-O-L) : This is the voltage on the pin when the output is low.
    Iol (I-sub-O-L) : This is the amount of current that the output can sink without Vol rising above its maximum value.

    Voh (V-sub-O-H) This is the voltage on the pin when the output is high.
    Ioh (I-sub-O-H) This is the amount of current that a pin can source without Voh dropping below its minimum value.

    Let us take an example from the PIC16F873 that was the subject my PWM thread with damochi.

    Go to page 156 of the PIC16F873 datasheet.
    Parameter D0080 is Vol for the I/O Ports. It has a maximum value of 0.6 Volts
    The box all the way to the right lists some conditions.
    First condition is Vdd = 4.5 Volts, and the second is that Iol = 8.5 mA, and the third is that even over temperature Vol will not exceed 0.6V. So if Iol is less than 8.5 mA then Vol will probably be less than 0.6 Volts

    On the same page look at parameter D0090, this is Voh for the I/O ports.
    It says that the minimum value of Voh is (Vdd - 0.7) Volts. Again we have some conditions. Ioh is -3.0 mA, Vdd = 4.5 Volts, and the temperature is in {-40.0 to 85.0 degrees C}. The footnote says that negative currents mean that the pin is sourcing current. If the output tries to source more than 3.0 mA the voltage will dip below (Vdd - 0.7). If the output is sourcing only a small current then the output voltage will be very close to the rail.

    One conclusion to draw from all this is that even though a PIC pin can sink about three times as much current as it can source, you can drive an LED or similar load either way.

    Hope this helps
  4. Mazaag

    Thread Starter Senior Member

    Oct 23, 2004

    I'm not quite sure I know what you mean by sourcing and sinking. I'll do some reading and try to figure it out.

    Okay , so here's the deal.
    I wrote my little program in assembly for my PIC on MPLAB. Its a very simple and basic program. It just sends an output to RA0 and RA1 of PORTA. Thats all.

    Code ( (Unknown Language)):
    1. main
    3. bcf STATUS,RP1   ;
    4. bsf STATUS,RP0   ; RP1:RP0 = 01 Switch To Bank 1
    6. movlw b'111100' ; Set RA0 and RA1 to output
    7. movwf TRISA
    9. bcf STATUS,RP1
    10. bcf STATUS,RP0   ; RP1:RP0 = 00 Switch To Bank 0
    12. movlw b'000011'
    13. movfw PORTA
    16. end
    What I want to do now is debug it and simulate it. Could someone run me through the simple steps of what to use to be able to simulate this program and monitor the register values?
  5. Papabravo


    Feb 24, 2006
    In very simple terms:
    1. A current sourcing transistor(BJT or FET) is connected between the power supply and the load. In most cases the other end of the load is connected to ground.
    2. A current sinking transistor(BJT or FET) is connected between the load and Ground. In most cases the other end of the load is connected to the positive supply.

    It has been some time since I used MPLAB, and I'll check on it for you. There are three basic steps.
    1. Crate a project. There is a dropdown menu or a hot button for this purpose. This will pick the processor that you are using and name the source file with the program
    2. Build the project. This will invoke the assembler and the linker.
    3. Debug the project. This is where you will choose the simulator rather than downloading the output file into the Flash memory.

    What version of MPLAB do you have? I'm still using Version 7.1 which is about 1 year old.
  6. Papabravo


    Feb 24, 2006
    Steps to simulate a PIC program with MPLAB
    1. Launch MPLAB

    2. Invoke the Project Wizard and answer all thw questions
    Project | Project Wizard
    Step 1 Select a device
    Select your device from the drop down list
    Step 2 Select a language toolsuite
    Select Microchip MPASM toolsuite
    Step 3 Name your project
    enter name and directory location
    Step 4 Add any existing files to your project
    Select you source file and hit the Add button

    3. Project | Build All OR Control + F10

    4. Debugger | Select Tool -> MPLAB SIM

    5. View | Disassembly Listing

    6. View | Registers

    The Run/Step commands should be available on the main tool bar. Look for a button which has an arrow pointing into a pair of curly braces. This will single step the program and highlight the most recently changed registers in RED.