Show Posts
Pages: [1]
1  Products / Arduino Due / Re: I2C not working on: December 07, 2012, 01:24:11 pm
http://www.arduino.cc/en/Reference/Wire

You're using the right pins?
2  Products / Arduino Due / Re: Due External Interrupts on: December 06, 2012, 07:56:32 pm
You're totally correct. The prints inside the interrupt functions are purely for demonstrative purposes for this post to show when the interrupt happens in order of events. My actual code only has the boolean value changes. Regardless, if you take the prints out you can still see that 'b==true' is set by an unexpected interrupt from the 'b true' prints.
3  Products / Arduino Due / Re: Due External Interrupts on: December 05, 2012, 02:32:57 am
I have no datasheets to link, but the board's maximum input voltage is 3.3V, so 2.5V should sensibly be enough for HIGH. But more than that, I can say with certainty from other projects I have done that 2.5V is enough to trigger HIGH.

The other pins are not connected nor initialized in the setup() function.

I have no other board to try this with.

The output corresponds to the button never being pushed.

4  Products / Arduino Due / Due External Interrupts on: December 04, 2012, 03:16:42 pm
I have isolated a problem I am having with interrupts on the Due board to the below code:


Code:
volatile boolean a = false;
volatile boolean b = false;

void setup() {
    int a_pin = 51;
    int b_pin = 49;
    Serial.begin(9600);
    Serial.println("0");    
    attachInterrupt(a_pin, a_func, RISING);
    Serial.println("1");    
    attachInterrupt(b_pin, b_func, FALLING);
    Serial.println("2");
}
void loop(){
    Serial.println("3");
    if(b==true){
        Serial.println("b true");
        delay(750);
    }
    Serial.println("4");
    if(a==true){
        Serial.println("a true");
        delay(750);
    }
    Serial.println("5");
}

void a_func(){
    Serial.println("a interrupt");
    a = true;
}

void b_func(){
    Serial.println("b interrupt");
    b = true;
}


The above code is supposed to work in conjunction with the simple circuit here. :
http://i.imgur.com/O6clD.jpg
I am confident the button is properly debounced, verified through the oscilloscope.

From the circuit, the normally high output of the voltage divider goes to pin 49 (associated with 'b' boolean and function) on the Due which is set to receive interrupts from FALLING signals (i.e. HIGH to LOW). The capacitor is to filter out any noise. The interrupt prints 'b interrupt' and sets 'b' = true, which causes the print statement 'b true' to print repeatedly in the loop().

The problem is that the interrupt is happening before the button is pushed, i.e. pin 49 must see a FALLING signal before I actually do anything. To determine the order of events I added a number of print statements and the output is as seen here:


Code:
0
1
b interrupt
2
3
b true
4
5
3
b true
4
5


As you can see, the 'b interrupt' happens between the prints of '1' and '2', setting 'b'=true, causing the 'b true' statement to print. Pushing the button associated with 'b' causes the 'b interrupt' print statement as expected, but I do not understand why the interrupt initially occurs before I physically do anything. I have watched the voltages on pin 49 with an oscilloscope to check if the pin defaults to HIGH and then goes low on program execution (thus triggering the interrupt), but as far as I can see, the pin always reports ~2.5V, unless I push the button, which causes it go to 0V as expected.

I added the interrupts associated with 'a' and simply grounded pin 51. I have no problems with the interrupt happening unexpectedly, as seen in the Serial output by lack of statements related to 'a'.

Is this some kind of weird system thing where the interrupt is called when I attach a function with a FALLING mode or am I getting a falling signal I can't see?

Update: I connected pin 51 to a normally closed debounced button in a similar circuit to the one in the original post. This means the output of the voltage divider is normally LOW and goes to HIGH on button push. Attaching an interrupt on such a RISING logic change does not produce the problems seen in the original post and the interrupt never occurs unless the button is actually pushed. While I realize I could just always use a normally closed button and use RISING interrupt triggers, it would still be nice to know what is causing my original problem.
5  Development / Other Software Development / Re: PWM frequency library on: November 26, 2012, 06:08:05 pm
For those that get here looking for how to change PWM frequency for the Due, you should look here for a solution: http://arduino.cc/forum/index.php/topic,131323.msg989728.html#msg989728

Basically, only pins 6-9 on the Due board are actual HWPWM and the other pins labeled as PWM are timer pins.

You can change the frequency of the PWM pins 6-9 with the following (changes the frequency for all the pins):
Code:
PWMC_ConfigureClocks(whatever_freq_you_want * 255 , 0, VARIANT_MCK)

I'm not sure how/if individual pin frequencies can be changed.

The same can be accomplished by changing
Code:
#define PWM_FREQUENCY 1000
for the pins 6-9 and
Code:
#define TC_FREQUENCY        1000
for the other PWM timer pins. These constants are defined in 'variant.h'.

Hope this helps someone along the road.
6  Products / Arduino Due / Re: Serial Communication over Programming USB Port on: November 21, 2012, 10:52:16 pm
I figured it out. It was reading the new line character in as Serial input and that was activating the default case. This can be fixed in the Serial Monitor by selecting "No line ending" in the drop down box on the bottom. See here: http://i.imgur.com/IM2vo.png
7  Products / Arduino Due / [solved] Serial Communication over Programming USB Port on: November 21, 2012, 10:39:07 pm
Hello, I am trying to figure out serial communication on the Due programming port with the below test code:

Code:
void setup() {
  // initialize serial communication:
  Serial.begin(9600);
   // initialize the LED pins:
  for (int thisPin = 22; thisPin <= 28; thisPin++) {
    pinMode(thisPin, OUTPUT);
  }
}

void loop() {
  // read the sensor:
  if (Serial.available() > 0) {
    int inByte = Serial.read();
    switch (inByte) {
    case 'a':    
      digitalWrite(22, HIGH);
      break;
    case 'b':    
      digitalWrite(23, HIGH);
      break;
    case 'c':    
      digitalWrite(24, HIGH);
      break;
    case 'd':    
      digitalWrite(25, HIGH);
      break;
    case 'e':    
      digitalWrite(26, HIGH);
      break;
    case 'f':    
      digitalWrite(27, HIGH);
      break;
    case 'g':    
      digitalWrite(28, HIGH);
      break;      
    default:
      // turn all the LEDs off:
      delay(1000);
      Serial.println("Turning all pins off");
      for (int thisPin = 22; thisPin <= 28; thisPin++) {
        digitalWrite(thisPin, LOW);
      }
    }
  }
}

I've got the digital output pins 22-28 hooked up to LEDs on my breadboard and sending the characters 'a'-'f' through the Serial Monitor should activate one of the LEDs and any other character should turn them all off. My LEDs light up as expected for each character, but only stay lit for 1 second (due to the delay(1000) in the default: of the switch()) and the print statement in the default case is always printed. It's as if my switch statement is going to the correct case in addition to the default case.

Anyone have some input on this problem? The only thing I can think of is that Serial.available() is returning '1' more than expected.
Pages: [1]