Part Number: LP-MSPM0L1306
Other Parts Discussed in Thread: MSPM0L1306
Are there other things that need to be changed other than "main.c" to main.cpp such as any other ".c-files"? This has been asked in one way or another before, but there does not seem to be a way that works. I can get that vector and string used in a class sparingly(less than 100 small 2-5 letter strings) could need more stack space, but a short temp_sense_thermistor_LP_MSPM0L1306_nortos_ticlang does not seem to a bad actor. If not possible, that would be nice to know too. It compiles but debug goes who knows where. c-code works with no ppin class use.
include "ti_msp_dl_config.h"
#include <stdio.h>
#include <math.h>
#define CHANGEFACTOR 10
volatile uint16_t gThermistorADCResult = 0;
volatile bool gCheckThermistor = false;
volatile uint32_t gCelcius_reading = 0;
volatile uint32_t gInitial_reading = 0;
volatile uint16_t gAlivecheck =0;
float VBias = 3.30; // set the VBIAS voltage
unsigned int ADC_BITS =
4096; // set the number of bits based on you ADC (2^# of ADC Bit Value)
float VTEMP = 0; // set up the variable for the measured voltage
float THRM_TEMP = 0; // setup the variable for the calculated temperature
float thermistor_calc_temperature(int raw_ADC)
{
// THRM calculations via regression
// Copied from TI Thermistor Design Tool Excel Doc
VTEMP = 0.0;
float THRM_ADC = raw_ADC;
float THRM_A0 = -4.232811E+02;
float THRM_A1 = 4.728797E+02;
float THRM_A2 = -1.988841E+02;
float THRM_A3 = 4.869521E+01;
float THRM_A4 = -1.158754E+00;
VTEMP =
(VBias / ADC_BITS) *
THRM_ADC; // calculate volts per bit then multiply that times the ADV value
THRM_TEMP = (THRM_A4 * powf(VTEMP, 4)) + (THRM_A3 * powf(VTEMP, 3)) +
(THRM_A2 * powf(VTEMP, 2)) + (THRM_A1 * VTEMP) +
THRM_A0; // 4th order regression to get temperature
return THRM_TEMP;//* 32; // multiply by 32 for GC to divide later
}
float gfC=0.0;float gfF=0.0;int giprnCF=0; const int gimodFC=0x10000;int giwhile=0;const int gimodw=0x20000;
void prnc_CF(void){
if(giprnCF%gimodFC==0){
gfC=thermistor_calc_temperature(gThermistorADCResult);
gfF=gfC*9/5 +32;
printf("Temperature = %2.1fC,%3.1fF\n",gfC,gfF);
}
giprnCF++;
}
int main(void)
{
SYSCFG_DL_init();
DL_GPIO_clearPins(RGB_PORT,
(RGB_RED_PIN | RGB_GREEN_PIN | RGB_BLUE_PIN));
NVIC_EnableIRQ(ADC_INST_INT_IRQN);
gCheckThermistor = false;
/* Start timer that triggers ADC sampling */
DL_TimerG_startCounter(THERMISTOR_TIMER_ADC_INST);
bool first_reading = true;
while (1) {
while (gCheckThermistor == false) {
__WFE();
}
//Insert Thermistor Algorithm
prnc_CF();
//fC=thermistor_calc_temperature(gThermistorADCResult);
//fF=fC*9/5 +32;
//
gCelcius_reading = gThermistorADCResult;
if (first_reading) {
gInitial_reading = gCelcius_reading;
first_reading = false;
}
else {
if(giwhile%gimodw==0){
prnc_CF();
giwhile++;
}
}
/*
* Change in LEDs is based on current sample compared to previous sample
*
* If the new sample is warmer than CHANGEFACTOR from initial temp, turn LED red
* If the new sample is colder than CHANGEFACTOR from initial temp, turn LED blue
* Else, keep LED green
* Variable gAlivecheck is utilized for debug window to confirm code is executing.
* It is not needed in final applications.
*
*/
gAlivecheck++;
if(gAlivecheck >= 0xFFF0){gAlivecheck =0;}
if (gCelcius_reading - CHANGEFACTOR > gInitial_reading) {
DL_GPIO_clearPins(
RGB_PORT, (RGB_GREEN_PIN | RGB_BLUE_PIN));
DL_GPIO_setPins(RGB_PORT, RGB_RED_PIN);
} else if (gCelcius_reading < gInitial_reading - CHANGEFACTOR) {
DL_GPIO_clearPins(
RGB_PORT, (RGB_RED_PIN | RGB_BLUE_PIN));
DL_GPIO_setPins(RGB_PORT, RGB_BLUE_PIN);
} else {
DL_GPIO_clearPins(
RGB_PORT, (RGB_RED_PIN | RGB_BLUE_PIN));
DL_GPIO_setPins(RGB_PORT, RGB_GREEN_PIN);
}
gCheckThermistor = false;
__WFI();
}
}
/*
* This IRQ is triggered whenever a new ADC conversion result is ready,
* and the conversion result is stored in gThermistorADCResult.
*/
void ADC_INST_IRQHandler(void)
{
switch (DL_ADC12_getPendingInterrupt(ADC_INST)) {
case DL_ADC12_IIDX_MEM0_RESULT_LOADED:
gThermistorADCResult =
DL_ADC12_getMemResult(ADC_INST, DL_ADC12_MEM_IDX_0);
gCheckThermistor = true;
break;
default:
break;
}
}
include <cstring>
#include <string>
#include <vector>
using namespace std;
class ppin {
private://static const std::vector<std::vector<const std::string>> vsuse;
static vector<vector<string>> vsuse;
public:ppin(int iN){
ipin = iN;
vsuses= vsuse[ipin - 1];
iuses = (int)vsuses.size();
iuse = 0;
suse = vsuses[0];
}
string p_use(int i2use) {
iuse = i2use % iuses;
suse = vsuses[iuse];
string sret = suse;
return sret;
}
private:
int ipin;
int iuses;
int iuse;
string suse;
vector<string> vsuses;
};
vector<vector<string>> ppin::vsuse = { // change multple use pins orders to first(0)=default
{"PA0"}, { "PA1" }, { "NRST" }, { "VDD" }, { "VSS" }, { "PA2","ROSC" }, { "PA3" }, { "PA4" },
{ "PA5" }, { "PA6" }, { "PA7" }, { "PA8" }, { "PA9" }, { "PA10" }, { "PA11" }, { "PA12" },
{ "PA13" }, { "PA14" }, { "PA15","A9" }, { "PA16","A8" }, { "PA17" }, { "PA18","A7" }, { "PA19","SWDIO" }, { "PA20","SWCLK","A6" },
{ "PA21","A5","VREF-" }, { "PA22","A4" }, { "PA23","VREF+" }, { "PA24","A3" }, { "PA25","A2" }, { "PA26","A1" }, { "PA27", "A0" }, { "VCORE" }
};
