Solved

No Timer1 interrupt on 8051 using Keil C

Posted on 2004-05-02
4
657 Views
Last Modified: 2013-12-10
I am writing code for a P89C664 8051 variant to control a radio control car. I had the code working using timer0 and timer2, but needed to switch to using timer0 and 1 as i needed timer2 for the baud rate generator to increase my baud rate. The problem is now i dont seem to be getting the timer1 interrupt.

Any ideas please?

sbit STROUT = P2^0;
sbit MTROUT = P2^1;

int TempVal = 0, MilliCount = 0;
signed int SteeringVal = 0, MotorVal = 0;
double SteeringScale = 1.667, MotorScale = 1.667;
int SteeringCentre = 4800, MotorCentre = 4500;

/** Initialisation *******************************************************/
void InitDevices()
{
      /** Set motor & steering output pins ***/
      STROUT = 0;
      MTROUT = 0;

      /** Init timers for car control ********/
      //Initialise Timer1 to 16-bit timer with interupt
      TMOD |= 0x10;

      //Initialise Timer0 to 16-bit timer with interupt
      TMOD |= 0x01;
      TL0 = 0xFA;
      TH0 = 0xF2;
      TR0 = 1;

      /** Enable Interrupts ******************/
      EA = 1;      //Global enable
      ET1 = 1;      //Timer1 enable
      ET0 = 1;      //Timer0 enable
}

/** Timer0 Interrupt *****************************************************/
void Timer0Interrupt() interrupt 1
{
      //Stop timer
      TR0 = 0;      
 
      //Increment ms counter
      MilliCount += 10;

      //Do steering control pulse
      if(MilliCount == 10)
      {
            TempVal = 65536 - (SteeringCentre + (SteeringVal*SteeringScale));
            TL1 = 0x00FF & SteeringVal;
            TH1 = (0xFF00 & SteeringVal)/256;
            STROUT = 1;
      }

      //Do motor control pulse
      if(MilliCount == 20)
      {
            TempVal = 65536 - (MotorCentre + (MotorVal*MotorScale));
            TL1 = 0x00FF & MotorVal;
            TH1 = (0xFF00 & MotorVal)/256;
            MTROUT = 1;
            MilliCount = 0;
      }

       //Reload value
      TL0 = 0xFA;
      TH0 = 0xF2;

      //Start Timer1
      TR1 = 1;

      //Start Timer0
      TR0 = 1;

      //Clear interrupt
      TF0 = 0;
}

/** Timer0 Interrupt *****************************************************/
void Timer1Interrupt() interrupt 3
{
      //Stop Timer1
      TR1 = 0;

      //Clear pins
      STROUT = 0;
      MTROUT = 0;

      //Clear interrupt
      TF1 = 0;
}
0
Comment
Question by:sclarke81
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 17

Expert Comment

by:mokule
ID: 10982423
Hi,
Are You sure that TH1,TL1 is > 0xF2FA? From the code above it can't be seen.
0
 

Author Comment

by:sclarke81
ID: 10982716
Hi,

I cant believe I was being so dumb! I needed to change the reload value for timer0 to give me 10ms interrupts...

Thanks alot mate, youre a star!

PS I dont suppose I could be cheeky and ask if you have any C code for interrupt driven serial comms? Currently I just have my main prog waiting for incoming data with a gets() command. Also would it screw up the serial comms if timer 0 and 1 had higher interrupt priorities? or would i need a buffer?
0
 
LVL 17

Accepted Solution

by:
mokule earned 500 total points
ID: 10984477
Hi
The problem is I'm not using Keil C.
General rule is that it depends on serial comm speed, oscilator frequency and time consuming interrupt routine.
It would be better not to perform these
  TempVal = 65536 - (SteeringCentre + (SteeringVal*SteeringScale));
 TempVal = 65536 - (MotorCentre + (MotorVal*MotorScale));
in an interrupt routine.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: When a connection to the internet is established, there always exists a modem between the connected device and the ISP (Internet Service Provider). The Operating System (OS) on your PC controls the modem which communicates with the …
Or at least that’s the word according to a new blog from Tech Target on AWS’s new Managed Services (MS) offering. According to the blog, AWS is launching their AWS MS program to expedite the adoption of cloud by Fortune 1000 and Global 2000 companie…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

631 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question