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

Reposting of question about timer speed with

This routine runs but it runs fast the crystal is 12Mhz and the configuration


/*
*FILE NAME:    msecWait.c
*
*NOTE:Since the counter counts up it is necessarey to *     subtract the nuber of counts/millsecnd from the *     maximum count for Counter 0 which is 0xFC65) *     seperated into bytes(unsigned char) hiByte =
*     0xFC and lowByte = 0x65.
*
*DESCRIPTION:  Delays for the input argument number *              of miliseconds
*
*INPUTS: Requested number of miliSeconds (0.001 *        Seconds) to delay
*
*OUTPUTS:        processor is on hold for the proscribed *          number of milliseconds
*
#include "F100GlobalDataTypeDefs.h"
#include "F100GlobalDef.h"
#include "F100GlobalVars.h"
#include "F100Functions.h"
#include "F100HW.h"
#include <stdio.h>
void msecWait(unsigned int milliSeconds)
{
//1000 counts/(milisecond)
unsigned char highByte = 0xFC;
lowByte = 0x65;  // up count, thus count is
               //  from 64286 (FB1E)bit
bitET0, bitTR0; //      Storage locations

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) {;}  // wait for T0 to overflow
  TR0 = 0 ;        // stop timer 0 //
  TF0 = 0 ;      // Reset the overflow
  milliSeconds--;// Decrement the count
 } // end  while (milliSeconds > NOMILLISECONDS)

ET0 = bitET0; // Restore ET0 //
TR0 = bitTR0; // Restore TR0 //
} // end msecWait(unsigned int milliSeconds)

Parents
  • The number of counts of the 16 bit timer is 65,536.

    The counter counts up

    The count would be from 64535 to overflow

    64535 Decimal is hex is FC17.

    could that be it, you load fc65 per your code

    the translation to the internet the uchar on lowByte was lost

    NEVER "translate to the internet " ALWAYS cut-and-paste. When you retype, errors are discussed you do not have that appear in the retype, but not in your code.

    Erik

    PS, you have tabs in the displayed code, always convert tabs to spaces before posting

Reply
  • The number of counts of the 16 bit timer is 65,536.

    The counter counts up

    The count would be from 64535 to overflow

    64535 Decimal is hex is FC17.

    could that be it, you load fc65 per your code

    the translation to the internet the uchar on lowByte was lost

    NEVER "translate to the internet " ALWAYS cut-and-paste. When you retype, errors are discussed you do not have that appear in the retype, but not in your code.

    Erik

    PS, you have tabs in the displayed code, always convert tabs to spaces before posting

Children