handling interrupts

how exactly are the interrupts get served in the real time embedded products like a washing machine,refrigirator?

is it like, we will write a program where we continuously check a particular status bit of the device has been set or not...or those interrupts will be hard wired to a interrupt pin (INT pin kind of)??

if it is hard wired how a variety of divices are connected to that particular pin and how exactly the interrupt by a particular device get serviced??

Reply to
Radha_Purnima
Loading thread data ...

Different developers will use different strategies.

Modern microcontrollers have a very rich set of peripherals built in, and the trend is toward each peripheral having its own vectored interrupt, often with more than one general purpose IO pin sourcing unique interrupts also.

In operation, each one of these interrupt sources is serviced by its own interrupt service routine.

--

Tim Wescott
Wescott Design Services
http://www.wescottdesign.com

Do you need to implement control loops in software?
"Applied Control Theory for Embedded Systems" gives you just what it says.
See details at http://www.wescottdesign.com/actfes/actfes.html
Reply to
Tim Wescott

What interrupts? Appliances like washing machines use mechanical timer with camshaft and set of switches.

Vladimir Vassilevsky DSP and Mixed Signal Design Consultant

formatting link

Reply to
Vladimir Vassilevsky

Some do. Some use microcontrollers.

--
Grant Edwards                   grante             Yow! This MUST be a good
                                  at               party -- My RIB CAGE is
                               visi.com            being painfully pressed up
                                                   against someone's MARTINI!!
Reply to
Grant Edwards

What makes you think a refrigerator or washing machine even uses any type of interrupt at all? What devices would NEED to be interrupt driven in such a usage? What do you think is happening in your fridge that is so transient/fast that a simple polling loop wouldn't suffice? What is going on in your fridge that would even require an MCU? Mine gets along just fine with a simple mechanical thermostat and a switch that (I think, I'm not really sure, it might stay on all the time.....) turns off the light when the door is closed. Same questions about your washer. These are things that need to be answered before I would go about asking particulars about hardware implementation. Running late on your homework? You must define the domain of the problem BEFORE you ask for an answer.

Reply to
James Beck

When the micro code has finished executing the previous instruction, the microcode checks if any interrupt requests are active.

If not, the operation code pointed by the program counter is fetched, decoded and executed.

However, if some interrupt is set, the micro code will save the context (typically the program counter and some registers) on the stack and then fetch an address from a known address (in the interrupt vector) and load it into the program counter. After that, the micro code will proceed normally.

Paul

Reply to
Paul Keinanen

It's been a while since you took one apart, eh?

Microprocessors are insinuating themselves even into wash machines and dishwashers. Soon all the old farts in the world will have to live in special homes with resident 13-year olds to program all their appliances, not just their VCRs.

It's a plot.

--

Tim Wescott
Wescott Design Services
http://www.wescottdesign.com

Do you need to implement control loops in software?
"Applied Control Theory for Embedded Systems" gives you just what it says.
See details at http://www.wescottdesign.com/actfes/actfes.html
Reply to
Tim Wescott

Oh dear. Poor users. Does it have the operating system, too?

It loos more that the things are going into the opposite direction: only the old farts can fix gadgets and vigets of young suckers who haven't got a slightest clue.

Vladimir Vassilevsky DSP and Mixed Signal Design Consultant

formatting link

Reply to
Vladimir Vassilevsky

Hey, do you want to share that beer:)

martin

Reply to
Martin Griffith

A simple state machine, run some moderate number of times per second, can check all input and output levels and decide what to do. It may be run by a periodic interrupt, or it may just pace itself with a wait loop. Interrupts from hardware inputs, like pushbuttons maybe, are often more trouble than simple polling from within a state machine.

And proper periodic polling can give you debouncing for free.

John

Reply to
John Larkin

Op Tue, 02 Sep 2008 17:53:04 +0200 schreef Paul Keinanen :

On some cores, some multi-cycle instructions can be cancelled and later restarted.

Or it will switch register banks, leaving the decision to perform stack operations to the specific interrupt handler.

But usually in a mode called 'priviledged' or 'supervisor'.

--
Gemaakt met Opera's revolutionaire e-mailprogramma:  
http://www.opera.com/mail/
Reply to
Boudewijn Dijkstra

I think the beer's gone...

--
Grant Edwards                   grante             Yow!
                                  at              
BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-
                               visi.com
Reply to
Grant Edwards

That is for big appliance micro processors like 2K. Seriously the code I see is in two categories 1970's spaghetti and some very clever well though out tightly implemented application code.

Both are what ever ROM size the appliance has the latter very functional fault tolerant and reliable.

w..

Reply to
Walter Banks

We are seeing increasing amounts of event driven code. Similar in design to state machines but very small event initiated execution fragments that always run to completion. These are a compromise in timing. The code can be shorter and require less RAM but the response time will be longer. As long as the response time meets the system requirements it is a big win.

Regards

-- Walter Banks Byte Craft Limited Tel. (519) 888-6911

formatting link

Reply to
Walter Banks

John:

For getting something done right away, I agree that polling is simpler to write, debug and assure it works. But I'm still old enough to remember when CPU cycles were "precious" and not to be wasted polling for things that mostly don't occur.

Deep down I prefer interrupts but they're trickier to handle properly due to possible concurrency among data structures. And interrupts allow for power saving techniques such as using slower clock rates, sleep or suspend modes.

Reply to
Jeff Jonas

Reply to
tripura

stopping until there is required switch input.The microcontroller i am using is Atmega2560.

I did this using 2 timer/counter interrupts TIMER/COUNTER1 AND TIMER/COUNTER3.The LED is blinking continuously and the timer 3 interrupt is not getting called.

Here is my program...

//ICC-AVR application builder : 3/19/2009 4:15:37 PM // Target : M2560 // Crystal: 16.000Mhz

#include #include #include /* This putchar works with the M2560 UART0. It will work with other devices

  • if their UART registers use the same names. If the UART IO locations * are different from the M2560, then you will also have to change the * #include header file statement. * * For device with multiple UARTs and if you want to use a different UART,
  • change the IO register names as appropriate. */ extern int _textmode; int putchar(char c) { if (_textmode && c == '\n') putchar('\r'); /* Wait for empty transmit buffer */ while ( !(UCSR0A & (1 1) & 1) #define SW2() ((PIND >> 2) & 1) #define SW3() ((PIND >> 3) & 1) #define SW4() ((PIND >> 4) & 1) #define SW5() ((PIND >> 5) & 1) #define SW6() ((PIND >> 6) & 1) #define SW7() ((PIND >> 7) & 1)

#define SET_LED0() cbi(PORTB,0) #define SET_LED1() cbi(PORTB,1) #define SET_LED2() cbi(PORTB,2) #define SET_LED3() cbi(PORTB,3) #define SET_LED4() cbi(PORTB,4) #define SET_LED5() cbi(PORTB,5) #define SET_LED6() cbi(PORTB,6) #define SET_LED7() cbi(PORTB,7)

#define CLR_LED0() sbi(PORTB,0) #define CLR_LED1() sbi(PORTB,1) #define CLR_LED2() sbi(PORTB,2) #define CLR_LED3() sbi(PORTB,3) #define CLR_LED4() sbi(PORTB,4) #define CLR_LED5() sbi(PORTB,5) #define CLR_LED6() sbi(PORTB,6) #define CLR_LED7() sbi(PORTB,7)

#define SWITCH_ON 0 #define SWITCH_OFF 1

#define TIMER_INTERVAL 500 #define PRESCALER 1024 #define PRESCALER10sec 8 #define PROCESSOR_CLOCK 1600000 #define TIMER_COMPARE_VALUE (((PROCESSOR_CLOCK / PRESCALER) * TIMER_INTERVAL) / 10000)

#define TIMER_COMPARE_VALUE10sec (((PROCESSOR_CLOCK / PRESCALER10sec) * TIMER_INTERVAL) / 10000)

#define TCCR1B_VALUE BIT(WGM12)|BIT(CS12)|BIT(CS10) #define TCCR3B_VALUE10s BIT(WGM32)|BIT(CS31)

#pragma interrupt_handler Timer1OutputCompareA:iv_TIMER1_COMPA

#pragma interrupt_handler handler_Timer10sec:iv_TIMER3_COMPA

#define TABLE_ENTRIES 3 #define PASSWORD_ENTRIES 4 #define SWITCH_ENTRIES 8

unsigned char gucPointer = 0;

unsigned char SW[SWITCH_ENTRIES] = {

0,1,2,3,4,5,6,7 } ;

const unsigned char LedPattern[TABLE_ENTRIES] = {

254, 255, 254 } ; void port_init(void) { PORTA = 0x00; DDRA = 0x00; PORTB = 0x00; DDRB = 0x00; PORTC = 0x00; //m103 output only DDRC = 0x00; PORTD = 0x00; DDRD = 0x00; PORTE = 0x00; DDRE = 0x00; PORTF = 0x00; DDRF = 0x00; PORTG = 0x00; DDRG = 0x00; PORTH = 0x00; DDRH = 0x00; PORTJ = 0x00; DDRJ = 0x00; PORTK = 0x00; DDRK = 0x00; PORTL = 0x00; DDRL = 0x00; }

//UART0 initialize // desired baud rate: 9600 // actual: baud rate:9615 (0.2%) // char size: 8 bit // parity: Disabled void uart0_init(void) { UCSR0B = 0x00; //disable while setting baud rate UCSR0A = 0x00; UCSR0C = 0x06; UBRR0L = 0x67; //set baud rate lo UBRR0H = 0x00; //set baud rate hi UCSR0B = 0x08; }

//call this routine to initialize all peripherals void init_devices(void) { //stop errant interrupts until set up CLI(); //disable all interrupts XMCRA = 0x00; //external memory XMCRB = 0x00; //external memory port_init(); uart0_init();

MCUCR = 0x00; EICRA = 0x00; //pin change int edge 0:3 EICRB = 0x00; //pin change int edge 4:7 PCICR = 0x00; //pin change int enable PCMSK0 = 0x00; //pin change mask PCMSK1 = 0x00; //pin change mask PCMSK2 = 0x00; //pin change mask EIMSK = 0x00; TIMSK0 = 0x00; //timer0 interrupt sources TIMSK1 = 0x00; //timer1 interrupt sources TIMSK2 = 0x00; //timer2 interrupt sources TIMSK3 = 0x00; //timer3 interrupt sources TIMSK4 = 0x00; //timer4 interrupt sources TIMSK5 = 0x00; //timer5 interrupt sources PRR0 = 0x00; PRR1 = 0x00; SEI(); //re-enable interrupts //all peripherals are now initialized }

// void main(void) { int i; int Keys_Pressed_Still=0; init_devices();

printf("Main Start\n\r"); DDRD = 0x00; DDRB = 0xFF; PORTB = 0xFF; TCCR1B = 0x00; // Stop Timer1 TCNT1H = 0x00; // Clear Timer1 TCNT1L = 0x00; while(1) { //alsoif((SW0()==SWITCH_ON)&(SW1()==SWITCH_ON)&(SW2()==SWITCH_ON)&(SW3()==SWITCH_ON))

if(SW0()==SWITCH_ON) { if(SW1()==SWITCH_ON) { if(SW2()==SWITCH_ON) { if(SW3()==SWITCH_ON) { if(Keys_Pressed_Still==0) { Keys_Pressed_Still=1; Timer1OutputCompareA(); OCR1A = TIMER_COMPARE_VALUE; // 100ms timer TIMSK1 |= BIT(OCIE1A); // Compare A Interrupt enable

TCCR1B = TCCR1B_VALUE; // Start Timer1 with clk/1024 & CTC mode

_SEI(); // Set the I flag in SREG

Timer10secStart(); } } else { Keys_Pressed_Still=0; NOP(); } } else NOP(); } else NOP(); } else NOP(); } // CLI(); //printf("Sleeping\n\r"); }

void Timer1OutputCompareA(void) { int Timer3control; long int timer3countH; long int timer3countL;

PORTB = LedPattern[gucPointer++]; if(gucPointer == TABLE_ENTRIES) { gucPointer = 0; } /* timer3countH=TCNT3H; timer3countL=TCNT3L; printf("Timer3: %d %d %d \n\r", timer3countH,timer3countL,TCCR3B);*/ }

void Timer10secStart(void) { long int timer3countH; long int timer3countL; printf("Start Timer 10sec \n\r"); OCR3A = TIMER_COMPARE_VALUE10sec; TIMSK3 |= BIT(OCIE3A); // Compare A Interrupt enable TCCR3B = TCCR3B_VALUE10s; // Start Timer3 with clk/8 & CTC mode

_SEI();

timer3countH=TCNT3H; timer3countL=TCNT3L; printf("TIMSK3: %d \n\r", TIMSK3); printf("TCCR3B: %d \n\r", TCCR3B); printf("OCIE3A: %d \n\r", OCIE3A); printf("TCCR3B_VALUE10s: %d \n\r", TCCR3B_VALUE10s); printf("Timer3: %d %d \n\r", timer3countH,timer3countL); }

int handler_Timer10sec(void) { TCCR1B = 0x00; // Stop Timer1 TCNT1H = 0x00; // Clear Timer1 TCNT1L = 0x00; printf("Stop Timer 1\n\r"); printf("Sleeping\n\r"); }

Kindly look at it and please let me know of my mistake in programming...

Thank you Tripura Sundari

Reply to
tripura

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.