[BUG]: wong PWM frequency with internally tuned clocks on attiny402 #977
-
Noticed an issue where attiny402s flashed with internal tuned clocks would generate PWM with 89hz frequency instead of 50hz with some servos (i have a really big batch of sg90 clones and about 10% of them were unusable cuz of this issue) Weird thing is that setting the internal clock to the same frequency but untuned generates PWM with correct frequency and all servos work without issue. Maybe the TCA timer is setup incorrectly for PWM when the chip is flashed with internally tuned clocks? |
Beta Was this translation helpful? Give feedback.
Replies: 8 comments 1 reply
-
Are you using the included servo library? Because that doesn't depend on a TCA, it uses a TCB... (one of the design goals of the rewrite of that ages ago was specifically removing the dependance on the TCA clock for Servo, same was done for tone); it's now implemented as using the TCB clocked from system clock divided by 2. I am inclined to suspect that the root of the problem is that the system is not operating at the clock speed you think it is. Possibly something went badly wrong during the tuning process and it now has bad values stored? Tuning does not improve accuracy of the clock when used at room temperature - the factory cal has already picked the closest calibration setting at room temperature, and he oscillator has very little voltage dependance. Tuning helps when you want to overclock the chip for some reason or if you are running at temperatures far above or below room temperature, such that you need to correct for that. |
Beta Was this translation helpful? Give feedback.
-
Yeah i was using the included servo library, and i think you're right about something going wrong with clock tuning, the PWM jumps from 50hz to 89hz (or 88.39hz sometimes) when flashed with a tuned clock, the thing that im not sure about is why it affects only some servos and not the others. |
Beta Was this translation helpful? Give feedback.
-
I used those cheap MG90's (purple label) also and noticed that while the sticker is similar, The inside can vary. Metal gear, mixed gear and even had some that I could use as a thermometer, as the midpoint shifted if they became warmer. |
Beta Was this translation helpful? Give feedback.
-
I'll try that next time i find a some defective ones |
Beta Was this translation helpful? Give feedback.
-
What does
print when the problem is manifesting? |
Beta Was this translation helpful? Give feedback.
-
Well... i can't really tell you because all of the times it occurred was on boards that don't have USB or serial outputs and i can't really run them off the Serial2UPDI adapter |
Beta Was this translation helpful? Give feedback.
-
I am very confused as to how this bizarre situation has come about where you don't have any of the boards that are exhibiting the bug you are reporting. To fix a bug that only impacts some devices, you need to "capture" a malfunctioning device and examine it. I suspect the devices are improperly tuned. If I had a board that exhibited the problem in my hand, I'd throw it on the hotplate to take the chip off, mount the chip on a basic breakoout. Then I'd readthe fuses, If the issue., as I suspect, is tuning, that would make it possible to prove that theory - printing anyhthing to serialwould get gibberish only when a tuned speed was selected. , confirming improper tuning, then you could upload a sketch to dump the contents of the userrow and the SIGROW (not just the first 3 bytes - the wholer 64 bytes of the sigrow, the values I need are near the middle, and which specific ones I need depend on the values you read from the fuses. So yeah - that is what is needed to debug this issue - I would be able to tell within like 2 minutes of seeing those three pieces of information (sigrow dump, userrow dump, fuses) whether my theory is correct, and also speculate about how it occurred. s(oh, and what is the target F_CPU? what is the nominal clock speed? if you're using tuning to overclock or underclock, particularly to an extreme degree, did you verify that the USERROW contains tuning for the speed you hope to use., not the error code indicating that the the tuning sketch determined that that specimen doesn't work |
Beta Was this translation helpful? Give feedback.
-
No response, but presently it appears to be some sort of tuning issue, moving this to discussion unless we can show an issue with the core - in any event, without more information from OP there isn't really anything I can do here. |
Beta Was this translation helpful? Give feedback.
Yeah sorry i was out of reach for a while, found what was the issue, it was the clock option, i had it set to
4Mhz internal tuned
that messed with the PWM frequency on some chips, setting it just4Mhz internal
fixed and i had no further issues.Thank you for your taking the time to help me and sorry for the long response x)