Cleanup of aux PR and add init routing for these channels

This commit is contained in:
Josh Stewart 2018-07-26 17:07:31 +10:00
parent 57a5791a05
commit 0bbed9f316
3 changed files with 70 additions and 68 deletions

View File

@ -3,7 +3,6 @@
#include "Arduino.h" #include "Arduino.h"
// The following are alpha values for the ADC filters. // The following are alpha values for the ADC filters.
// Their values are from 0 to 255 with 0 being no filtering and 255 being maximum // Their values are from 0 to 255 with 0 being no filtering and 255 being maximum
#define ADCFILTER_TPS 128 #define ADCFILTER_TPS 128
@ -30,6 +29,7 @@ unsigned long MAPrunningValue; //Used for tracking either the total of all MAP r
unsigned long EMAPrunningValue; //As above but for EMAP unsigned long EMAPrunningValue; //As above but for EMAP
unsigned int MAPcount; //Number of samples taken in the current MAP cycle unsigned int MAPcount; //Number of samples taken in the current MAP cycle
uint32_t MAPcurRev; //Tracks which revolution we're sampling on uint32_t MAPcurRev; //Tracks which revolution we're sampling on
bool auxIsEnabled;
//These variables are used for tracking the number of running sensors values that appear to be errors. Once a threshold is reached, the sensor reading will go to default value and assume the sensor is faulty //These variables are used for tracking the number of running sensors values that appear to be errors. Once a threshold is reached, the sensor reading will go to default value and assume the sensor is faulty
byte mapErrorCount = 0; byte mapErrorCount = 0;

View File

@ -50,6 +50,31 @@ void initialiseADC()
MAPcurRev = 0; MAPcurRev = 0;
MAPcount = 0; MAPcount = 0;
MAPrunningValue = 0; MAPrunningValue = 0;
//The following checks the aux inputs and initialises pins if required
auxIsEnabled = false;
for (byte AuxinChan = 0; AuxinChan <16 ; AuxinChan++)
{
currentStatus.current_caninchannel = AuxinChan;
//currentStatus.canin[14] = ((configPage9.Auxinpinb[currentStatus.current_caninchannel]&127)+1);
//currentStatus.canin[13] = (configPage9.caninput_sel[currentStatus.current_caninchannel]&3);
if ( (configPage9.caninput_sel[currentStatus.current_caninchannel] == 1) && (configPage9.enable_candata_in > 0) && (configPage9.enable_canbus == 1)) //if current input channel is enabled as canbus
{
auxIsEnabled = true;
}
else if ((configPage9.caninput_sel[currentStatus.current_caninchannel]&3) == 2) //if current input channel is enabled as analog local pin
{
//Channel is active and analog
pinMode( (configPage9.Auxinpina[currentStatus.current_caninchannel]&127), INPUT);
auxIsEnabled = true;
}
else if ((configPage9.caninput_sel[currentStatus.current_caninchannel]&3) == 3) //if current input channel is enabled as digital local pin
{
//Channel is active and digital
pinMode( (configPage9.Auxinpinb[currentStatus.current_caninchannel]&127), INPUT);
auxIsEnabled = true;
}
}
} }
static inline void instanteneousMAPReading() static inline void instanteneousMAPReading()
@ -317,12 +342,12 @@ void readBat()
* This value is incremented with every pulse and reset back to 0 once per second * This value is incremented with every pulse and reset back to 0 once per second
*/ */
void flexPulse() void flexPulse()
{ {
++flexCounter; ++flexCounter;
} }
uint16_t readAuxanalog(uint8_t analogPin) uint16_t readAuxanalog(uint8_t analogPin)
{ {
//read the Aux analog value for pin set by analogPin //read the Aux analog value for pin set by analogPin
unsigned int tempReading; unsigned int tempReading;
#if defined(ANALOG_ISR) #if defined(ANALOG_ISR)
@ -332,12 +357,12 @@ uint16_t readAuxanalog(uint8_t analogPin)
tempReading = fastMap1023toX(analogRead(analogPin), 511); //Get the current raw Auxanalog value tempReading = fastMap1023toX(analogRead(analogPin), 511); //Get the current raw Auxanalog value
#endif #endif
return tempReading; return tempReading;
} }
uint16_t readAuxdigital(uint8_t digitalPin) uint16_t readAuxdigital(uint8_t digitalPin)
{ {
//read the Aux digital value for pin set by digitalPin //read the Aux digital value for pin set by digitalPin
unsigned int tempReading; unsigned int tempReading;
tempReading = digitalRead(digitalPin); tempReading = digitalRead(digitalPin);
return tempReading; return tempReading;
} }

View File

@ -987,77 +987,54 @@ void loop()
//The IAT and CLT readings can be done less frequently (4 times per second) //The IAT and CLT readings can be done less frequently (4 times per second)
if (BIT_CHECK(LOOP_TIMER, BIT_TIMER_4HZ)) if (BIT_CHECK(LOOP_TIMER, BIT_TIMER_4HZ))
{ {
BIT_CLEAR(TIMER_mask, BIT_TIMER_4HZ); BIT_CLEAR(TIMER_mask, BIT_TIMER_4HZ);
readCLT(); readCLT();
readIAT(); readIAT();
readO2(); readO2();
readO2_2(); readO2_2();
readBat(); readBat();
nitrousControl(); nitrousControl();
if(eepromWritesPending == true) { writeAllConfig(); } //Check for any outstanding EEPROM writes. if(eepromWritesPending == true) { writeAllConfig(); } //Check for any outstanding EEPROM writes.
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) //ATmega2561 does not have Serial3 if(auxIsEnabled == true)
//check through the Aux input channels if enabed for Can or local use {
for (byte AuxinChan = 0; AuxinChan <16 ; AuxinChan++) //check through the Aux input channels if enabed for Can or local use
{ for (byte AuxinChan = 0; AuxinChan <16 ; AuxinChan++)
{
currentStatus.current_caninchannel = AuxinChan; currentStatus.current_caninchannel = AuxinChan;
//currentStatus.canin[14] = ((configPage9.Auxinpinb[currentStatus.current_caninchannel]&127)+1); //currentStatus.canin[14] = ((configPage9.Auxinpinb[currentStatus.current_caninchannel]&127)+1);
//currentStatus.canin[13] = (configPage9.caninput_sel[currentStatus.current_caninchannel]&3); //currentStatus.canin[13] = (configPage9.caninput_sel[currentStatus.current_caninchannel]&3);
if (configPage9.caninput_sel[currentStatus.current_caninchannel] == 1) //if current input channel is enabled as canbus if (configPage9.caninput_sel[currentStatus.current_caninchannel] == 1) //if current input channel is enabled as canbus
{
if (configPage9.enable_candata_in) //if external data input is enabled
{ {
if (configPage9.enable_candata_in) //if external data input is enabled if (configPage9.enable_canbus == 1) // megas only support can via secondary serial
{ {
if (configPage9.enable_canbus == 1) // megas only support can via secondary serial sendCancommand(2,0,currentStatus.current_caninchannel,0,((configPage9.caninput_source_can_address[currentStatus.current_caninchannel]&2047)+0x100));
{ //send an R command for data from caninput_source_address[currentStatus.current_caninchannel]
sendCancommand(2,0,currentStatus.current_caninchannel,0,((configPage9.caninput_source_can_address[currentStatus.current_caninchannel]&2047)+0x100)); }
//send an R command for data from caninput_source_address[currentStatus.current_caninchannel] #if defined(CORE_STM32) || defined(CORE_TEENSY)
} else if (configPage9.enable_canbus == 2) // can via internal can module
} {
sendCancommand(3,configPage9.speeduino_tsCanId,currentStatus.current_caninchannel,0,configPage9.caninput_source_can_address[currentStatus.current_caninchannel]); //send via localcanbus the command for data from paramgroup[currentStatus.current_caninchannel]
}
#endif
} }
}
else if ((configPage9.caninput_sel[currentStatus.current_caninchannel]&3) == 2) //if current input channel is enabled as analog local pin else if ((configPage9.caninput_sel[currentStatus.current_caninchannel]&3) == 2) //if current input channel is enabled as analog local pin
{ {
//read analog channel specified //read analog channel specified
currentStatus.canin[currentStatus.current_caninchannel] = readAuxanalog(configPage9.Auxinpina[currentStatus.current_caninchannel]&127); currentStatus.canin[currentStatus.current_caninchannel] = readAuxanalog(configPage9.Auxinpina[currentStatus.current_caninchannel]&127);
} }
else if ((configPage9.caninput_sel[currentStatus.current_caninchannel]&3) == 3) //if current input channel is enabled as digital local pin else if ((configPage9.caninput_sel[currentStatus.current_caninchannel]&3) == 3) //if current input channel is enabled as digital local pin
{ {
//read digital channel specified //read digital channel specified
currentStatus.canin[currentStatus.current_caninchannel] = readAuxdigital((configPage9.Auxinpinb[currentStatus.current_caninchannel]&127)+1); currentStatus.canin[currentStatus.current_caninchannel] = readAuxdigital((configPage9.Auxinpinb[currentStatus.current_caninchannel]&127)+1);
} } //Channel type
} } //For loop going through each channel
} //aux channels are enabled
#elif defined(CORE_STM32) || defined(CORE_TEENSY)
//check through the Aux input channels if enabed for Can or local use
for (byte AuxinChan = 0; AuxinChan <16 ; AuxinChan++)
{
currentStatus.current_caninchannel = AuxinChan;
if ((configPage9.caninput_sel[currentStatus.current_caninchannel]&3) == 1) //if current input channel is enabled as canbus
{
if (configPage9.enable_candata_in)
{
if (configPage9.enable_canbus == 1) //can via secondary serial
{
sendCancommand(2,0,currentStatus.current_caninchannel,0,((configPage9.caninput_source_can_address[currentStatus.current_caninchannel]&2047)+0x100)); //send an R command for data from paramgroup[currentStatus.current_caninchannel]
}
else if (configPage9.enable_canbus == 2) // can via internal can module
{
sendCancommand(3,configPage9.speeduino_tsCanId,currentStatus.current_caninchannel,0,configPage9.caninput_source_can_address[currentStatus.current_caninchannel]); //send via localcanbus the command for data from paramgroup[currentStatus.current_caninchannel]
}
}
}
else if ((configPage9.caninput_sel[currentStatus.current_caninchannel]&3) == 2) //if current input channel is enabled as analog local pin
{
//read analog channel specified
currentStatus.canin[currentStatus.current_caninchannel] = readAuxanalog(configPage9.Auxinpina[currentStatus.current_caninchannel]&127);
}
else if ((configPage9.caninput_sel[currentStatus.current_caninchannel]&3) == 3) //if current input channel is enabled as digital local pin
{
//read digital channel specified
currentStatus.canin[currentStatus.current_caninchannel] = readAuxdigital((configPage9.Auxinpinb[currentStatus.current_caninchannel]&127)+1);
}
}
#endif
vvtControl(); vvtControl();
idleControl(); //Perform any idle related actions. Even at higher frequencies, running 4x per second is sufficient. idleControl(); //Perform any idle related actions. Even at higher frequencies, running 4x per second is sufficient.
} //4Hz timer } //4Hz timer