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 // */
}

Parents
  •    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?

Reply
  •    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?

Children
No data