Skip to content
Snippets Groups Projects
Unverified Commit dd3c7db0 authored by recallmenot's avatar recallmenot Committed by GitHub
Browse files

GPIO branchless PWM flicker (#157)


* one GPIO library to rule them all

* GPIO example makefile transfer

* GPIO README.md video upload

* Update README.md

* Update README.md

* GPIO library path recitified

* GPIO pretty paths please

* platformio.ini removed GPIO_analogRead test

* GPIO removed implementation block (unused)

* restoring blink.bin #1

* restoring blink.bin #2

* GPIO_branchless added branching digitalWrite (sometimes necessary)

* GPIO fixed PWM fade flicker

---------

Co-authored-by: default avatarrecallmenot <edmund.raile@proton.me>
parent 49e75d02
No related branches found
No related tags found
No related merge requests found
...@@ -80,6 +80,10 @@ This puts the defaults at an inaudible 23.4kHz. ...@@ -80,6 +80,10 @@ This puts the defaults at an inaudible 23.4kHz.
The higher the frequency, the greater the EMI radiation will be. The higher the frequency, the greater the EMI radiation will be.
With low frequencies, say below 1000Hz, LEDs may exhibit perceivable flicker. With low frequencies, say below 1000Hz, LEDs may exhibit perceivable flicker.
Since this library enables compare capture preload (OCxPE of CHCTLRy), writing a value into the compare register using analogWrite will automatically apply it (=load into shadow register) when the timer starts its next cycle.
This avoids a bug whereby writing a compare value lower than the current counter value, the output will glitch high for the next cycle, resulting in flickery updates.
Writing `TIMx->SWEVGR |= TIM_UG` will immediately update the shadow register and cause the same issue.
*/ */
...@@ -463,12 +467,10 @@ static inline void GPIO_tim2_init() { ...@@ -463,12 +467,10 @@ static inline void GPIO_tim2_init() {
#undef GPIO_tim1_analogWrite #undef GPIO_tim1_analogWrite
#define GPIO_tim1_analogWrite(channel, value) ({ \ #define GPIO_tim1_analogWrite(channel, value) ({ \
TIM1->GPIO_timer_CVR(channel) = value; \ TIM1->GPIO_timer_CVR(channel) = value; \
TIM1->SWEVGR |= TIM_UG; \
}) })
#undef GPIO_tim2_analogWrite #undef GPIO_tim2_analogWrite
#define GPIO_tim2_analogWrite(channel, value) ({ \ #define GPIO_tim2_analogWrite(channel, value) ({ \
TIM2->GPIO_timer_CVR(channel) = value; \ TIM2->GPIO_timer_CVR(channel) = value; \
TIM2->SWEVGR |= TIM_UG; \
}) })
#endif // CH32V003_GPIO_BR_H #endif // CH32V003_GPIO_BR_H
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment