Multiple PWM Signal Reading On Arduino Mega 2560
Maybe your like
Dear Sirs,
I’m new in the Arduino world, and I would need, for data acquisition, to read PWM data coming from a R/C receiver (very classical problem) on my Arduino MEGA 2560.
After few hours on Google, the best code I found to do it is:
Welcome cheapscience.com - BlueHost.com
Bluehost - Top rated web hosting provider - Free 1 click installs For blogs, shopping carts, and more. Get a free domain name, real NON-outsourced 24/7 support, and superior speed. web hosting provider php hosting cheap web hosting, Web hosting,...
I tried it, and it run perfectly…!!
However, I would need to read 4 different channels, so I tried to modify the code (see just bellow) to be able to read another channel in the same time. The code read PIN2 at its origin, and I tried to read PIN3 in the same time.
But this code is still able to read PWM signals on PIN2, but not in PIN3.
Would someone have any idea of the problem??
Thanks in advance for your help,
Best Regards,
Stéphane
// Reading servos with interrupts // For an Arduino Mega // Scott Harris January 2010 // // This work is licensed under the Creative Commons Attribution-Share Alike 3.0 United States License. // To view a copy of this license, visit Creative Commons — Attribution-ShareAlike 3.0 United States — CC BY-SA 3.0 US
volatile long servo0; // servo value volatile long count0; // temporary variable for servo1
volatile long servo1; // servo value volatile long count1; // temporary variable for servo1
// PIN 2 // #define int0 (PINE & 0b00010000) // Faster than digitalRead #define int0 (PINE & 0x10)
// PIN 3 // #define int0 (PINE & 0b00100000) #define int1 (PINE & 0x20)
void handleInterrupt() { if(int0) count0=micros(); // we got a positive edge else servo0=micros()-count0; // Negative edge: get pulsewidth
if(int1) count1=micros(); // we got a positive edge else servo1=micros()-count1; // Negative edge: get pulsewidth }
void setup() { Serial.begin(9600);
pinMode(2,INPUT); pinMode(3,INPUT);
attachInterrupt(0,handleInterrupt,CHANGE); // Catch up and down }
void loop() { delay(10); Serial.println(servo0,DEC); // Pulsewidth in microseconds Serial.println(servo1,DEC); // Pulsewidth in microseconds }
Tag » Arduino Mega 2560 Pwm Input
-
PWM Frequency And Duty Cycle Using Input Capture On ATmega2560
-
PWM & TX/RX Pins As Inputs On MEGA 2560 R3 - Arduino Forum
-
Trouble Setting Up 16 Bit PWM On Mega2560 - Arduino Forum
-
Arduino Mega 2560 PWM Pins - Programming Questions
-
Arduino Mega 2560 - Inverting PWM - Programming Questions
-
Arduino Mega 2560 PWM Output - Programming Questions
-
Arduino Mega - PWM 2KHz - Project Guidance
-
Increasing The PWM Frequency On A MEGA 2560 - Arduino Forum
-
Simulink Arduino Mega 2560 Digital Input - PWM Signal Uncorrect ...
-
Digital PWM Or PPM Signal Read For Arduino Mega2560 - - MathWorks
-
[PDF] Arduino Mega 2560
-
Giới Thiệu Arduino Mega 2560 - ĐIỆN TỬ TƯƠNG LAI
-
Arduino Mega2560 Rev3 - ATmega2560 - Kiwi Electronics