Skip to content

Commit 2e32c71

Browse files
author
Bogdan Marinescu
committed
[K64F] Ensure immediate update of CnV register in FTM
Also changed pin assignment for the PWM test.
1 parent 286a4e4 commit 2e32c71

File tree

2 files changed

+8
-4
lines changed
  • libraries

2 files changed

+8
-4
lines changed

libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_K64F/pwmout_api.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,19 @@ void pwmout_free(pwmout_t* obj) {
116116
}
117117

118118
void pwmout_write(pwmout_t* obj, float value) {
119+
uint32_t instance = obj->pwm_name >> TPM_SHIFT;
119120
if (value < 0.0f) {
120121
value = 0.0f;
121122
} else if (value > 1.0f) {
122123
value = 1.0f;
123124
}
124-
uint16_t mod = ftm_hal_get_mod(obj->pwm_name >> TPM_SHIFT);
125+
uint16_t mod = ftm_hal_get_mod(instance);
125126
uint32_t new_count = (uint32_t)((float)(mod) * value);
126-
ftm_hal_set_channel_count_value(obj->pwm_name >> TPM_SHIFT, obj->pwm_name & 0xF, new_count);
127-
ftm_hal_set_counter(obj->pwm_name >> TPM_SHIFT, 0);
127+
// Stop FTM clock to ensure instant update of MOD register
128+
ftm_hal_set_clock_source(instance, kClock_source_FTM_None);
129+
ftm_hal_set_channel_count_value(instance, obj->pwm_name & 0xF, new_count);
130+
ftm_hal_set_counter(instance, 0);
131+
ftm_hal_set_clock_source(instance, kClock_source_FTM_SystemClk);
128132
}
129133

130134
float pwmout_read(pwmout_t* obj) {

libraries/tests/mbed/pwm/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ float value = 0.75;
1818

1919
int main() {
2020
#if defined(TARGET_FF_ARDUINO)
21-
PwmOut pwm(D5);
21+
PwmOut pwm(D9);
2222

2323
pwm.period_ms(10);
2424
pwm.write(value);

0 commit comments

Comments
 (0)