I am building an “external DDS oscillator “ for older amateur radio.
I want to control
an interrupt driven “tune” AD9850 DDS module – SPI ,
parallel LCD ( 4 bits BCD – just because I already have one),
an interrupt driven “band switch” 5 position
So the Uno coming from China will not do straight from the box.
I was thinking adding a momentary switch to switch the interrupts from “tune” to “band switch” - they do not have to run same time. But I am still missing one “band switch” setting.
I may add another “controls” in the future also.
I am not looking for “cool / clean” solution, I am open to anything using external circuits.
But - KISS - is there Arduino X with more interrupt pins?
If the switches are input to the Arduino then you can just poll then no need for interrupts at all. If where outputs then there not interrupts (as far as the Arduino is concerned any way).
Mark,
as far as I am concerned a real time system / controller should always use interrupt. Arduino is not Windoze and polling is not what I wanted to do anyway.
Now I am wondering if the "serial" ports can also be used as generic I/O , included interrupt.
But I don't need it, I think 13 pins will work just fine for this FIRST project.
Thanks guys.
Vaclav
The atmegaxx8 family (arduino diecimila, uno, others) has 2 external interrupts and 3 pin change interrupts, for a total of 5 interrupt vectors triggered by changes on the pins. The pin change interrupts can by connected to different pins. A change on any pin selected by the Pin Change Enable Mask will trigger the interrupt vector. So the same interrupt vector can be triggered by zero to eight different pins. Maybe it's easier if you just read the External Interrupts section in the datasheet yourself.
I definitely need to read more about Arduino interrupts.
So far I am sure that there is two "external" interrupts which I see as real hardware interrupts, fine..
Than there are three additional interrupt INPUTS - and they can be assigned to ANY I/O digital pins, right?
And these three can be tied to up to eight "vectors", so they actually simulate the old fashion IC "3 out of 8 decoder"?
I assume that this software "3 out of 8 decoder" , which is what I was thinking about to use externally, code is in some library.Google here I come.
Vaclav
Hi Vaclav
Take a look at this page http://arduino.cc/en/Hacking/PinMapping168
It shows the atmega168/328 chip and the pins. The black text is the datasheet naming and functions of the pin. The red text is the arduino naming / use of the pin.
Interrupt vectors are pointers located in the beginning of flash memory on the chip. When something happens that triggers an interrupt, the microcontroller will start executing the code that the relevant interrupt vetor points to. You define that code like this:
ISR(PCINT0_vect) {
// code to handle interrupt
}
ISR is short for interrupt service routine. Setting up the vector and entering / exiting the interrupt properly is handled by avr-libc. If you want to become ninja read this page avr-libc: <avr/interrupt.h>: Interrupts
Back to the atmega pinout diagram. The pins labelled with INT0 and INT1 can trigger INT0_vect and the INT1_vect respectively. Just one pin each. These interrupts can be configured for rising edge, falling edge, logic zero or finally any logic change. You choose which condition should trigger the interrupt. Example: enable INT0 for any logic change:
void setup() {
noInterrupts();
// External Interrupt Control Register A
EICRA |= B00000100; // Set INT1 to trigger on any logic change
// External Interrupt Mask Register
EIMSK |= B00000010; // enable INT1
// Enable interrupts globally
interrupts()
}
ISR(INT1_vect) {
// do stuff
}
Now look at the diagram for the PCINTxx pins::
PCINT0 - PCINT7 pins can be set to trigger PCINT0_vect
PCINT8 - PCINT14 pins can be set to trigger PCINT1_vect
PCINT16 - PCINT23 pins can be set to trigger PCINT2_vect
Example: turn on PCINT1_vect for arduino pins A4 and A5
Vaclav:
as far as I am concerned a real time system / controller should always use interrupt.
As far as I'm concerned, regardless of the environment you're working in, interrupts should only be used where they are the most appropriate solution. In the context of an Arduino, using interrupts introduces considerable complexity and should be avoided as far as possible. The only sensible reason I can think of for using interrupts in this context is when there are latency requirements which can't be met any other way. Using interrupts to detect or generate a high frequency or short duration signal may be appropriate. Using interrupts to detect slow and non-time-critical inputs such as the position of manually operated switches is silly.
Very interesting,
I get an absolutely fantastic reply from a “newbie” - BIG THANKS - and lectures why not to use interrupts “from Tesla” – whatever that means. After I provided a clear , at least to my be best knowledge and ability, description what I am trying to accomplish. Real time tuning.
As a reaction to my first post I hope this is not an indication about how diversified this group is.
But I did I received what I asked for - “an opinion”. Thank you for that.
I shall be more specific in the future provided the person who answers my inquiry actually reads the OP.
PS I am still waiting for shipment of hardware , but I am busy coding.
Vaclav
Vaclav:
lectures why not to use interrupts “from Tesla” – whatever that means. After I provided a clear , at least to my be best knowledge and ability, description what I am trying to accomplish. Real time tuning.
Yes, the real time tuning part of your problem is why I wrote this:
Using interrupts to detect or generate a high frequency or short duration signal may be appropriate.
But you very clearly wrote this, and also implied that the number of interrupt-capable pins was an issue:
an interrupt driven “band switch” 5 position
Hence my response:
Using interrupts to detect slow and non-time-critical inputs such as the position of manually operated switches is silly.
Vaclav:
as far as I am concerned a real time system / controller should always use interrupt.
As far as I'm concerned, regardless of the environment you're working in, interrupts should only be used where they are the most appropriate solution. In the context of an Arduino, using interrupts introduces considerable complexity and should be avoided as far as possible.
Agreed.
Polling in Windows is antisocial because that is a multitasking OS with better things to do than waste several amps of power burning in a tight loop. So, don't poll in Windows.
But a microcontroller doesn't have anything better to do. It will sip a couple milliamps regardless of whether it's sitting around bored or running flat out. Polling is my preferred method of getting human input -- and most other types of input requiring millisecond response times as well. Only when things get in the microsecond ("real-time") range, or when you're on battery and want the microcontroller to go to sleep most of the time, is it appropriate to look to interrupts. IMHO.
I thought I was done with this discussion.
Apparently not .
So if you still come late , after the cartoons, one more time - I have an optical encoder setting DDS frequency in real time.
I have done this project using Basic Stamp using polling - boring.
I am going to run interrupts on ALL inputs - especially analog!
And I will probably ignore any more posts in this thread.
Whoa there. You said a "5-position switch" in your first post, which is quite the different animal than an optical encoder!
A human spinning an optical encoder could indeed generate pulses in the microsecond range, so interrupts actually are appropriate for that particular type of input.
I have done this project using Basic Stamp using polling - boring.
So what!
Just because its boring, simple, easy does not make it wrong, if fact it makes it right!. But your claim was that "interrupts are the ONLY right way to do input", which is plainly stupid.
Please don't ignore the rest of our responses on this thread - please do ignore all the Arduino forums!. No one need an "eletrionics(sic) expert" whose main claim to fame is wring up a bulb in fifth grade (by the way what's fifth grade most of the world don't come from that tiny little place called the USA.).
We spend a lot of time here trying to teach and help people at no charge. Your not helping so but out!