2019-09-09 12:34 AM
2019-09-28 04:02 AM
hello sir, now i'm able to get the values of IRMS and VRMS when i execute the program individually inside the while loop.
the problem here i face is when i try to get the values of IRMS and VRMS together , inside the while loop i get the correct reading with the incorrect values and so forth.
while (1) {
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
//voltage measurement
reg = reg_V|reg_r; //0x17|0x00
READ_24bit(reg); //function described below
V = (0.5 / 1551400.0 / sqrt(2)) * data * 476; //voltage calculation
sprintf(buffer1, "data=%ld, VRMS=%.2f \r\n", data, V); //uart
uprintf(buffer1);
HAL_Delay(10);
reg = reg_I|reg_r; //0x16|0x00
READ_24bit(reg); //function described below
I = (0.5 / 1868467.0 / sqrt(2)) * data / 10.0 * 1800; //current measurement
sprintf(buffer, " data=%ld, IRMS=%.2f \r\n", data, I); //uart
uprintf(buffer);
HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_13);
HAL_Delay(100);
}
}
uint32_t READ_24bit(uint8_t reg) {
Slave_select();
data=0;
uint8_t data0=0, data1=0, data2=0;
DWT_Delay_us(10);
spi_transmit(reg); //transmit register value
DWT_Delay_us(25);
data0 = spi_transmit(0x00); //first 8 bit read operation
DWT_Delay_us(5);
data1 = spi_transmit(0x00); //second 8 bit read operation
DWT_Delay_us(5);
data2 = spi_transmit(0x00); //third 8 bit read operation
DWT_Delay_us(5);
Slave_deselect();
data = ((uint32_t) data0 << 16) | ((uint32_t) data1 << 8)| ((uint32_t) data2);
return data;
}
help me.
2019-09-28 04:25 PM
“i get the correct reading with the incorrect values and so forth�?
What the heck does that mean? If you want help on an internet forum, the better you lay our your problem the more helpful the responses can/will be.
2019-09-29 08:26 AM
answer me please.
2019-09-29 08:48 AM
I'm not able to debug this through a keyhole. You have code fragments, talking to a device I don't have, and no supporting data showing any of the registers, values read. intermediate computations. Your code outputs messages, don't see any of this output, or the data supporting it.
I don't seen any registers dumps, or scope output.
Best you work this out with your colleagues, and ST / Analog Devices support staff.