Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

clock 328 for MWS

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
SZTRAD

Bascom Member



Joined: 30 Dec 2019
Posts: 165

blank.gif
PostPosted: Thu Feb 04, 2021 7:31 pm    Post subject: clock 328 for MWS Reply with quote

Since the topic is closed, I will answer my MWS colleague here. I think it's quite important and for some people it could solve unexpected problems.

From MWS
Flash is prepared to run with higher clock, after all the controller runs up to 20MHz.
If executing single instructions only, that's 20 million commands per second, the flash must be able to fetch instructions in that speed, 14 MHz will do no harm to flash
.

Yes you are right flash is able to work up to 20MHz (even a little more), but this does not apply to the internal signal source. The catalog sheet quite clearly states that I quote "Note that this oscillator is used to time EEPROM and Flash write accesses, and these write times will be
affected accordingly. If the EEPROM or Flash are written, do not calibrate to more than 8.8MHz.
Otherwise, the EEPROM or Flash write may fail. "
Since the fuses are part of rewritable memory, you may not be able to write to it again from the program. I didn't write anything about the processor being damaged. It just freezes and you don't know why.
Again, I'm probably a little paranoid, but these attempts don't work well.
I'm not saying it's not possible, I'm just pointing out that it may not be reliable.
Just for fun, about 5 years ago I tried it and the 328 runs up to 25MHz on an external crystal and without any problems at 11.5MHz on an internal RC. I think it's not so much due to the speed of the memory but rather the edges of the clock signal, where the RC time constant will be so small that it will not be able to keep the input values ​​of the schmitters (or whatever they have there) to match the edges of the signal.
RS

(BASCOM-AVR version : 2.0.8.3 )
Back to top
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Thu Feb 04, 2021 8:44 pm    Post subject: Re: clock 328 for MWS Reply with quote

SZTRAD wrote:
The catalog sheet quite clearly states that I quote "Note that this oscillator is used to time EEPROM and Flash write accesses, and these write times will be affected accordingly. If the EEPROM or Flash are written, do not calibrate to more than 8.8MHz.
Otherwise, the EEPROM or Flash write may fail. "

Take explicitly note of: Flash write. This means: bootloader. While user-code execution you won't write flash.
Quote from the datasheet in my mentioned post :
Quote:
During reset, hardware loads the pre-programmed calibration value into the OSCCAL

The pre-programmed calibration value is written to the controller at production time, is located in the so-called Signature Row and is not user-writable.
OSCCAL however is part of IO, which gets lost as power goes off or a reset is triggered, for example by the programmer.
And a hard-reset or power-off always, even a watchdog-reset overrides any incorrect code execution.
Quote:
Since the fuses are part of rewritable memory, you may not be able to write to it again from the program.

That's your error.
Fuses are rewritable, but even then, the calibration byte is not part of the fuses, at least not in ATMega328.
OSCCAL is volatile and restored from the signature row.
Quote:
It just freezes and you don't know why.

The code you have flashed may freeze, but not forever, only till you flash new and better code.
Beside, if I would write code which bothers with OSCCAL and if this code freezes, I would guess why.
Quote:
Again, I'm probably a little paranoid, but these attempts don't work well.

Oh, I don't would say paranoid, rather the mechanism seems not to be clear.
It works this way, for example with bootloader:

1) Evil program loads 255 into OSCCAL.
2) Controller feels insulted, stops or stutters.
3) RESET-pin pulled low, reset is issued.
4) OSCCAL loads calibrated value from signature row, runs now @8MHz (if CKDIV8 = 1)
5) Bootloader is executed, new flash content with no or lower OSCCAL settings is written.
6) New code starts, either leaves OSCCAL untouched, then clock is still 8MHz.
In case OSCCAL is still too high and code freezes again, then repeat.
This procedure can be automated too.
Without BL, replace 5) by 'Code is flashed via ISP'.

Anyway, in this process old code has no chance to keep the old OSCCAL.
Thus you can not brick a controller with OSCCAL, as you'll always get another chance.
Quote:
I'm not saying it's not possible, I'm just pointing out that it may not be reliable.

Why, do you have experiences with this issue?
Quote:
without any problems at 11.5MHz on an internal RC.

Did you try to set OSCCAL to 255 or did you stop early?
Back to top
View user's profile
SZTRAD

Bascom Member



Joined: 30 Dec 2019
Posts: 165

blank.gif
PostPosted: Fri Feb 05, 2021 8:58 am    Post subject: Reply with quote

So we really don't understand each other.
I understand how it works and I do not argue that after the reset everything returns and the processor works normally.
I'm just saying that if you do it repeatedly while the program is running, it can freeze. And a reset is not the solution in case of unexpected outages. We differ in our point of view, that's all. Just as the solution is not to go to parameters outside the manufacturer's recommendations just to the point that I need to generate the SPI bus faster. If the speed is not enough for me, I reach for something faster or I solve it differently. I hope I agree on that.
I have experience because I test the limit catalog values ​​of the used components before their deployment.
How it works in tests. Buy 10 samples from different sources to have different batches. And they are tested for the given parameters. The clock is currently being tested in great detail for external interference and stability, including the temperature profile. A statistical sample is obtained from the 10 measurements and the given parameters must not be exceeded in the projects under any conditions.
I do the test in reverse reverse the frequency up and generate the output signal per port. since it works in interrupt so i can see when it dropped out.
I apologize for my English, the problem of the translator and my description seems to be known here.
Back to top
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Fri Feb 05, 2021 10:39 am    Post subject: Reply with quote

SZTRAD wrote:
So we really don't understand each other.

Partially maybe.
Quote:
I'm just saying that if you do it repeatedly while the program is running, it can freeze.

The word repeatedly is nowhere to find in your top-post, so this is a new condition you claimed now.
Quote:
And a reset is not the solution in case of unexpected outages.

Correct. But you wrote about permanent damage:
SZTRAD wrote:
Since the fuses are part of rewritable memory, you may not be able to write to it again from the program.

which is wrong, so I had to prove the contrary.
Quote:
We differ in our point of view,

No, considering above context it's not only the POV, you did state something very different.

I am aware that my suggestion was a hack, but as the TO of the mentioned thread made the mistake to finish the hardware before proper evaluation, which made him sound a bit desperate, I considered my suggestion to be a fair hack.
Only at the end of the discussion it came obvious, that the TO was not fixed to mentioned display, as he readily gave up to try his luck with another display.

That's for the background, but for properly doing this hack, I would firstly test out, how far I can go.
As said this can be an automated process, increase the value of OSCCAL by 1, slow down, write to EEProm, transfer new value up slowly to OSCCAL, run several minutes and repeat till 255 or until a heartbeat-led in the mainloop doesn't do its beating anymore. The value in EEProm is the last good value for OSCCAL. If I'd test an OSCCAL of 240 to be ok, I'd chose my max as 10 to 20 below.

Means also I would avoid harsh changes in OSCCAL, as the R/C may stutter then. I would not do a hard switch from 255 to 128 and back, I would step up and down in terms of 1s or 10s in a loop.

Doesn't matter if this takes a few cycles, as it's only required for reading/writing to EEProm.
Back to top
View user's profile
SZTRAD

Bascom Member



Joined: 30 Dec 2019
Posts: 165

blank.gif
PostPosted: Fri Feb 05, 2021 11:48 am    Post subject: Reply with quote

In our language, this is exaggeratedly called "tearing off an identity card"
Yes you are right in my posts no but in yours yes.
I quote
Can make the difference between a 'tad too slow' vs. 'good enough'.
Only make sure you switch it back to default before any EEProm access.
If I understand correctly you mean switching at runtime. Or am i wrong?

And I just pointed out that he may not be able to change it back because he won't be allowed to write.
Yes, I didn't point out that it could reset from this, but I also didn't say that the chip would be damaged.
You know I do a lot with children and young people (I return to the community what was provided to me a long time ago) and since they are learning I try from the beginning to forget about the internet and the vast majority of arduino constructions where they just put it together and copy the program and it somehow works but they were thinking about what the manufacturer wrote. If it goes well and at least a few of them understand that the manufacturer wrote it there for some reason and it is necessary to follow it. I followed the master of the original interviewer and I know that he wrote that he was an older person (he wrote it somewhere) so I pointed out that a problem could occur.
Thanks to the Internet, it is read by more people and many of them buy a module from China or a processor from a store, use a scheme from the Internet, read that they can hack it and then are surprised by the result.
That's why I'm used to saying b) when I say a).

I quote
Means also I would avoid harsh changes in OSCCAL, as the R / C may stutter then. I would not do a hard switch from 255 to 128 and back, I would step up and down in terms of 1s or 10s in a loop.
You didn't say that in the original post.

You have to keep in mind that not everyone knows the catalog sheet to the last comma. Quite often I hear the opinion that the catalog sheet or instructions are read last because they have a lot of pages.

Before it degenerates into an exchange in Mark's previous closed post, I'd end it. It is probably clear to the two of us what is going on, and in my work I will not allow myself to do something that someone might find in the future as a mistake of judgment and processing.

From my point of view, I would not choose this display for these series of processors. If I were already forced to solve this AVR, I would choose xmeg with external memory and I would copy the memory image using DMA and SPI. When I ever have time (now it looks like I'll have enough of it) and I will rewrite it from c to bascom. I've been forced to use c for a long time now, and I have a lot of libraries written in c.
Since I'm slowly returning to bascom now and I have to say that Mark has worked a lot on it over the years and I expect your help. I used bascom for simple purposes and never lost its beauty of simple language where one does not have to worry about what it does but how it works as a result.
Back to top
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Fri Feb 05, 2021 2:27 pm    Post subject: Reply with quote

SZTRAD wrote:
In our language, this is exaggeratedly called "tearing off an identity card"

As well fuzzy-logic exists, writing code for controllers does not pardon fuzzy coding, thus lets stay sharp with our expressions, who said what and when.
Quote:
If I understand correctly you mean switching at runtime. Or am i wrong?

You understand correct, as switching is only possible on runtime.
Quote:
And I just pointed out that he may not be able to change it back because he won't be allowed to write.

What you maybe want to tell is, that a controller running nuts by executing random/nonsense code, can basically not restore the volatile IO-register OSCCAL back to its regular value.

This would be correct, also correct would be, that the controller is not able to free himself out of this condition.
It requires a WDR or hard-reset, and without flashing new code a program with OSCCAL set too high will likely get stuck again.
However this is not a permanent condition, which the phrase 'to brick something' would fit for.

But that's what you wrote, you wrote about flash and fuses, which was nonsense in this context.
Quote:
Since the fuses are part of rewritable memory, you may not be able to write to it again from the program.

As you misunderstood OSCCAL or at least the signature row as belonging to flash, your words point out a serious and enduring condition.

Quote:
Yes, I didn't point out that it could reset from this, but I also didn't say that the chip would be damaged.

See above, damage is what your words implicate.
If these words do not mean damage, their meaning become completely senseless then.
Quote:
You know I do a lot with children and young people (I return to the community what was provided to me a long time ago) and since they are learning I try from the beginning to forget about the internet and the vast majority of arduino constructions where they just put it together and copy the program and it somehow works but they were thinking about what the manufacturer wrote. If it goes well and at least a few of them understand that the manufacturer wrote it there for some reason and it is necessary to follow it. I followed the master of the original interviewer and I know that he wrote that he was an older person (he wrote it somewhere) so I pointed out that a problem could occur.
Thanks to the Internet, it is read by more people and many of them buy a module from China or a processor from a store, use a scheme from the Internet, read that they can hack it and then are surprised by the result.

My advise was a potential solution for a guy who screwed up. It's not about children and it's not about arduino.
If I tell you to jump from the cliff into the river, because otherwise the lion will eat you, it does not mean it is advisable for everyone to jump off cliffs.
This is everyones own responsibility.

If in contrary I project your comments and attitude to this case here, everyone must take care to jump from the sidewalk, as no one knows exactly how high it is, and whether somthing dangerous lures at the bottom. Very Happy
Means a pretended fear about nothing.
If my advise of speeding up the controller would not have worked out, what would have the TO lost?
Exactly: nothing.
Quote:
That's why I'm used to saying b) when I say a).

It was me who said a) and actually you said kagtresbqoutibxdralsqrek.
Quote:
I quote
Means also I would avoid harsh changes in OSCCAL, as the R / C may stutter then. I would not do a hard switch from 255 to 128 and back, I would step up and down in terms of 1s or 10s in a loop.
You didn't say that in the original post.

Why should I? It's my knowledge, which I would give as advise, if the addressee of my suggestion with his special demand would had positively responded to it.
Which he did not.

You remember which very special demand it was? It was:
Quote:
I don't want to use an external clock, as experience has shown that this leads to interference in my hf receiver.

If this would not be the case, the most straightforward advise would have been external oscillator or crystal.
Quote:
Before it degenerates into an exchange in Mark's previous closed post, I'd end it. It is probably clear to the two of us what is going on, and in my work I will not allow myself to do something that someone might find in the future as a mistake of judgment and processing.

Actually I do not understand what drives you to this lengthy and imho quite useless conversation.
Quote:
From my point of view, I would not choose this display for these series of processors. If I were already forced to solve this AVR, I would choose xmeg with external memory and I would copy the memory image using DMA and SPI.

You tell exactly what the user of said display knows in the meantime too.

As you ask me why I do not hand out details freely and of course presto, at once, you may excuse the question:
Why didn't you share your wisdom as the second poster in said thread?

Which I link here:
https://www.mcselec.com/index2.php?option=com_forum&Itemid=59&page=viewtopic&t=14743
as otherwise no reader in the future would understand what this thread here is all about.

Quote:
Mark has worked a lot on it over the years and I expect your help.

Don't expect me to understand that.
Did you ever try to back-translate the message from English to your native language?
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum