I try the code ext interrupt pulse measurement on PA8 at STM32F103C8T6STM32F103C8T6Microcontrollers and processors…e Sep 27, 2016 10:28 pm I know this is an old topic, but… I’m using blue pill board ( STM32F103C8T6 , version 3). With the current (modified) Adafruit library 0.96″ OLED display w…View in hardware catalog ↗ chip. it’s ok
#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 Timerstimer.setChannel1Mode(TIMER_OUTPUT_COMPARE);timer.pause();timer.setCount(0);timer.setPrescaleFactor(72); //run at 72 MHz/72 = 1MHz count every 1ustimer.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 LOWHighToLowCount++;PulseWidth = CurrentCount;}timer.resume();}void timer_handler(){PulseWidth = 0;OverflowCount = 0;timeroverflow++;}
Replies12
Sun Nov 27, 2016 9:09 pm
Thanks for sharing.
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?
Mon Nov 28, 2016 1:38 am
@dangthaison1992
out of curiosity
any particular reason you’re using Serial1?
srp
Mon Nov 28, 2016 1:53 am
I used analogWrite(5, value); on arduino mega2560 for PWM and I measure the pulse pin PA8 on Generic STM32F103C8T6STM32F103C8T6Microcontrollers and processors…e Sep 27, 2016 10:28 pm I know this is an old topic, but… I’m using blue pill board ( STM32F103C8T6 , version 3). With the current (modified) Adafruit library 0.96″ OLED display w…View in hardware catalog ↗. it low noise more than use pulseIn(PA8, High, 5000);
Used ext interrupt pulse measurement
Image
Used pulseIn(PA8, High, 5000);
Image
Mon Nov 28, 2016 1:59 am
your output text is via Serial1, i just wondered why?
srp
Mon Nov 28, 2016 2:04 am
@dangthaison1992
out of curiosity
any particular reason you’re using Serial1?
I used usart1 PA9 TX -> pin0, PA10 RX ->pin1 of board Arduino UnoArduino UnoDevelopment and computing boards…ime debugging. konczakp Mon Jul 18, 2016 12:18 pm OK, so I took working example from Arduino UNO . I’ve cut off everything from library that I don’t need and from rest I have crea…View in hardware catalog ↗
Mon Nov 28, 2016 2:15 am
your output text is via Serial1, i just wondered why?
srp
i designed board. I used usart1 view data
Image
Image
Mon Nov 28, 2016 2:18 am
Thanks for sharing.
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.
Mon Nov 28, 2016 2:56 am
Thanks…
BTW. What does the board do ?
(Some sort of power controller / motor controller ?)
Mon Nov 28, 2016 3:17 am
Thanks…
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_STM32STM32Microcontrollers and processors…Map magic glue code, ethernet compiles, just WARNING: library LwIP claims to run on [ stm32 ] architecture(s) and may be incompatible with your current board which runs on [STM32]…View in hardware catalog ↗
Image
Mon Nov 28, 2016 3:22 am
Wow.
Looks like its heavy duty
Tue Dec 13, 2016 9:34 am
I made a similar code for a PPM signal decoder with 0.5us resolution .It works like a charm.
Tue Dec 13, 2016 1:16 pm
i do like those power lines
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.