Skip to content

Commit

Permalink
Fix conversion when COMPAT_MODE is set
Browse files Browse the repository at this point in the history
The conversion was just backwards. In COMPAT_MODE, period value of 1000
corresponds to 1kHz, while, without COMPAT_MODE, 5000 corresponds to
the same period. So when SDK_PWM_PERIOD_COMPAT_MODE is set, period
should be multiplied by 5. For the same reason, duty needs to be
divided by 5.
  • Loading branch information
perpernorbi committed Aug 23, 2018
1 parent 5feee3a commit e3fce1d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions pwm.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@

#define PWM_MAX_TICKS 0x7fffff
#if SDK_PWM_PERIOD_COMPAT_MODE
#define PWM_PERIOD_TO_TICKS(x) (x * 0.2)
#define PWM_DUTY_TO_TICKS(x) (x * 5)
#define PWM_MAX_DUTY (PWM_MAX_TICKS * 0.2)
#define PWM_MAX_PERIOD (PWM_MAX_TICKS * 5)
#define PWM_PERIOD_TO_TICKS(x) (x * 5)
#define PWM_DUTY_TO_TICKS(x) (x * 0.2)
#define PWM_MAX_DUTY (PWM_MAX_TICKS * 5)
#define PWM_MAX_PERIOD (PWM_MAX_TICKS * 0.2)
#else
#define PWM_PERIOD_TO_TICKS(x) (x)
#define PWM_DUTY_TO_TICKS(x) (x)
Expand Down

1 comment on commit e3fce1d

@perpernorbi
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Used comments of @zym060050 from StefanBruens#24

Please sign in to comment.