This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Timer runs to fast with a 12 MHz crystal

The crystal is a 12 Mhz
//#include "F100GlobalDataTypeDefs.h"
//#include "F100GlobalDef.h"
//#include "F100GlobalVars.h"
//#include "F100Functions.h"
//#include "F100HW.h"

void msecWait(uint milliSeconds)
{ /* Since the counter counts up it is necessarey to subtract the nuber of counts/millsecnd from the maximum count for the sixteen bit unsigned intiger (65535 - 922 = 64613 = 0xFC65) seperated into bytes (uchar) hiByte = 0xFC and lowByte = 0x65 */
// uchar highByte = 0xfc, lowByte = 0x65; //922 counts/(milisecond up count) // count is from 64613 (0xfc65)

// bit bitET0, bitTR0;

/************ Based on 12 MHz crystal**** Input in miliseconds ***************

bitTR0 = TR0; // Save TR0 //
TR0 = 0; // Stop T0 //
bitET0 = ET0; // Save ET0 //
ET0 = 0; // Disable T0 //
while (milliSeconds > NOMILLISECONDS) { TH0 = highByte; TL0 = lowByte; TR0 = 1; //start timer 0 // while (!TF0) {;} TR0 = 0 ; // stop timer 0 // TF0 = 0 ; milliSeconds--; }
ET0 = bitET0; // Restore ET0 //
TR0 = bitTR0; // Restore TR0 // */
}

  • It's the 3rd of the 4 bullet points immediately above the 'Message' box where you type your post!

    Use the 'Preview' button to confirm that it's legible.

    And describe how you've determined that it's "too fast"

  • Where's the question?

    Please use the pre and /pre tags when posting source code.
    

    ...and it seems to be all comment (?).

    --
    Joost

  • Did you took care about the mode in which the timer0 is running.
    Its possible that the timer is running as 8 bit timer and not 16 bit as intended.

    Suvidh

  • The set up is:

            //---------  Serial Communication Set-up -----------
    
        SCON   = 0x70;                  // Set serial communication in mode 01
                                                                       // (8-bit) and reciever enabled (RI = 1).
        PCON   = 0x00;                //  Set SMOD0 = 0.
            T2CON &= 0xF0;                   //  Set timer 2 as baud rate generator.
            RCAP2H = 0xFF;              //  Set 9600 baud high.
            RCAP2L = 0xD9;             //  Set 9600 baud high.
            SADEN  = 0xFF;                //  Enable slave address
                                     //  for automatic address recognition.
            SADDR  = F100ADDRESS;   //  Address of data byte (0xF3).
            RCLK   = 1;                        //  Receiving baud rate clock.
            TCLK   = 1;           //  Transmission baud rate clock.
            SM2    = 1;                  //  Enable automatic address recognition.
            IE     = 0x1E;      //  Enable timer 1, 0, External 1, and serial interrupts.
            EA     = 1;                //  Enable global interrupt flag.
            TR1    = 1;               //  Start timer 1.
            TR2    = 1;      //  Start timer 2.
            ET1    = 1;             //  Enable Timer 1 interrupt.
            EX1    = 1;        //  Enable External interrupt 1.
            IP     = 0x10;//  Set Serial Interrupt as highest priority.
    


    Checking on th 8-16 bit

  •    SCON   = 0x70;        // Set serial communication in mode 01
                             // (8-bit) and reciever enabled (RI = 1).
       PCON   = 0x00;        //  Set SMOD0 = 0.
       T2CON &= 0xF0;        //  Set timer 2 as baud rate generator.
       RCAP2H = 0xFF;        //  Set 9600 baud high.
       RCAP2L = 0xD9;        //  Set 9600 baud high.
       SADEN  = 0xFF;        //  Enable slave address
                             //  for automatic address recognition.
       SADDR  = F100ADDRESS; //  Address of data byte (0xF3).
       RCLK   = 1;           //  Receiving baud rate clock.
       TCLK   = 1;           //  Transmission baud rate clock.
       SM2    = 1;           //  Enable automatic address recognition.
       IE     = 0x1E;        //  Enable timer 1, 0, External 1, and serial interrupts.
       EA     = 1;           //  Enable global interrupt flag.
       TR1    = 1;           //  Start timer 1.
       TR2    = 1;           //  Start timer 2.
       ET1    = 1;           //  Enable Timer 1 interrupt.
       EX1    = 1;           //  Enable External interrupt 1.
       IP     = 0x10;        //  Set Serial Interrupt as highest priority.
    


    Isn't that better?