hi dears
i have a small project that use atmega32 (MICROC FOR AVR)
i need to use 3 interrupts INT0, INT1, INT2 withTIMER1
1. INT0 to detect ZERO CROSSING
2. INT1 to detect MOTOR SPEED
3. INT2 to detect some EXTERNAL FEEDBACK
note that I have no any library or headers for INTERRUPTS MY CODE:
Code:
void Timer1Overflow_ISR() org IVT_ADDR_TIMER1_COMPA
{
MS++;
}
ISR (INT0_VECT)
{
return ZC_FLAG = 1;
/// have i reset INT0 flag here? ///
}
ISR (INT1_VECT)
{
return TCHO_FLAG = 1;
/// have i reset INT1 flag here? ///
}
ISR (INT2_VECT)
{
return FEEDBACK_FLAG = 1;
/// have i reset INT2 flag here? ///
}
void main (void)
{
/// TIMER1 ///
SREG.B7 = 1; // ENABLE GLOBAL INTERRUPT BIT
TCCR1A = 0x80;
TCCR1B = 0x0B;
OCR1AH = 0x30;
OCR1AL = 0xD3;
OCIE1A_bit = 1;
/// EXT_INTS ///
SREG.B7 = 0;
GICR.B6 = 1; // INT0 ENABLE
GICR.B7 = 1; // INT1 ENABLE
GICR.B5 = 1; // INT2 ENABLE
MCUCR.B0 = 0; MCUCR.B1 = 1; // INT0 FALLING EDGE
MCUCR.B2 = 0; MCUCR.B3 = 1; // INT1 FALLING EDGE
MCUCSR.B6 = 0; // INT2 FALLING EDGE
SREG.B7 = 1; // ENABLE GLOBAL INTERRUPTS
while (1)
{
if (ZC_FLAG) {
// do somethings //
ZC_FLAG = 0;
}
if (TACHO_FLAG) {
// do somethings //
TACHO_FLAG = 0;
}
if (FEEDBACK_FLAG) {
// do somethings //
FEEDBACK_FLAG = 0;
}
}
}
/// END CODE //
Performance Software offers tips to avoid mistakes made by embedded software engineers in avionics that are prevalent in the DO-178B/C industry.
www.psware.com
Instead, minimize the use of interrupts when possible. For example, program interrupts so their only function is to signal an aperiodic process or server. Or convert handlers from periodically interrupting devices to periodic processes. If you must use interrupts, use only real-time analysis methods that account for the interrupt handling overhead. Never assume that overhead from interrupts and their handlers is negligible. Ensure mutually exclusive access to data buffers and registers in the interrupts. Do the absolute minimum amount of work possible in the handlers and exit.
* I expect it to get compiled, but I expect it not to work.
* don´t do the triac timing in main(), do it in the ISR. But don´t use busy wait like delay_us().
The general rule "don´t use delay in an ISR" or "keep the ISR as short as possible" does not mean it just should set a flag. Otherwise you´ve nothing won.
How I´d do it:
* in the ISR: CLEAR the output (for triac gate trigger)
* use the PWM hardware to automatically SET the gate trigger output.
(this just needs a couple of microseconds in the ISR)
This is the most precise solution. It just uses the ZeroCrossISR.
Another way is to use the ZeroCrossISR and a timerISR:
* in the ZeroCrossISR: CLEAR the output (for triac gate trigger)
* set the timer timeout, then leave this ISR
* in the timerISR just SET the gate trigger output. and leave.
*****
Avoid doing precise timing in main(). Do it in the ISR. This is how it´s meant to work.
*****
I know it´s hard time to go through this the first time. We all have this behind us. (not only behind)
I know it´s a lot to read ... and it needs time to understand.
But you should know: This will go on as long as you are doing electronics/software design.
All professionals read more papers every day than you may expect. It´s unavoidable in my eys, but one get´s used to it. It´s our daily job.
Unfortunately, I do not understand the sequence you mentioned
So please write me an example
As for the external interrupt, it must be tried
Anyway, I am waiting for the controllers, and when they arrive, I will test them and let you know the result
But I think it will work in principle because it's just like a timer1 interrupt
it doesn´t work this way.
You don´t do what I recommend.
You don´t answer questions or give detailed informations.
You don´t show your own effort.
I try to explain, but no feedback.
I will help you to rectify mistakes, but I won´t do your job.
This is not how a forum is meant to work.
Again: I will support you as long as you do your job and take your part in the conversation.
I understand very well what you are saying and thank you very much for that
Of course, I don't want anyone to do my work, or I won't learn anything
The problem is that I'm trying to deal with the code at the registrar level
I've been busy reading the datasheet very carefully
Now notice in the following picture, this is timer1 interrupt in the timer calculator
The definition of the ISR. This is nothing new. It´s already in your code since post#1.
And the same style you need to define all your other ISRs.. as already written.
The MikroE documentation as well as my example can be copy and pasted.
Feel free to tell us what you understand so far and where you need assistance.
The definition of the ISR. This is nothing new. It´s already in your code since post#1.
And the same style you need to define all your other ISRs.. as already written.
The MikroE documentation as well as my example can be copy and pasted.
Feel free to tell us what you understand so far and where you need assistance.
I wonder why you insist on doing the wrong things ... and avoid doing it correct.
****
In your post#27 neither the red nor the green are showing ISR definitions. Both are wrong.
While the green ones try to define three times a function with the same name "ISR" but with different prameters.
But still just naming a function "ISR" does not mean it is an ISR.
The error message says that you must not have three function with the same name. The error message is not related to a true ISR at all.
The red one define three different functions. Thus there is no compiler error. But neither one is defined as an ISR.
Still it´s not correct definition of an ISR.
****
We have given now a lot of informations, examples how to do it right. If you can´t or don´t want to "copy and past" our effort is useless.
You clearly didn't get the point, either in understanding the numerous technical tips provided over and over again, or in understanding that some conclusions/experiments must be inferred by yourself, as long as being trivial. Since you don't seem to be interacting in a clear way, this thread will be closed for now, in the hope that you will follow the recommendations of get introduced with the fundamentals at tutorials and examples starting from the basic, found here and elsewhere; BTW, it is not the function of the forum to teach you what can be found on compiler's documentation, here you get help about specific questions, one per thread.