Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
5abb41a
copied my pwm input code from the older branch
XanBu Feb 4, 2025
b0280cd
pwm_input works
XanBu Feb 7, 2025
2c9ca24
Created necessary classes in order to seperate HAL stuff from main an…
XanBu Feb 7, 2025
156284b
Completed setup for class, with the exeption of the PWM_INPUTf3xx.cpp…
XanBu Feb 11, 2025
5178c45
Everything except this tim15 config works
XanBu Mar 29, 2025
58f0c4f
All timers that should work work.
XanBu Apr 22, 2025
1adeb76
committing pre fall changes
XanBu Aug 28, 2025
508a7b6
moved PWM Input setup into f3xx, need to clean up main sample and add…
XanBu Sep 6, 2025
82775ef
added getPWM_INPUT to manager.hpp, removed all setup from main sampl…
XanBu Sep 6, 2025
e369674
Works, need to clean it up a bit and add comments.
XanBu Sep 6, 2025
9b514ca
Added comments where needed
XanBu Sep 8, 2025
a7f164c
added comments, broke something
XanBu Sep 9, 2025
d4a008b
All pins/timers tested and working with 1000 micro second period
XanBu Sep 12, 2025
441c743
Applied Formatting Changes During GitHub Build
Sep 12, 2025
263b711
Update samples/pwm/main.cpp
XanBu Oct 9, 2025
0be73e0
Update src/core/io/platform/f3xx/PWM_INPUTf3xx.cpp
XanBu Oct 9, 2025
7396504
Moved Period, Frequency, and DutyCycle to be local variables in main …
XanBu Oct 9, 2025
921a336
Changed dutyCycle to be a uint8_t because it is whole percentages. Fi…
XanBu Oct 16, 2025
a360bcc
Update samples/pwm_input/main.cpp
XanBu Oct 16, 2025
42d6981
Merge branch 'feature/xmb4293/pwm_input_v2' of https://github.com/RIT…
XanBu Oct 16, 2025
f2a2fe0
Applied Formatting Changes During GitHub Build
Oct 17, 2025
d91f8e4
Changed names to follow standard naming convention
XanBu Oct 17, 2025
4d7c0e5
merge
XanBu Oct 17, 2025
d698e72
Applied Formatting Changes During GitHub Build
Oct 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ target_sources(${PROJECT_NAME} PRIVATE
src/core/io/GPIO.cpp
src/core/io/I2C.cpp
src/core/io/PWM.cpp
src/core/io/PWMInput.cpp
src/core/io/UART.cpp
src/core/io/SPI.cpp
src/core/io/types/CANMessage.cpp
Expand All @@ -57,6 +58,7 @@ if(COMPDEFS MATCHES "(.*)STM32F3xx(.*)")
src/core/io/platform/f3xx/GPIOf3xx.cpp
src/core/io/platform/f3xx/I2Cf3xx.cpp
src/core/io/platform/f3xx/PWMf3xx.cpp
src/core/io/platform/f3xx/PWMInputf3xx.cpp
src/core/io/platform/f3xx/UARTf3xx.cpp
src/core/io/platform/f3xx/SPIf3xx.cpp
src/core/dev/platform/f3xx/IWDGf3xx.cpp
Expand Down
58 changes: 58 additions & 0 deletions include/core/io/PWMInput.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@

#ifndef EVT_PWMINPUT_HPP
#define EVT_PWMINPUT_HPP

#include <stdint.h>

namespace core::io {

// Forward declarations:
// The different pins are hardware specific. Forward declaration to allow
// at compilation time the decision of which pins should be used.
enum class Pin;

class PWMInput {

public:
/**
* Setup the given pin for PWMInput usage.
*
* @param[in] pin The pin to setup for PWMInput
*/
PWMInput(Pin pin);

/**
* Get the current duty cycle.
*
* @return The duty cycle of the PWM signal being read, as a percentage.
*/
virtual uint8_t getDutyCycle() = 0;

/**
* Get the current period.
*
* @return The period the PWM signal being read is operating at in timer ticks.
*/
virtual uint32_t getPeriod() = 0;

/**
* Get the current frequency.
*
* @return The frequency the PWM signal being read is operating at in Hz.
*/
virtual uint32_t getFrequency() = 0;

protected:
/// The pin PWM input is on
Pin pin;
/// The duty cycle of the PWM input
uint8_t dutyCycle;
/// The period of the PWM input
uint32_t period;
/// The frequency of the PWM input
uint32_t frequency;
};

} // namespace core::io

#endif
51 changes: 51 additions & 0 deletions include/core/io/platform/f3xx/PWMInputf3xx.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@

#ifndef EVT_PWMINPUTF3XX_HPP
#define EVT_PWMINPUTF3XX_HPP

#include <HALf3/stm32f3xx.h>

#include <core/io/PWMInput.hpp>
#include <core/io/pin.hpp>
#include <stdint.h>

namespace core::io {

/**
* PWM input for f3
* Measures the duty cycle, frequency, and period of a PWM signal on a pin
*/
class PWMInputf3xx : public PWMInput {
public:
/**
* Setup the given pin for PWM Input usage.
*
* @param pin[in] The pin to setup for PWM Input Capture
*/
PWMInputf3xx(Pin pin);

uint8_t getDutyCycle();

uint32_t getPeriod();

uint32_t getFrequency();

/// Called from HAL_TIM_IC_CaptureCallback to update duty cycle, period, and frequency
void handleCapture(TIM_HandleTypeDef* htim);

/// Provides access to HAL handle for IRQ forwarding
TIM_HandleTypeDef* getHandle();

private:
/// HAL timer representation
TIM_HandleTypeDef halTIM; // hal timer handle
/// Channel for rising edge measurement
uint32_t directChannel;
/// Channel for falling edge measurement
uint32_t indirectChannel;
/// active channel
uint32_t activeChannel;
};

} // namespace core::io

#endif
18 changes: 18 additions & 0 deletions include/core/manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <core/io/GPIO.hpp>
#include <core/io/I2C.hpp>
#include <core/io/PWM.hpp>
#include <core/io/PWMInput.hpp>
#include <core/io/UART.hpp>
#include <core/io/pin.hpp>

Expand All @@ -19,6 +20,7 @@
#define IWDG_SUPPORTED
#define MCU_SUPPORTED
#define PWM_SUPPORTED
#define PWM_INPUT_SUPPORTED
#define RTC_SUPPORTED
#define SPI_SUPPORTED
#define UART_SUPPORTED
Expand All @@ -31,6 +33,7 @@
#include <core/io/platform/f3xx/CANf3xx.hpp>
#include <core/io/platform/f3xx/GPIOf3xx.hpp>
#include <core/io/platform/f3xx/I2Cf3xx.hpp>
#include <core/io/platform/f3xx/PWMInputf3xx.hpp>
#include <core/io/platform/f3xx/PWMf3xx.hpp>
#include <core/io/platform/f3xx/SPIf3xx.hpp>
#include <core/io/platform/f3xx/UARTf3xx.hpp>
Expand Down Expand Up @@ -240,6 +243,21 @@ PWM& getPWM() {
}
#endif

/**
* Get an instance of a PWMInput pin.
*
* @param[in] pin The pin to attach to the PWMInput.
*/
#ifdef PWM_INPUT_SUPPORTED
template<Pin pin>
PWMInput& getPWM_INPUT() {
#ifdef STM32F3xx
static PWMInputf3xx pwm_input(pin);
return pwm_input;
#endif
}
#endif

/**
* Get an instance of a UART.
*
Expand Down
1 change: 1 addition & 0 deletions samples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ add_subdirectory(lcd)
add_subdirectory(log)
add_subdirectory(millis)
add_subdirectory(pwm)
add_subdirectory(pwm_input)
add_subdirectory(queue)
add_subdirectory(read_write)
add_subdirectory(rtc)
Expand Down
3 changes: 3 additions & 0 deletions samples/pwm_input/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include(${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/evt-core_build.cmake)

make_exe(pwm_input main.cpp)
39 changes: 39 additions & 0 deletions samples/pwm_input/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Example of PWM input.
* This sample will measure the duty cycle, frequency, and period of a PWM signal.
*/

#include <core/io/PWMInput.hpp>
#include <core/io/UART.hpp>
#include <core/manager.hpp>
#include <core/utils/time.hpp>

namespace io = core::io;
namespace time = core::time;

int main(void) {
// Initialize system
core::platform::init();

// Setup UART
io::UART& uart = io::getUART<io::Pin::UART_TX, io::Pin::UART_RX>(9600);

uart.printf("Starting PWM input capture\n\r");

uint32_t Period = 0; // ICValue
uint32_t Frequency = 0;
uint8_t DutyCycle = 0;

io::PWMInput& pwmInput = io::getPWM_INPUT<io::Pin::PB_15>();

while (1) {
Period = pwmInput.getPeriod();
Frequency = pwmInput.getFrequency();
DutyCycle = pwmInput.getDutyCycle();
uart.printf("\n\rPeriod: %d\n\r", Period);
uart.printf("\n\rFrequency: %d\n\r", Frequency);
uart.printf("\n\rDuty: %2d%%\n\r", DutyCycle);
uart.printf("\n\r----------------------------------\n\r");
time::wait(1000);
}
}
12 changes: 12 additions & 0 deletions src/core/io/PWMInput.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <core/io/PWMInput.hpp>

namespace core::io {

PWMInput::PWMInput(Pin pin) { // core::io::Pin pin
this->pin = pin;
this->dutyCycle = 0;
this->period = 0;
this->frequency = 0;
}

} // namespace core::io
Loading