Show Posts
Pages: 1 [2] 3
16  Forum 2005-2010 (read only) / Syntax & Programs / Re: Debouncing on: August 27, 2010, 04:54:53 am
Thanks all for these very helpfull answers.
What I learned from them is that my first intuition which consisted in staying away from interrupts for debouncing was funded.

Just for your records, ALPS data sheets for rotary encoders series EC12 says <= 3 ms. But yes, some switches may bounnnnnnnnnnnnnnnnnnce for a longer time.
17  Forum 2005-2010 (read only) / Syntax & Programs / Re: Debouncing on: August 26, 2010, 05:39:09 am
Oooops about
"When you read a port "PORTC", you should instead read "PINC" (see section 13.2.4 of the datasheet)"

Your are 100% right, I simplified my code for the post, please read PINC instead. In my application PORTs are passed as arguments and the pin reading is slightly less self explicit.

Code:
uint8_t startState = ((((PIN(*_encPort) >> _swA) & 0x01) << 2) | (((PIN(*_encPort) >> _swB) & 0x01) << 1) | ((PIN(*_encPort) >> _swPb) & 0x01));
18  Forum 2005-2010 (read only) / Syntax & Programs / Debouncing on: August 26, 2010, 03:22:55 am
I want to use a debouncer within an ISR, and this is the code I wrote:

Code:

ISR(PCINT0_vect) {
// Interrupt service request for external interrupt
// Interpret switches position
      static uint8_t prevState = 0x03;
      // Get current state
      uint8_t startState = ((((PINC >> _swA) & 0x01) << 2) | (((PINC >> _swB) & 0x01) << 1) | ((PINC >> _swPb) & 0x01));
      // Simple debouncing. 1 nop = 62.5 ns, 1600 nops approx 100 us
      for (int i=0; i < 1600; i++)
            asm volatile ("NOP");
      // Get current state
      uint8_t stopState = ((((PINC >> _swA) & 0x01) << 2) | (((PINC >> _swB) & 0x01) << 1) | ((PINC >> _swPb) & 0x01));
      // Check if the previous state was stable and different from the previous one
      if ((startState == stopState) && (stopState != prevState)) {
            _buttonDown = (~startState & 0x01); // Update button state
            if ((startState >> 1) == 0x03) { // If in idle state
              // Decode steps pattern
                  if (patternBuffer == patternCW)
                        _counts++;             
              if (patternBuffer == patternCCW)
                        _counts--;             
                  patternBuffer = 0x00; // reset buffer
            }
            else {
                  // Append state to the buffer
                  patternBuffer <<= 2;
                  patternBuffer |= (startState >> 1) ;
            }
            prevState = stopState; // Record state for next change
      }
}

It sounds like there are much better solutions. Does one of you has contructive comments and suggestions?
19  Forum 2005-2010 (read only) / Syntax & Programs / Re: Calling a routine/function from an ISR on: August 28, 2010, 02:38:34 am
End of game. The problem is under investigation in some other places where it has been reproduced aknowledged and ranked as strange.
So far the answer is:

Yes it is possible to call a sub function from an ISR. Bit it has restrictions (We will cover that in some other place). And it is not recommended to do so because it lengthens the execution of the ISR.
20  Forum 2005-2010 (read only) / Syntax & Programs / Re: Calling a routine/function from an ISR on: August 26, 2010, 04:06:49 am
Thanks drhex. I moved this specification question to a new topic http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1282810975/0#0 Would you contribute to it.
21  Forum 2005-2010 (read only) / Syntax & Programs / Re: Calling a routine/function from an ISR on: August 26, 2010, 03:16:33 am
We are getting far from my original question which is:

Is it possible to call a sub routine from an ISR? I am just asking.

On the other hand, I understand that the good forum pratices recommand to avoid multiple threads from the same topic. So that I will create new topics for the new questions from some of you. I will try to solve the misunderstandings by MP. Link here http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1282810975/0#0
22  Forum 2005-2010 (read only) / Syntax & Programs / Re: Calling a routine/function from an ISR on: August 25, 2010, 02:29:17 pm
Did I assmume anything related to the compiler? I am just asking... Sorry if my prose was not clear enough, english is not my mother langage.

I did not post the real code which is huge. As an exemple, I wished to use a command readState() function within the next ISR instead of startState  and stopState .

Code:
ISR(PCINT0_vect) {
// Interrupt service request for external interrupt
// Interpret switches position
      static uint8_t prevState = 0x03;
      // Get current state
      uint8_t startState = ((((PIN(*_encPort) >> _swA) & 0x01) << 2) | (((PIN(*_encPort) >> _swB) & 0x01) << 1) | ((PIN(*_encPort) >> _swPb) & 0x01));
      // Simple debouncing. 1 nop = 62.5 ns, 1600 nops approx 100 us
      for (int i=0; i < 1600; i++)
            asm volatile ("NOP");
      // Get current state
      uint8_t stopState = ((((PIN(*_encPort) >> _swA) & 0x01) << 2) | (((PIN(*_encPort) >> _swB) & 0x01) << 1) | ((PIN(*_encPort) >> _swPb) & 0x01));
      // Check if the previous state was stable and different from the previous one
      if ((startState == stopState) && (stopState != prevState)) {
            _buttonDown = (~startState & 0x01); // Update button state
            if ((startState >> 1) == 0x03) { // If in idle state
              // Decode steps pattern
                  if (patternBuffer == patternCW)
                        _counts++;             
              if (patternBuffer == patternCCW)
                        _counts--;             
                  patternBuffer = 0x00; // reset buffer
            }
            else {
                  // Append state to the buffer
                  patternBuffer <<= 2;
                  patternBuffer |= (startState >> 1) ;
            }
            prevState = stopState; // Record state for next change
      }
}


Anyway, my major concern was for the whole content of the ISR, and yes, the ISR_ALIASOF flag solves the problem at the price of two lines of code !

Code:
// Use PCINT0_vect for PCINT1_vect and PCINT2_vect
ISR(PCINT1_vect, ISR_ALIASOF(PCINT0_vect));
ISR(PCINT2_vect, ISR_ALIASOF(PCINT0_vect));

23  Forum 2005-2010 (read only) / Syntax & Programs / Re: Calling a routine/function from an ISR on: August 25, 2010, 12:50:28 pm
I tried  :-X and missed  :'( thus my question  :-/

I should have added that the code belongs to a library. The compiler says unrecognized function talking about the called routine/function, while everything looks ok (99.99% sure)

On the other hand: after (spending an hour) searching, I found an alternative to my question: the ISR_ALIASOF flag!

Anyway, I am interested in the answer to the original question... Thanks for helping  smiley-wink
24  Forum 2005-2010 (read only) / Syntax & Programs / Calling a routine/function from an ISR on: August 25, 2010, 12:07:36 pm
The title speaks for itself !
Is it possible to call a routine/function from an ISR?

Note: I understand that the code should stay minimal, but in my case, I want a couple of ISR's to run the same code.
25  Forum 2005-2010 (read only) / Interfacing / Re: filtering accelerometer data on: January 05, 2011, 06:12:52 am
You may want to read this http://didier.longueville.free.fr/arduinoos/?p=1389  smiley-wink
26  Forum 2005-2010 (read only) / Interfacing / Re: DS1306 on: August 17, 2010, 04:49:06 am
There are few tricky pits, which are (as very often) due to fancy features that are suppose to save your (precious) time and your (badly hurt) nerves. You may want to visit my blog here http://didier.longueville.free.fr/arduinoos/wp-admin/post.php?action=edit&post=715 (check updates)  smiley-wink
27  Forum 2005-2010 (read only) / Development / Re: FFT library on: October 12, 2010, 09:31:40 am
You are kindly invited to visit my blog and read the FFT related pages (they will endup with a library).  smiley-wink
http://didier.longueville.free.fr/arduinoos/
28  Forum 2005-2010 (read only) / Development / Re: My new Arduinoos blog on: August 27, 2010, 12:37:02 pm
This place is for: open source software, open source hardware and open ... minds. With no restrictions.  smiley
29  Forum 2005-2010 (read only) / Development / My new Arduinoos blog on: August 23, 2010, 02:11:21 am
You are kindly invited to visit my new blog which contains information that was usefull to the developmentof my own projects. http://didier.longueville.free.fr/arduinoos/
HTH
30  Forum 2005-2010 (read only) / Français / Re: numéro de serie atmega328 on: March 24, 2010, 03:52:35 am
Churchill: +1  smiley-wink
C'est ce que j'ai fait pour une application où l'Arduino est contrôlé par une application externe. Dans l'EEPROM j'ai enregistré un n° de série, le code de l'application et son code de version.
En fonction du niveau de protection souhaité, tu peux éparpiller ces codes dans les 512 bytes de mémoire EEPROM, utiliser un encodage pour éviter une lecture directe trop intuitive.
Sinon, la soluce Maxim/Dallas semble (je ne l'ai pas testée mais je l'ai étudiée un moment donné) assez simple et robuste.
HTH
Pages: 1 [2] 3