This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

AC RMS Voltage Sensor Using STM32F103C8 and ZMPT101B

Hello all! this is a working (below at the end), code for using ZMPT to measure Ac mains 250VAC, The code is a working code and it is fairly accurate but my problem is that I have been trying quite for some time now to translate it to STM32 Keil uVision but I can't seem to do it. I want to start My ADC learning base on this. Please can someone here help me out to port this code to Keil uVision, I want the  RMS to display on serial monitor via UART1 TX_Only.

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
void setup(void) {
Serial.begin(9600); // initialize serial communication at 9600 bits per second:
//analogReference(INTERNAL); // set ADC positive reference voltage to 1.1V (internal)
}
// get maximum reading value
uint16_t get_max() {
uint16_t max_v = 0;
for(uint8_t i = 0; i < 100; i++) {
uint16_t r = analogRead(A0); // read from analog channel 3 (A0)
if(max_v < r) max_v = r;
delayMicroseconds(200);
}
return max_v;
}
// main loop
void loop() {
// get amplitude (maximum - or peak value)
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Sorry! In case you have viewed this code few minutes ago, I posted a wrong code but a have corrected it now.

ouble sensorValue1 = 0; double sensorValue2 = 0; int val[100]; int max_v = 0; double VmaxD = 0; double VeffD = 0; double RMS = 0; void setup() {  Serial.begin(9600); } void loop() {  for ( int i = 0; i 511) {  val[i] = sensorValue1;...Code I am learning STM32 with Keil but I am bewildered in some translations from my little knowlade
0