-
Notifications
You must be signed in to change notification settings - Fork 1
Perchance We May need Input? #122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
XanBu
wants to merge
24
commits into
main
Choose a base branch
from
feature/xmb4293/pwm_input_v2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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 b0280cd
pwm_input works
XanBu 2c9ca24
Created necessary classes in order to seperate HAL stuff from main an…
XanBu 156284b
Completed setup for class, with the exeption of the PWM_INPUTf3xx.cpp…
XanBu 5178c45
Everything except this tim15 config works
XanBu 58f0c4f
All timers that should work work.
XanBu 1adeb76
committing pre fall changes
XanBu 508a7b6
moved PWM Input setup into f3xx, need to clean up main sample and add…
XanBu 82775ef
added getPWM_INPUT to manager.hpp, removed all setup from main sampl…
XanBu e369674
Works, need to clean it up a bit and add comments.
XanBu 9b514ca
Added comments where needed
XanBu a7f164c
added comments, broke something
XanBu d4a008b
All pins/timers tested and working with 1000 micro second period
XanBu 441c743
Applied Formatting Changes During GitHub Build
263b711
Update samples/pwm/main.cpp
XanBu 0be73e0
Update src/core/io/platform/f3xx/PWM_INPUTf3xx.cpp
XanBu 7396504
Moved Period, Frequency, and DutyCycle to be local variables in main …
XanBu 921a336
Changed dutyCycle to be a uint8_t because it is whole percentages. Fi…
XanBu a360bcc
Update samples/pwm_input/main.cpp
XanBu 42d6981
Merge branch 'feature/xmb4293/pwm_input_v2' of https://github.com/RIT…
XanBu f2a2fe0
Applied Formatting Changes During GitHub Build
d91f8e4
Changed names to follow standard naming convention
XanBu 4d7c0e5
merge
XanBu d698e72
Applied Formatting Changes During GitHub Build
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. | ||
ActuallyTaylor marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| */ | ||
| 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 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> | ||
ActuallyTaylor marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| #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 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.