I am designing modules for radio controlled aircraft. Most of the time I have to read a PWM pulse and produce a PWM pulse between 1000 - 2000 microseconds. When I use an Atmega328 (@16 MHz with crystal) there are no problems but if I use an Attiny85 (@8 MHz internal oscillator) I get servo jitter (due to PWM pulse timing problems). My question is; Can this behaviour be explained with the difference between a quartz and an R/C oscillator? Thank you...
Firstly, make sure you've not got the "CKDIV8" fuse set to 1, this will reduce your actual instruction clock rate to 1MHz if you're using the 8MHz internal oscillator. This is the default state of the ATTiny85 chip when it leaves the factory.
You can set the internal CPU frequency to 16MHz (refer to "Table 6-4" in the datasheet) using the following fuses in the programming dialog...
- EXTENDED = 0xFF
- HIGH = 0xDC
- LOW = 0xC1
You can type those numbers in hex into the 3 text fields in the "Fuses" section of the device programming dialog, doing this will automatically refresh the list of checkboxes corresponding to the full set of fuses in the device.
If you adjust your code to compensate for the higher frequency, this might be enough to give you better pulse timing resolution.
I use these fuses when I'm driving NeoPixel LEDs, which require rather fussy and tight timings.
Alternatively as you suggested, you can simply use a an external crystal oscillator of up to 20MHz. As always, follow the datasheet and you'll be able to do this.
Can this behaviour be explained with the difference between a quartz and an R/C oscillator?
Possible but unlikely.
The jitter from a t.v. oscillator is in the sub us range. And nothing over the long term (ms range)
The processing, if done right, is going to be 100 to 200 ticks per edge. So roughly 400 ticks over a 20000 tick period, even if the Mic runs at 1Mhz.
So the issue is likely your software.
edit: i just tested it on a atmega328p running at 1MIPS. Generating 5-ch of concurrent and independent RC signals utilizes less than 6% of the mcu's processing power. or 1200 ticks / 6 -> 200 ticks per channel in a 20-ms period.
The approach is outlined here: https://dannyelectronics.wordpress.com/2017/02/18/driving-multiple-servos-off-a-pic-timer2-ranged-extended/
so I would think your issues are likely with your software.