Hi!
Im using Attiny84 for control servo. For this I involve Servo_ATTinyCore.h. However, the lib description says that "analogWrite of PWM on pins associated with the timer are disabled when the first servo is attached".
So Im wondering how to use PWM on Attiny84 to control MOSFET alongside with servo?
Attiny84 has a 8-bit Timer0 and a 16-bit Timer1
I think Servo is using Timer1 (but not sure), so that would mean you can use the 8-bit Timer0 for generating PWM.
If Servo is using Timer0, you could use the 16-bit Timer1 for your PWM
Servo uses the 16-bit timer. On all parts with a 16-bit timer, it uses one of those.
Otherwise it uses the fanciest timer it can get.
So classic AVRs with normal 16-bit timer1's use Timer1.
ATtiny85's and 861s have an 8 or 10-bit high speed timer with very flexable prescaler, they use that instead,
Modern AVRs use one of the 16-bit non-PWM-or-8-bit-crap-pwm Type B timers (most parts have at least 2, some as many as 5)
Many pinout charts don't list which timer is used for pwm of which pin. On classic AVRs, the channels are names OCNx where N is a number of the timer and x is a letter corresponding to the channel (classic AVRs normally have 2 channels per timer.
On modern AVRs, the outputts are abbreviated "TCxn WOy, where xn is a letter indicating the type of timer, n is a number indicating the number of the timer, and y is either omitted (if the timer only outputs a single channel) gives the name of the channel at hand. Some timers have numbers for y (ex, type A timers) while others use letters (ex, the type D timer on some parts) and type B timers, since they suck for PWM and have only one channel, don't have anything after the WO.
OC stands for Output Compare (it outputs the result of comparing the timer count with a specified value. If the timer is counting repeatedly to 100, and the compare value is 20, you get PWM with a duty cycle of 20% or 80% (depending on how the timer is otherwise configured - most timers will do both normal and inverted PWM)
WO stands for Waveform Output, which is a less obtuse description of what it's doing.
They'll be shown on the pinout charts of classic AVRs, or in the I/O Multiplexing Considerations table on modern AVRs. There is no advantage to controlling a servo with the timer's "home" pin (however, on classic - but not modern - AVRs, there is much to be gained from generating any necessary tone() on the pin that the timer direction has control of. But the same advantage isn't there for Servo). Either way though while a timer is being used for servos, the pins associated with that timer won't doi PWM - because the timer's doing something else which you told it to do,.
On classic AVRs, timers have usually 2 PWM output channels, A and B, rarely (on huge chips like mea2560) a third channel , C, can be gotten from each 16-bit timer1-like timer. Classic MegaAVR usually has an 8-bit async timer with 2 channels and a couple of really weird, infrequently encountered caveats.
After timer2, if the part has more times, they're usually more of the nice 16-bit ones.
The ATtiny43 (a chip that is utter garbage except that it can run from a single alkaline battery via an on-chip boost converter (just add inductor and diode) and achieve very favorable sleep mode power consumption form such a battery, in large part because the boost converter knows that if the current is below a certain point, either the chip is asleep, or is running clocked slow enough that it doesn't need the whole 3v for operation, and will relax about the voltage regulation, while the 0-load current of a boost converter is almost always higher got cheated on the Timer1 - it's just a copy of Timer0.
Timer0, on the other hand is very basic, but it is universal. That timer is identical on almost every part (I can think of only two exceptions, all tinies - the x61 (it's wierd AF like everything else on that chip), and the x7 (where it's a single-pwm-channel hybrid of the normal Timer0 and async Timer2 of a mega).
Timer2, if present on a mega is AFAIK always the same or a very similar 8-bit async timer you can clock from a watch crystal if you insist. On classic tinyAVRs, only the x41 has a Timer2, and it's a copy of Timer.
Modern AVRs instead have relatively standardized timers, and parts combine different quantities of these - TCA's are the normal PWM timer, either 3 channel 16-bit, or split it in half and disable most of it's features to get 6 8-bit PWM channels (that's what my cores all do, since analogWrite is only 8-bit anyway) 1 on most parts, 2 on higher end non-tinys They get TCBs which are piss poor at PWM, but are spectacular utility timers, of of which is usually used for millis (it can also be used for PWM, but only if compromises are made. I think that those compromises are detrimental to to the integrity and reliability of the timekeeping API and refuse to make those compromises in my cores (mTC never uses TCB for PWM. DxCore will use it but at every chance I get in the docs I recommend against it), TCC was probably skipped because of it's similarity to register name s on classic AVRs related to timers. TCD is a crazy 12-bit async timer where the async caveats are no longer swept under the rug but are very visible, and explicitly discussed (it's the longest chapter in the modern datasheet. I had to read some sections 3-4 times to grok it. TCDs are very powerful, but they're sort of the feint of heart nor the dull of mine. Recent product brief for the EB revealed two new types of timers, a TCE specialized for PWM (likely specifically optimized for brushless DC motors, like the ATtiny861 was) which may have as many as 8 channels on it (ie, drive a 4-phase BLDC motor?), as well as a 24-bit type F timer that has PWM channels, but they might not see much use in that role unless the period was made considerably shorter - I think the idea is not to use them as PWM timers, but as super-TCBs under typical applications. and they threw in the PWM mode because it didn't cost much silicon and like it does also get you very accurate pulse lengths - but we'll have to wait a while for the first documentation for the new parts to come out to know the deets. On the modern AVE's. peripherals gain but very rarely lose features. On classic AVRs, peripherals gained and lost functions right and left.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.