#include "HardwareTimer.h"
volatile int state = LOW;
volatile int HighToLowCount = 0;
volatile int LowToHighCount = 0;
volatile int val;
volatile int CurrentCount;
volatile int Period;
volatile int OldCount;
volatile int PulseWidth;
volatile int OverflowCount;
volatile int timeroverflow;
HardwareTimer timer(1);
void setup()
{
Serial1.begin(9600);
pinMode(PA8, INPUT);
attachInterrupt(0, exti_handler, CHANGE);
CurrentCount = 0;
OldCount = 0;
Period = 0;
PulseWidth = 0;
OverflowCount = 0;
timeroverflow = 0;
// Setup Counting Timers
timer.setChannel1Mode(TIMER_OUTPUT_COMPARE);
timer.pause();
timer.setCount(0);
timer.setPrescaleFactor(72); //run at 72 MHz/72 = 1MHz count every 1us
timer.setOverflow(65535);
timer.setCompare1(1);
timer.attachCompare1Interrupt(timer_handler);
timer.refresh();
timer.resume();
}
void loop()
{
Serial1.print("LowToHighCount: ");
Serial1.print(LowToHighCount);
Serial1.print(" HighToLowCount: ");
Serial1.print(HighToLowCount);
Serial1.print(" Period: ");
Serial1.print(Period);
Serial1.print(" PulseWidth: ");
Serial1.print(PulseWidth);
Serial1.print(" Overflow: ");
Serial1.println(OverflowCount);
delay(1000);
}
void exti_handler()
{
timer.pause();
CurrentCount = timer.getCount();
val = digitalRead(0);
if (val == HIGH)
{
LowToHighCount++;
Period = CurrentCount;
timer.setCount(0);
timer.refresh();
}
else { // state must be LOW
HighToLowCount++;
PulseWidth = CurrentCount;
}
timer.resume();
}
void timer_handler()
{
PulseWidth = 0;
OverflowCount = 0;
timeroverflow++;
}
Looking at the code, I think it measures pulse width, of both the high and low parts of a waveform?
With the value in microseconds
Can I add this code to the examples in the repo?
out of curiosity
any particular reason you’re using Serial1?
srp
Used ext interrupt pulse measurement

Used pulseIn(PA8, High, 5000);

srp
out of curiosity
any particular reason you’re using Serial1?
I used usart1 PA9 TX -> pin0, PA10 RX ->pin1 of board arduino uno
srp
i designed board. I used usart1 view data

Looking at the code, I think it measures pulse width, of both the high and low parts of a waveform?
With the value in microseconds
Can I add this code to the examples in the repo?
yes, you can add this code to the example in the repo.
BTW. What does the board do ?
(Some sort of power controller / motor controller ?)
BTW. What does the board do ?
(Some sort of power controller / motor controller ?)
The board is PID motor controller. I working the project pid driver motor use Arduino_STM32

Looks like its heavy duty
istr a discussion and quite a debate somewhere about the effectiveness and the amount of solder actually required, where oh where ?
this google search >effect adding solder to power traces tracks pcb< returns a few.
stephen

