Hi, I would like to ask you for advice on changing the PWM frequency on the ATtiny804. I don't have much experience with AVR processors and I can't figure it out on my own.
I would recommend to start with the blink sketch on the AT804, to see if you actually can get it programmed via UPDI.
Then play with the embedded example sketches of MegaTinycore
You will need to change the clock divider or period (TOP) value (or both) for the timer module in use. The processor data sheet has complete details.
I am not that new to programming ATtiny boards. I have a working updi programmer
thanks, I will try to search the datasheet
I tried to use the ATtiny_PWM library, but I can't get it to work
That means nothing to us, except that you are unhappy with whatever you did, and whatever result you had.
When I try to compile the PWM_basic sketch, which is part of the library. So I get this error massage
In file included from C:\Users\user\Documents\Arduino\libraries\ATtiny_PWM\examples\PWM_Basic\PWM_Basic.ino:16:0:
C:\Users\user\Documents\Arduino\libraries\ATtiny_PWM\src/ATtiny_PWM.h: In member function 'void ATtiny_PWM::setPeriod_TimerD0(long unsigned int)':
C:\Users\user\Documents\Arduino\libraries\ATtiny_PWM\src/ATtiny_PWM.h:301:12: error: 'TCA_t {aka union TCA_union}' has no member named 'CMPBCLR'
TCA0.CMPBCLR = pwmPeriod;
^~~~~~~
C:\Users\user\Documents\Arduino\libraries\ATtiny_PWM\examples\PWM_Basic\PWM_Basic.ino: In function 'void setup()':
PWM_Basic:78:18: error: 'BOARD_NAME' was not declared in this scope
Serial.println(BOARD_NAME);
^~~~~~~~~~
exit status 1
Exception in thread "AWT-EventQueue-0" 'BOARD_NAME' was not declared in this scope
java.lang.IndexOutOfBoundsException: len=-7
at sun.font.FontDesignMetrics.charsWidth(FontDesignMetrics.java:501)
at org.fife.ui.rsyntaxtextarea.TokenImpl.getWidthUpTo(TokenImpl.java:601)
at org.fife.ui.rsyntaxtextarea.TokenImpl.getWidth(TokenImpl.java:570)
at org.fife.ui.rsyntaxtextarea.RSyntaxUtilities.getTokenListWidth(RSyntaxUtilities.java:1180)
at org.fife.ui.rsyntaxtextarea.RSyntaxUtilities.getTokenListWidth(RSyntaxUtilities.java:1159)
at org.fife.ui.rsyntaxtextarea.SyntaxView.getLineWidth(SyntaxView.java:307)
at org.fife.ui.rsyntaxtextarea.SyntaxView.calculateLongestLine(SyntaxView.java:110)
at org.fife.ui.rsyntaxtextarea.SyntaxView.updateMetrics(SyntaxView.java:903)
at org.fife.ui.rsyntaxtextarea.SyntaxView.setSize(SyntaxView.java:811)
at javax.swing.plaf.basic.BasicTextUI$RootView.setSize(BasicTextUI.java:1722)
at javax.swing.plaf.basic.BasicTextUI.modelToView(BasicTextUI.java:1046)
at javax.swing.plaf.basic.BasicTextUI.modelToView(BasicTextUI.java:1022)
at javax.swing.text.JTextComponent.modelToView(JTextComponent.java:1377)
at org.fife.ui.rtextarea.RTextAreaBase.possiblyUpdateCurrentLineHighlightLocation(RTextAreaBase.java:778)
at org.fife.ui.rtextarea.RTextAreaBase.setFont(RTextAreaBase.java:987)
at org.fife.ui.rsyntaxtextarea.RSyntaxTextArea.setFont(RSyntaxTextArea.java:2532)
at processing.app.EditorTab.applyPreferences(EditorTab.java:333)
at processing.app.Editor.lambda$selectTab$52(Editor.java:1457)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
Did you remember to select the correct board in the Arduino IDE?
Does that library support the MCU you have?
I have read the github page and it is supporting ATtinyx04 boards. (assuming it does support Attiny 804)
Just tried. PWM_BASIC wil not compile for 804 nor 824 because it is using the 12bit timerD whisch as far as I know only the 1 series have.
So it compiles for a 814.
Thanks for this information, is there a way to edit the library to use timerA/B?
Arduino is open source and you are free to edit any code, any way you like. Change the PWM frequency while you are at it.
So, I edited the library and now I'm getting this error when i try to compile the sketch
C:\Users\user\AppData\Local\Temp\ccR8F6zP.ltrans0.ltrans.o: In function
__base_ctor ': C:\Users\user\Documents\Arduino\libraries\ATtiny_PWM\src/ATtiny_PWM.h:237: undefined reference to__PeripheralControl'
collect2.exe: error: ld returned 1 exit status
exit status 1
Error compiling for board ATtiny1614/1604/814/804/414/404/214/204.
Track down where and how __PeripheralControl is normally defined, and make changes to your code accordingly.
So I solved the last problem and now I'm getting this annoying one when trying to upload the sketch:
An error occurred while uploading the sketch
Consider posting the actual, meaningful part of the error message. Or all of it, if you don't know which parts are important.
But first, read it carefully, and see if you can solve the problem yourself.
__PeripheralControl is the internal tracking variable inside the core used to determine whether the user has called takeOverTCA0 or takeOverTCD0 - which tell the core "Turn off any PWM from the timer, if it's a type A timer, give it the hard reset command (there isn't such a command on the TCD), and clear a bit in __PeripheralControl", and in turn, that bit being cleared tells the core "Pretend this timer does not exist for the purpose of all API calls" And all the builtin functions that can modify PWM behavior check __PeripheralControl.
That variable is not visible outside I think the wiring_* files, since it's not intended for use except as described above, and as it's not documented and not visible outside of the core files, the behavior of __PeripheralControl is not guaranteed not to change and user code should never use or need to use that variable (it is not in the least bit unlikely that I will have to significantly change the data stored in there on DxCore when the EB series comes out, with two new timer types, and I think that's part of the code that I mirror between the two cores to make maintenance of the cores tractable.
Have you looked at the TakingOverTCA0 guide and tried the examples provided? Changing the TCA configuration to get a different pwm frequency is like, pretty straightforward....
I tried to solve it.
btw this is the whole error message
Thanks for your help, I finally got it up and running