![]() But it makes sense to me now, and seems to be a slightly nicer way of what Mr. I came across this library yesterday, and at the time of reading, I just couldn't make sense of the example, so I decided not to use it. I am myself just starting with this so don't know too much about it. Sorry for lingering here beyond the word but I thought this library provides a way to manipulate timer1 for PWM (arbitrary period and 10bit): Sorry, I just found this: TCCR1B |= ~(_BV(CS12) | _BV(CS11) | _BV(CS10)) Īctually, I think my first suggestion is correct! Thank you so much for this! If I wanted a prescaler of 1 (or rather, no prescaler), would I put CS10 in the brackets, instead of CS11? Now I measure a frequency of 978 Hz which is roughly 122 Hz * 8. The extra two lines change the prescaler from 64 to 8, multiplying the frequency by 8. You can do that by changing setup to: void setup () You could bump that back up by changing the prescaler. This would be because of the longer overall cycle time (counting up to 1023 rather than 255). You will note that the frequency has dropped down to 122 Hz. So, close enough to a duty cycle of 257 / 1023. I'm using SPI to see with the logic analyzer exactly what the value is at a given moment.Īt the moment when we have sent out 257, we get a pulse width of 2.0545 out of 8.1819 which gives: 2.0545 / 8.1819 * 1023 = 256.88 PWM, Phase Correct, 10-bit and set D9 pin correctly This seems to work OK in a sense: #include What if I changed val in analog_wiring.c to 1023, and changed the little timer bit in wiring.c?īut I take it I will be able to change OCR1A just as I would use analogWrite() in loop()? That sounds okay to me. ![]() This seems to work better: OCR1A = timerVal // set pwm duty And that was after adding: TCCR1A = 0x03 My testing confirms that if you try something like this: analogWrite (9, 254) for consistenty with Wiring, which doesn't require a pinModeįirst, analogWrite takes a 16-bit value. Also, make sure the pin is in output mode that support it, as we turn it off when digitally reading or ![]() We need to make sure the PWM output is enabled for those pins Other things aside: void analogWrite(uint8_t pin, int val) ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |