TucsonDon
Member
C:
typedef enum
{
Array = 0x0,
Water = 0x1,
Pool = 0xC,
channel_CTMU = 0x1D,
channel_DAC = 0x1E,
channel_FVRBuf2 = 0x1F
} adc_channel_t;
adc_channel_t channel;
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
typedef enum
{
Array = 0x0,
Water = 0x1,
Pool = 0xC,
channel_CTMU = 0x1D,
channel_DAC = 0x1E,
channel_FVRBuf2 = 0x1F
} adc_channel_t;
adc_channel_t channel;
unsigned ADC_Ch[] = {0x0, 0x1, 0xC}; //located in array indexes 0, 1, 2, respectively
const unsigned Array = 0; //so you can use english names when referring to array elements
const unsigned Water = 1; //you can also use #defines similarly but this is more dangerous since they can apply when they shouldn't if you aren't careful
const unsigned Pool = 2;
//ADC_Ch[Array] same as ADC_Ch[0]
//ADC_Ch[Water] same as ADC_Ch[1]
//ADC_Ch[Pool] same as ADC_Ch[2]
enum English_Index = {Array, Water, Pool};
English_Index This_Index
This_Index = Array; //or Water or Pool depending on whether you want 0, 1, or 2
ADC_Ch[This_Index]; //have to work through the enum variable. Can't directly do something like ADC_Ch[Water]
dknguyen thank you for the info. I am using Microchip Code Config and this is how it generated the code but it was a good learning opportunity
Ahh!! Generic code with generic assumptions.... Never used code configurator, NEVER will!!!dknguyen thank you for the info. I am using Microchip Code Config and this is how it generated the code but it was a good learning opportunity
You shouldn't need to reject the hi and low values unless you get occasionally get wildly erroneous readings in which case you should fix the source of the problem.I now have the adc cycling through the channels, my next question is I am using thermistor to measure the temp should I take a number of samples and average and should I through out the hi & low?
I am using a 10kΩ thermistor with a 10kΩ voltage divider is there something more that I need to add? I am also only powering up the thermistor to sample and then powering down.
I know that the thermistor is not the best to use but in this application it is my only option.How about an LM35 so you can get accurate temperature readings
Well, you can get real fancy by using bridge circuits and stuff if you wanted to. If you're powering it up and down then you'll need a method to do so (a switch transistor probably, and you might need to add stuff to compensate for the voltage drop across it when you sample).I am using a 10kΩ thermistor with a 10kΩ voltage divider is there something more that I need to add? I am also only powering up the thermistor to sample and then powering down.
That was what I was lead to believe because of not being non-linear.
That was what I was lead to believe because of not being non-linear.
typedef struct
{
size_t len;
char *data;
}buf_t;
void i2c_readDataBlock(i2c_address_t address, uint8_t reg, void *data, size_t len)
{
// result is little endian
buf_t d;
d.data = data;
d.len = len;
while(!i2c_open(address)); // sit here until we get the bus..
i2c_setDataCompleteCallback(rdBlkRegCompleteHandler,&d);
i2c_setBuffer(®,1);
i2c_setAddressNACKCallback(i2c_restartWrite,NULL); //NACK polling?
i2c_masterWrite();
while(I2C_BUSY == i2c_close()); // sit here until finished.
}
So now that I have the adc figured out I have moved to the next step of reading on one MCU and displaying on another MCU v i2c.
here is the code that was generated by MCC
I am confused about the void pointer and how to assign that data to a float variable. I am reading a float from one MCU and need to assign to another variableC:typedef struct { size_t len; char *data; }buf_t; void i2c_readDataBlock(i2c_address_t address, uint8_t reg, void *data, size_t len) { // result is little endian buf_t d; d.data = data; d.len = len; while(!i2c_open(address)); // sit here until we get the bus.. i2c_setDataCompleteCallback(rdBlkRegCompleteHandler,&d); i2c_setBuffer(®,1); i2c_setAddressNACKCallback(i2c_restartWrite,NULL); //NACK polling? i2c_masterWrite(); while(I2C_BUSY == i2c_close()); // sit here until finished. }
that I have declared on the other MCU.