Tried that, changed the analog pin PB0 to D7 to get the pwm and for the voltage used PB0 but the code crashes after the first pwm value. It seems because of the analogRead inside the interrupt?
volatile int pwm_value = 0;
volatile int prev_time = 0;
volatile float voltage=0.0;
void setup() {
Serial.begin(115200);
analogReadResolution(12);
// when pin D2 goes high, call the rising function
attachInterrupt(PA8, rising, RISING);
}
void loop(){
if (pwm_value > 0) {
Serial.println(pwm_value);
Serial.printf("voltage %f\n", voltage);
delay(1000);
}
}
void rising() {
attachInterrupt(PA8, falling, FALLING);
prev_time = micros();
voltage= analogRead(PB0) * 3.3/4096; // read the input pin
}
void falling() {
attachInterrupt(PA8, rising, RISING);
pwm_value = micros()-prev_time;
// Serial.println(pwm_value);
}