###Background
Background
###Background
Background
I used Serial.print() to see if my volatile channel variable was updating (that is, change its value to the channel 1 flag value). It was not updating, so my ISR must be wrong. I based my code (pretty much copied) off of a blog post where the code is said to have worked for the people who used it. You can find the original code in the blog post.
I used Serial.print() to see if my volatile channel variable was updating (that is, change its value to the channel 1 flag value). It was not updating, so my ISR must be wrong. I based my code (pretty much copied) off of a blog post where the code is said to have worked for the people who used it. You can find the original code in the blog post.
I used Serial.print() to see if my volatile channel variable was updating (that is, change its value to the channel 1 flag value). It was not updating, so my ISR must be wrong. You can find the original code in the blog post.
Background###Background
I'm trying to write a code to read signals from a 6 channelsix-channel RC receiver on an arduino mega 2560Arduino Mega 2560. Currently I am keeping the code to just read 1one channel to make things easy to troubleshoot. The problem is my shared variable is not updating, leading me to believe that my interrupt service routine is not detecting any rising edges.
I thought my receiver was broken, so I tested it using the standard arduino attach interrupt functionthe standard Arduino attach interrupt function. It worked perfectly, so my receiver is fine.
I used serial.printSerial.print() to see if my volatile channel variable was updating (iethat is, change its value to the channel 1 flag value). It was not updating, so my ISRISR must be wrong. The thing is I based my code(pretty much copied) off of a bloga blog post where the code is said to have worked for the people who used it. You can find the original code here
http://rcarduino.blogspot.co.uk/2012/04/how-to-read-multiple-rc-channels-draft.html in the blog post.
Can anyone take a look at my code and see whatsWhat's wrong? I'm out of ideas at the moment
btw I tried using attach code tool to put my code up but its not working.
#include <PinChangeInt.h>
//Pin assinmentassignment
#define chanel1PINchannel1PIN 10
//Bit flags
#define Chanel1FLAGChannel1FLAG 1
//Flag Holderholder
volatile uint8_t bFLAGUPDATESHARED;
//Shared Variablesvariables:Accessed by the interrupt service routine and read in Void'void Looploop'.
volatile uint16_t unCHANNEL1SHARED;
//Start Timetime Variablesvariables:These are used to set the start time of the rising edge of
//a pulse. They are only accessed by the ISR, and thus they are unsigned integers and
//not volatiles.
uint32_t ulCHANNEL1START;
void setup()
{
Serial.begin(9600);
Serial.print("RC Channel PWM Read Interrupt Test");
//PinChangInt library function. Used to set attach interrupts.
PCintPort::attachInterrupt(chanel1PINchannel1PIN, calcCHANNEL1, CHANGE);
}
void loop()
{
//In-loop variables to hold local copies of channel inputs.
//This is static so itretainsit retains values between call loops.
static uint16_t unCHANNEL1IN;
//The in-loop copy of the bSHAREDFLAGUPDATE volatile flag holder
static uint8_t bFLAGUPDATELOCAL;
//checkCheck to see if any chanelschannels have received signals. ifIf so, copy
//shared variables to local in loop variables.
if(bFLAGUPDATESHARED)
{
//switchSwitch ofoff interrupsinterrupts when I copy shared variables to local variables
noInterrupts();
bFLAGUPDATELOCAL=bFLAGUPDATESHARED;bFLAGUPDATELOCAL = bFLAGUPDATESHARED;
if(bFLAGUPDATELOCAL & Chanel1FLAGChannel1FLAG)
{
unCHANNEL1IN=unCHANNEL1SHARED;unCHANNEL1IN = unCHANNEL1SHARED;
}
bFLAGUPDATESHARED = 0;
interrupts();
}
Serial.println(unCHANNEL1IN);
//clearClear local update flags copy as all values have been copied to local variables
bFLAGUPDATELOCAL = 0;
}
void calcCHANNEL1()
{
if(digitalRead(chanel1PINchannel1PIN) == HIGH)
{
//If pin goes Highhigh, start timer and set ulCHANNEL1START to timer start
ulCHANNEL1START = micros();
}
else
{
//If it is not rising, it must be falling so set shared //variable to current time-start time
unCHANNEL1SHARED = (uint16_t)(micros()-ulCHANNEL1START);
//Tell that channel1channel 1 has received a signal
bFLAGUPDATESHARED |= Chanel1FLAG;Channel1FLAG;
}
}
Background
I'm trying to write a code to read signals from a 6 channel RC receiver on an arduino mega 2560. Currently I am keeping the code to just read 1 channel to make things easy to troubleshoot. The problem is my shared variable is not updating leading me to believe that my interrupt service routine is not detecting any rising edges.
I thought my receiver was broken so I tested it using the standard arduino attach interrupt function. It worked perfectly so my receiver is fine.
I used serial.print to see if my volatile channel variable was updating (ie change its value to the channel 1 flag value). It was not updating so my ISR must be wrong. The thing is I based my code(pretty much copied) off of a blog where the code is said to have worked for the people who used it. You can find the original code here
http://rcarduino.blogspot.co.uk/2012/04/how-to-read-multiple-rc-channels-draft.html
Can anyone take a look at my code and see whats wrong? I'm out of ideas at the moment
btw I tried using attach code tool to put my code up but its not working
#include <PinChangeInt.h>
//Pin assinment
#define chanel1PIN 10
//Bit flags
#define Chanel1FLAG 1
//Flag Holder
volatile uint8_t bFLAGUPDATESHARED;
//Shared Variables:Accessed by the interrupt service routine and read in Void Loop
volatile uint16_t unCHANNEL1SHARED;
//Start Time Variables:These are used to set the start time of the rising edge of
//a pulse. They are only accessed by the ISR thus they are unsigned integers and
//not volatiles
uint32_t ulCHANNEL1START;
void setup()
{
Serial.begin(9600);
Serial.print("RC Channel PWM Read Interrupt Test");
//PinChangInt library function. Used to set attach interrupts
PCintPort::attachInterrupt(chanel1PIN, calcCHANNEL1, CHANGE);
}
void loop()
{
//In-loop variables to hold local copies of channel inputs
//This is static so itretains values between call loops
static uint16_t unCHANNEL1IN;
//The in-loop copy of the bSHAREDFLAGUPDATE volatile flag holder
static uint8_t bFLAGUPDATELOCAL;
//check to see if any chanels have received signals if so copy
//shared variables to local in loop variables
if(bFLAGUPDATESHARED)
{
//switch of interrups when I copy shared variables to local variables
noInterrupts();
bFLAGUPDATELOCAL=bFLAGUPDATESHARED;
if(bFLAGUPDATELOCAL & Chanel1FLAG)
{
unCHANNEL1IN=unCHANNEL1SHARED;
}
bFLAGUPDATESHARED = 0;
interrupts();
}
Serial.println(unCHANNEL1IN);
//clear local update flags copy as all values have been copied to local variables
bFLAGUPDATELOCAL = 0;
}
void calcCHANNEL1()
{
if(digitalRead(chanel1PIN) == HIGH)
{
//If pin goes High start timer and set ulCHANNEL1START to timer start
ulCHANNEL1START = micros();
}
else
{
//If not rising, must be falling so set shared variable to current time-start time
unCHANNEL1SHARED = (uint16_t)(micros()-ulCHANNEL1START);
//Tell that channel1 has received a signal
bFLAGUPDATESHARED |= Chanel1FLAG;
}
}
###Background
I'm trying to write code to read signals from a six-channel RC receiver on an Arduino Mega 2560. Currently I am keeping the code to just read one channel to make things easy to troubleshoot. The problem is my shared variable is not updating, leading me to believe that my interrupt service routine is not detecting any rising edges.
I thought my receiver was broken, so I tested it using the standard Arduino attach interrupt function. It worked perfectly, so my receiver is fine.
I used Serial.print() to see if my volatile channel variable was updating (that is, change its value to the channel 1 flag value). It was not updating, so my ISR must be wrong. I based my code(pretty much copied) off of a blog post where the code is said to have worked for the people who used it. You can find the original code in the blog post.
What's wrong? I'm out of ideas.
#include <PinChangeInt.h>
//Pin assignment
#define channel1PIN 10
//Bit flags
#define Channel1FLAG 1
//Flag holder
volatile uint8_t bFLAGUPDATESHARED;
//Shared variables:Accessed by the interrupt service routine and read in 'void loop'.
volatile uint16_t unCHANNEL1SHARED;
//Start time variables:These are used to set the start time of the rising edge of
//a pulse. They are only accessed by the ISR, and thus they are unsigned integers and
//not volatiles.
uint32_t ulCHANNEL1START;
void setup()
{
Serial.begin(9600);
Serial.print("RC Channel PWM Read Interrupt Test");
//PinChangInt library function. Used to set attach interrupts.
PCintPort::attachInterrupt(channel1PIN, calcCHANNEL1, CHANGE);
}
void loop()
{
//In-loop variables to hold local copies of channel inputs.
//This is static so it retains values between call loops.
static uint16_t unCHANNEL1IN;
//The in-loop copy of the bSHAREDFLAGUPDATE volatile flag holder
static uint8_t bFLAGUPDATELOCAL;
//Check to see if any channels have received signals. If so, copy
//shared variables to local in loop variables.
if(bFLAGUPDATESHARED)
{
//Switch off interrupts when I copy shared variables to local variables
noInterrupts();
bFLAGUPDATELOCAL = bFLAGUPDATESHARED;
if(bFLAGUPDATELOCAL & Channel1FLAG)
{
unCHANNEL1IN = unCHANNEL1SHARED;
}
bFLAGUPDATESHARED = 0;
interrupts();
}
Serial.println(unCHANNEL1IN);
//Clear local update flags copy as all values have been copied to local variables
bFLAGUPDATELOCAL = 0;
}
void calcCHANNEL1()
{
if(digitalRead(channel1PIN) == HIGH)
{
//If pin goes high, start timer and set ulCHANNEL1START to timer start
ulCHANNEL1START = micros();
}
else
{
//If it is not rising, it must be falling so set shared //variable to current time-start time
unCHANNEL1SHARED = (uint16_t)(micros()-ulCHANNEL1START);
//Tell that channel 1 has received a signal
bFLAGUPDATESHARED |= Channel1FLAG;
}
}