Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Timers and interrupts

Status
Not open for further replies.

impakt

Member level 4
Member level 4
Joined
Dec 19, 2005
Messages
68
Helped
2
Reputation
4
Reaction score
0
Trophy points
1,286
Activity points
1,799
timers and interrupts

I'd like to understand how timers and interupts work (doesn't matter the MCU). I know that timers are registers whose value is incremented every time an instruction is executed. What happens when it reaches it's maximum value? And when does an interrput occurs? What happens after??
 

port1_isr

When a timer reaches its maximum value (that's ffh(255d) for 8-bit,ffffh(65535d) for 16 bit timer) overflow occurs and it starts from beginning (00h) .If you have enabled its interrupt ,it jumps to the interrupt vector address when the overflow occurs.By that way you can run some code at specific time intervals.That's the basic explanation
 
ccs interrupt

coshkun said:
If you have enabled its interrupt ,it jumps to the interrupt vector address when the overflow occurs.By that way you can run some code at specific time intervals.
Can you be more specific please? When does the interrupt triggers?? What is the interrupt vector address? Thank you!
 

interrupt programs for infrared sensors

I don't know which language you use.In assembly(ex:8051),at the beginnings of programs you might see that lines:
org 00h
sjmp start
org 0bh
sjmp timer

0bh is the timer0 interrupt vector address.When timer0 overflows,PC jumps to the 0bh address automaticly and executes "sjmp timer" line.
You should study interrupts,first.
 

port1_vector

Hi Impakt,
If I remember correctly, you use the PIC micro, yes? If that is the case, your interrupt vector (in the 12Fxx and 16Fxx devices) is 0x04. The 18Fxxx has more than one, since it has low and high priority interrupts. (I think 0x04 and 0x08, but that is only from memory, the data sheet will tell...)
You have to then, write the code for your interrupt handler, and place it at that vector. You also have to enable the interrups you wish to use - ie: timer overflow, change on pin, serRx, Tx, etc. and enable global interrupts. The data sheet for your specific part will give you the details on how to do this.
I forget if you are using assembly, or a higher level language.
Can you be more specific please? When does the interrupt triggers?? What is the interrupt vector address? Thank you!
If you enable a timer0 interrupt on overflow, then when timer0 overflows, your Program Counter will be set to 0x04, and the Interrupt Service Routine you wrote, will execute. Depending on what language you are using, you may have to take care of some registers when this happens.
More questions, just ask.
Best wishes,
Robert
 
msp430 delay_us

I'm using CCS C for this project and I have to develop a code of a small robot based on a code given by the producer. I have something like:
Code:
// Timer 0 for Scheduler
setup_timer_0 (RTCC_DIV_4);
set_timer0(0);
enable_interrupts(INT_TIMER0);
....
#INT_TIMER0
void Scheduler_Interrupt(void)      // Internal Task Manager, Interrupt every 200 us
{                               
....
}
This function void Scheduler_Interrupt(void) will be executed everytime timer 0 overflows? Can I change the time timer 0 reaches it's maximum value? To interrupt on a change on pin I must use external interrupts (port B on PIC16F877)? After this function is executed form where does my program starts executing again? Or it executes the code following the interrupt function?

And a question about infrared sensors: this robot uses 8 infrared sensors which measures the proximity and the ambiental light with the same sensors. I can see the values colected from the sensors by the means of 2 commands given on the serial hyperterminal (in winxp). I looked at the codes of the commands and their similar (I'll post it if necesary). But the results are different from one command (proximity) and the other (light). How can this be?
Thank you for your answers.
 

ccs timer interrupt

hello impakt

sorry for not having answer for your question.
i'have the same question, but for MSP430

Code:
#pragma vector=PORT1_VECTOR                 // PORT_1 Interrupt Service Routine (ISR)
__interrupt void PORT1_ISR (void)

does that code means the routine should be coded in there? or else?
about interrupt edge select, does the interrupt instantly triggered when an edge is detected? or does it need to be polled?
anyone have a sample code?
thanks
 

ccs external interrupt

Hi Impakt,

OK, I'll try and answer everything:
This function void Scheduler_Interrupt(void) will be executed everytime timer 0 overflows?
Yes, that is correct.

Can I change the time timer 0 reaches it's maximum value?
Yes, you can use the prescaler and or an initial value in timer0. Be careful, though, as you cannot write directly to the high byte.

To interrupt on a change on pin I must use external interrupts (port B on PIC16F877)?
That is correct.

After this function is executed form where does my program starts executing again? Or it executes the code following the interrupt function?
Yes, you are correct, the code starts executing where it left off. The way an interrupt works is that the Program Counter is pushed onto the stack when your interrupt executes, and then popped off the stack when the service routine exits. So the counter points to the last instruction before it entered the service routine.

I'm not sure about your sensors, though. Could you explain them a bit more? If I understand, you are using an IR sensor to first measure distance, and then using the same sensor to measure the amount of ambient light? Perhaps a short snippet of the code you are using to measure would help.

For Dika:
I haven't used the MSP, but can answer some of your questions. If you need more detailed answers, I suggest starting a new thread, rather than hijacking this one.
does that code means the routine should be coded in there?
Yes, you put your service routine there:
void PORT1_ISR (void) {
your actions go here;
}
you put your statements where it is bolded.

about interrupt edge select, does the interrupt instantly triggered when an edge is detected?
Yes, but you most likely have control over which edge is used. The data sheet for your micro will tell you how to do this.

or does it need to be polled?
No, the whole idea of using an interrupt is that you don't have to poll. Polling is a telephone which doesn't have a ringer. You pick up the reciever every few seconds to see if there is someone on the other end. A phone with a ringer has an interrupt. It uses a ring to interrupt you from what you are doing when someone calls you, so you don't have to keep checking. Hope this makes sense for you.

Best wishes,
Robert
 

    impakt

    Points: 2
    Helpful Answer Positive Rating
read_adc ccs interrupt

As I said before, the robot has 8 infrared sensors: 6 for obstacle avoidance and 2 for line following. You can see the robot at **broken link removed**.
I don't understand the algorithm. Here's the code form one zone:
Code:
case FrontZone :
			set_adc_channel( FrontLeft );
			delay_us( 12 );
			__IR_Light[ FrontLeft ] = read_adc();
			set_adc_channel( FrontRight );
			delay_us( 12 );
			__IR_Light[ FrontRight ] = read_adc();
			set_adc_channel( Front );
			delay_us( 12 );
			__IR_Light[ Front ] = read_adc();
			output_high( PIN_B2 );
			delay_us( 300 );
			__IR_Proximity[ Front ] = __IR_Light[ Front ] - read_adc();
			set_adc_channel( FrontLeft );
			delay_us( 12 );
			__IR_Proximity[ FrontLeft ] = __IR_Light[ FrontLeft ] - read_adc();
			set_adc_channel( FrontRight );
			delay_us( 12 );
			__IR_Proximity[ FrontRight ] = __IR_Light[ FrontRight ] - read_adc();
			output_low( PIN_B2 );
			break;
 

interrupt programming for infrared sensor

Hi,
Well looks like this is out of a switch statement, something like switch on sensor readings, and in this case, the FrontZone, it looks like it starts an AD conversion by calling the function set_adc_channel( whichSensor )
which selects the proper sensor to read.
It then stores the reading in the array __IR_Light[n] delays for a spell,
then reads the next sensor.
It does three sensors in the front, delays for a while (300 uS,) then sets pin B2 high. What's on this pin? I'm guessing it is an IR emitter? It then compares the previous reading stored in __IR_Light[n] with a new measurement, and stores the resulting difference in the array __IR_Proximity[n]
Then it moves to the next sensor to make another comparison.

I hope this is making sense, it is so late, and I really have to shut it down. I'll come back in the morning with more.

Oh, I took a look at the page you pointed to but I'm not sure which product/source code you're working with. I'm thinking you got your source code here? If it is, I'll take a look at it. If I knew which BOT, could probably explain it much better.

Regards,
Robert
 

ccs interrupt at specific time

hai

a vector is nothing but a pre defined program memory location (normally the starting location)which is specified by the manufacturer of the chip. which cannnot be changed by the programmer
first and formost is the reset vector where the system will read first at the time of switching on or reset.we cannot keep this location blank.next are the interruprvector.the interrupt is nothing but something to inform the system of purticular situation.when there's no interrupt.the system will perform the normal operations and when an interrupt occurs the systems controllwill jump to the currusponding reset vector where we must program the solution for that purticular interrupt.this program is called interrupt service routine(isr).after complition of the isr,the system will go back to the previous place and continue what it was doing

hope this will clear ur doubts.if not pls feelfree to mail again,we r here to help u


thanking you


sunish
 

    impakt

    Points: 2
    Helpful Answer Positive Rating
ccs interrupt timer

I don't understand this line:
Code:
__IR_Proximity[ Front ] = __IR_Light[ Front ] - read_adc();
If __IR_Light[ Front ] is the value red from ADC channel, read_adc() that is, won't the result be 0 (zero)? Then won't the the value printed on the hyperterminal be 0???
Thanks for answers.
 

example interrupt port b with ccs

Hi,
Code:
__IR_Proximity[ Front ] = __IR_Light[ Front ] - read_adc();

If __IR_Light[ Front ] is the value red from ADC channel, read_adc() that is, won't the result be 0 (zero)? Then won't the the value printed on the hyperterminal be 0???

No, the call read_adc(); is taking a new reading. That new reading is subtracted from the reading stored in the array variable __IR_Light[ Front ]

It then stores the difference computed on the right side:
(__IR_Light[ Front ] - read_adc())
in the array variable __IR_Proximity[ Front ]

The reading will be different IF your robot is moving.

Remember __IR_Light[n] is an array, and the index [n] is a numerical value indicating the possition within the array. The value for Front, for example, is equated with a number, somewhere, like this #define Front 1

read_adc() is a function call, which returns a value. That value, in effect, will replace the call to the function, with its result. The first time it is called, it stores the reading in the array variable __IR_Light[ Front ]

The second time it is called, it doesn't store the value, but subtracts it from the first reading, then stores the result of that subtraction in the array variable __IR_Proximity[ Front ]

I see they give you a library for CCS, and they probably haven't released the source of the library, eh?

Nice looking robot, looks like it is well made.

Best wishes,
Robert
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top