Software PWM & time measurement with one timer

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

short:
setup software-pwm and use same timer to measure time.
problem: pwm frequency low.

Hello Forum!

currently i'm using an at90s2343 to measure rpm (time between pulses) and to output a PWM-Signal.
the calculation between the both values doesn't matter now.

my problem is, that my PWM frequency is too slow.

The controller is running on internal r-c oscillator with 1 MHz.
My algorithm describes as follows:

Timer prescaler = 8

timer overflow-interrupt: (tovf0)
{
get pwm-setpoint (8bit).
set timer value to a value that the next overflow happens at the desired time.
count up the (virtual) high-byte of timer0 on the correct condition.
change the status of the output pin.
}

external interupt: (int0)
{
get the actual timer value.
correct the timer value using the status of PWM-period (=putput pin).
get hi-byte oft timer0.
get old_timer(16bit).
store current timer0 (lo corrected, hi) in registers old_timer(16bit) (or sram)
calculate difference between act. timer0(16bit) and old_timer(16bit)
output the difference on duration-registers (16bit)
}

main loop
{
get duration-registers (1/ rpm)
calculate PID ... etc.
put pwm_setpoint (8bit)
}

the timer-overflow- interrupt takes 26 clocks.
so i cannot go below 4 or above 251 with the pwm_setpoint, but this is no problem.

by the way: i code with bascom-compiler.
But both interrupt-routines are coded in assembler.

The question is: is there a possibility to speed up the frequency by a software-trick ?
(i still want to use the timer for measuring the rpm.)

kind regards and thanx for any comment

Fabian

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Fabian,

the internal oscillator of the 2343 was not very stable. So I assume, the accuracy of your RPM measuring should not be better as +/-20%.

Why not use the ATtiny15L ?

Its oscillator was many times better stable and factory calibrated.
Also its two timers should solve the PWM problem.

Peter

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Peter!

peter: thanx for the tip with the tiny, the high speed-pwm would be a solution.

I think, im going to buy one and code in assembler, as the tiny unfortunately has no ram and therefore isn't supported by the bascom compiler.
assembler is anyway faster.

thank you!

but the question remains:
is there no "intelligent" way to produce faster PWM with 1 Mhz clock than 488 Hz ?
any ideas highly appreciated! ;-)

greetinx

Fabian