Trouble generating a 15-20KHz PWM signal on PA3 of an ATTiny404 #741
-
Hi all.
I've been trying to decipher the examples in Taking over TCA0 in the READEME. It seems to me that I've tried example 3 & the example code under "PORTMUX and accessing alternate pins" specifically for I'm probably missing something obvious here. My embedded development experience doesn't go too much deeper than Arduino APIs and framework wrappers. If anyone could give me so pointers as to what I may be doing wrong here, I would greatly appreciate it. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
Look at this code, doing 20khz pwm. https://github.com/tetrabiodistributed/papra-pcb-firmware/blob/main/papracode/papracode.ino |
Beta Was this translation helpful? Give feedback.
-
According to the datasheet, in section 20.2.2, WO3 is only available in split mode. Not sure how this will impact any other uses you may have for TCA. Section 20.3.3.6 then describes split mode configuration, where I think, to get output on PA3, which is WO3, you need to set HCMP0 to your compare value, as well as set clock speed/scaler as appropriate. If you ran the main clock at 16MHz and used a 1024 divider, you'd end up close to 15kHz. Note that the split mode will only give you 8-bits of resolution on your PWM output. The following code fragments are the kind of thing you may be wanting to do:
Of course, if you're using TCA for other things and need 16-bit single mode, then this won't help. Also, don't forget to tell the core you're taking over TCA. |
Beta Was this translation helpful? Give feedback.
-
Most of what you want is already set up. There's just a small tweak you need to do (unnecessary steps commented out
Y'all are making this way more complicated than it had to be ;-) |
Beta Was this translation helpful? Give feedback.
Most of what you want is already set up. There's just a small tweak you need to do (unnecessary steps commented out