Ley de Ohm
Fork of FastPWM by
Revision 6:0f57969697b6, committed 2014-03-17
- Comitter:
- Sissors
- Date:
- Mon Mar 17 22:12:58 2014 +0000
- Parent:
- 5:2812f0a115f7
- Child:
- 7:1b5df740bcd7
- Commit message:
- Changing period now keeps pulsewidth the same instead of duty cycle
;
; KLXX now doesn't give glitches when changing pulsewidth
Changed in this revision
--- a/Device/FastPWM_KLXX.cpp Fri Feb 28 18:18:52 2014 +0000 +++ b/Device/FastPWM_KLXX.cpp Mon Mar 17 22:12:58 2014 +0000 @@ -13,12 +13,10 @@ void FastPWM::pulsewidth_ticks( uint32_t ticks ) { *(_pwm.CnV) = ticks; - *_pwm.CNT = 0; //Not yet sure why this is needed! } void FastPWM::period_ticks( uint32_t ticks ) { *(_pwm.MOD) = ticks; - *_pwm.CNT = 0; } uint32_t FastPWM::getPeriod( void ) {
--- a/FastPWM.h Fri Feb 28 18:18:52 2014 +0000 +++ b/FastPWM.h Mon Mar 17 22:12:58 2014 +0000 @@ -22,9 +22,7 @@ /** Library that allows faster and/or higher resolution PWM output * - * Library can directly replace standard mbed PWM library. Only limitation is that the maximum PWM period is four times shorter - * The maximum achievable period is roughly 40 seconds, I dont think that should be a problem. - * Do take into account all PWM objects will run four times faster than default. + * Library can directly replace standard mbed PWM library. * * Contrary to the default mbed library, this library takes doubles instead of floats. The compiler will autocast if needed, * but do take into account it is done for a reason, your accuracy will otherwise be limitted by the floating point precision. @@ -40,22 +38,22 @@ FastPWM(PinName pin, int prescaler = -1); /** - * Set the PWM period, specified in seconds (double), keeping the duty cycle the same. + * Set the PWM period, specified in seconds (double), keeping the pulsewidth the same. */ void period(double seconds); /** - * Set the PWM period, specified in milli-seconds (int), keeping the duty cycle the same. + * Set the PWM period, specified in milli-seconds (int), keeping the pulsewidth the same. */ void period_ms(int ms); /** - * Set the PWM period, specified in micro-seconds (int), keeping the duty cycle the same. + * Set the PWM period, specified in micro-seconds (int), keeping the pulsewidth the same. */ void period_us(int us); /** - * Set the PWM period, specified in micro-seconds (double), keeping the duty cycle the same. + * Set the PWM period, specified in micro-seconds (double), keeping the pulsewidth the same. */ void period_us(double us);
--- a/FastPWM_common.cpp Fri Feb 28 18:18:52 2014 +0000 +++ b/FastPWM_common.cpp Mon Mar 17 22:12:58 2014 +0000 @@ -5,8 +5,8 @@ this->prescaler(prescaler); //Set duty cycle on 0%, period on 20ms - _duty=0; period(0.02); + write(0); } @@ -16,7 +16,6 @@ calcPrescaler((uint64_t)(seconds * (double) SystemCoreClock)); period_ticks(seconds * dticks + 0.5); - pulsewidth_ticks(getPeriod() * _duty); } void FastPWM::period_ms(int ms) { @@ -24,7 +23,6 @@ calcPrescaler(ms * (SystemCoreClock / 1000)); period_ticks(ms * iticks_ms); - pulsewidth_ticks(getPeriod() * _duty); } void FastPWM::period_us(int us) { @@ -32,7 +30,6 @@ calcPrescaler(us * (SystemCoreClock / 1000000)); period_ticks(us * iticks_us); - pulsewidth_ticks(getPeriod() * _duty); } void FastPWM::period_us(double us) { @@ -40,7 +37,6 @@ calcPrescaler((uint64_t)(us * (double)(SystemCoreClock / 1000000))); period_ticks(us * dticks_us + 0.5); - pulsewidth_ticks(getPeriod() * _duty); } void FastPWM::pulsewidth(double seconds) {