Hi all can a attiny 85 produce a 1 mhz pwm signal. Please advise.
Thanks
Perhaps. It depends on what frequency it works and what step you want for the PWM duty cycle.
Hi flashko
Just want a 50/50 duty and its run at 8 mhz
I have very little experience with timers. For a 50% duty cycle, I think you can get a pretty accurate frequency by choosing the right divider for the selected timer and setting the timer count range. Maybe you will find relevant info here
and also in datasheet of ATtiny85.
50/50 duty
Then don't bother to think about PWM. Use the timer in CTC mode to divide by 8 (set OCRA to 3, toggle pin on compare match) to produce 1 MHz output on a pin. The data sheet explains how the timer works.
Thanks guys for the help. Will do some reading in the datasheet
I mean, if it were me doing it I'd set Timer1 for fast PWM mode, the one where OCR1C is the period, set to 7, and the prescaler configured to divide by 8.
You could actually get resolution of at least 32 if not running at 5V, 64 if running at 5v (ie, 5 or 6 bits of resolution at 1 MHz. The 85 has a feature that is very rare on the classc AVRs - an on-chip PLL that lets the chip run at 16 MHz (PLL divided by 4), and timer1 run at the undivided PLL speed either 8x or 4x the 8 MHz internal oscillator (below 4.5v, you are supposed to use "low speed mode" which is that gives 32 MHz (and it's not compatible with using PLL as clock source), but running at 16 MHz at the voltages that require LSM isn't supported anyway). Note also that you can only use the much weirder timer1 (the one that's capble of running from the PLL) whether or not you need actual PWM or just an 1 MHz squarewave: there's only one other timer, and it's used for millis)
Usually the path of least resistance is to use analogWrite() to set up everything, but then immediately stop the timer, and reconfigure it, knowing that the other registers that you don't explicitly know yo need to change (the one controlling prescaler, the two OCR1's and possibly the waveform generation mode), and everything else will be set up for pwm already and you don't have to figure out the combination of OCR and PWM1 bits that need to be set to tell it to output PWM from Timer1.
There was so much heterogeneity on the classic AVRs. Timer1 is an example of it that I find particularly annoying, there are at least 5 implementations, the most useful being the 16-bit normal one. But the x5-series got the third worst timer of the lot, and the worst and second worst timer1's are only on 1 part each that hardly anyone touched even in their hayday. It's one thing to deal with quirks if you;re getting something for it, but when the timer is worse than the most common timer (the nice 16-bit one that almost every classic AVR has for Timer1 and sometimes higher numbered timers - All of ATTinyCore ues that kind of timer, except tor the x5, x61, 43, and 26 (in case of x7, x41, and 828, they bolted on a limited pin remapping scheme unique to that part or part family)
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.