Bugfix for KLxx/K20 pwm period

Period is MOD + 1, so needs to add/substract 1 in the correct places
pull/410/head
Sissors 2014-07-21 19:03:07 +02:00
parent 699c1782d5
commit dc7155634a
2 changed files with 6 additions and 6 deletions

View File

@ -99,11 +99,11 @@ void pwmout_write(pwmout_t* obj, float value) {
value = 1.0;
}
*obj->CnV = (uint32_t)((float)(*obj->MOD) * value);
*obj->CnV = (uint32_t)((float)(*obj->MOD + 1) * value);
}
float pwmout_read(pwmout_t* obj) {
float v = (float)(*obj->CnV) / (float)(*obj->MOD);
float v = (float)(*obj->CnV) / (float)(*obj->MOD + 1);
return (v > 1.0) ? (1.0) : (v);
}
@ -118,7 +118,7 @@ void pwmout_period_ms(pwmout_t* obj, int ms) {
// Set the PWM period, keeping the duty cycle the same.
void pwmout_period_us(pwmout_t* obj, int us) {
float dc = pwmout_read(obj);
*obj->MOD = (uint32_t)(pwm_clock * (float)us);
*obj->MOD = (uint32_t)(pwm_clock * (float)us) - 1;
pwmout_write(obj, dc);
}

View File

@ -78,12 +78,12 @@ void pwmout_write(pwmout_t* obj, float value) {
value = 1.0;
}
*obj->CnV = (uint32_t)((float)(*obj->MOD) * value);
*obj->CnV = (uint32_t)((float)(*obj->MOD + 1) * value);
*obj->CNT = 0;
}
float pwmout_read(pwmout_t* obj) {
float v = (float)(*obj->CnV) / (float)(*obj->MOD);
float v = (float)(*obj->CnV) / (float)(*obj->MOD + 1);
return (v > 1.0) ? (1.0) : (v);
}
@ -98,7 +98,7 @@ void pwmout_period_ms(pwmout_t* obj, int ms) {
// Set the PWM period, keeping the duty cycle the same.
void pwmout_period_us(pwmout_t* obj, int us) {
float dc = pwmout_read(obj);
*obj->MOD = (uint32_t)(pwm_clock * (float)us);
*obj->MOD = (uint32_t)(pwm_clock * (float)us) - 1;
pwmout_write(obj, dc);
}