Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Clock frequency
Goto page 1, 2  Next
 
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: Mon Aug 10, 2020 4:02 pm    Post subject: Clock frequency Reply with quote

So one solution, I continue.
Mark, do you take into account the calibration constants of the internal RC oscillator to generate the baud rate?
What is my point? The test chip with which I test the possibilities shows me an error rate. So I took 1606 to have a clock signal generated on PB5 and found that the frequency is 20.27Mhz in constants, I see that as they point out in the documentation, the value needs to be adjusted so that the OSC20MCALIBA register is overwritten. The chip should then run at the adjusted frequency and the factory settings will be reset.
Alternatively, the baud rate is adjusted according to the factory calibration constants according to the procedure in the data sheet, with the core running at an unadjusted frequency.
Does Bascom do this calculation or should I do it myself? I'm not able to connect an oscilloscope now because I forgot to switch it and I measured the switching power supply so that was the last thing I measured. Smile
If I'm too intrusive, I'm sorry. I like accuracy and I don't like error. Although there are not many outages, they are.
Regards RS

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

Administrator



Joined: 09 Apr 2004
Posts: 5920
Location: Holland

blank.gif
PostPosted: Mon Aug 10, 2020 8:38 pm    Post subject: Reply with quote

the clock calibration registers are loaded automatic. if you want to change the core frequency you need to do that yourself. i only wonder which reference you would use?
i would suggest an external xtal when high accuracy/low drift is required.
if the problem is the baud, you can adjust the baud registers. bascom does not know at which voltage you run the micro. so which offset register to load.
i did not test because my offset is 0 and this there is no error.
the offset is a signed short int.
you can test the sign bit (bit 7), if 0 just add to the USART0_BAUD
if the MS bit is set, complement the number, add 1 and then sub this from the USART_BAUD

i could make it an option too.
my test chips all worked very reliable at 115200. but that might be because the error is 0.
i can check later if i have a micro with an actual offset error

odd enough the datasheet has a procedure to adjust the baud, but it would make more sense to adjust the osc. frequency so the baud becomes correct as well.
i wonder how the osc calibration reg relates to the osc err signature and if that can be used to adjust the osc. frequency. and if so, why that is not automatically.

_________________
Mark
Back to top
View user's profile Visit poster's website
SZTRAD

Bascom Member



Joined: 30 Dec 2019
Posts: 165

blank.gif
PostPosted: Tue Aug 11, 2020 10:21 am    Post subject: Reply with quote

1317/5000
Hi
An external crystal is the solution but it takes up input and they are extra components.
I took a clean, unused 1604 chip and had the constants listed after a reboot.
This is the result
Sigrow 16MHz 3V: 10
Sigrow 16MHz 5V: 17
Sigrow 20MHz 3V: 2
Sigrow 20MHz 5V: 4
Calibration constant: 27
When I go from the top, the values ​​are in the extract from the register
SIGROW.OSC16ERR3V address 1122
SIGROW.OSC16ERR5V address 1123
SIGROW.OSC20ERR3V address 1124
SIGROW.OSC20ERR5V address 1125
The latter is
CLKCTRL.OSC20MCALIBA (address 71 bits 5: 0) from which the calibration constant of the RC oscillator should be read after restart (if I understand correctly). It can be seen that there is a value that is not listed for any of the calibration constants, so in my humble understanding something does not belong there.
To change this value, write must be enabled by changing CPU_CCP = CCP_IOREG_gc and write a new value.
The manufacturer therefore leaves it up to the programmer to choose how to adjust the baud rate. Either apply the formula in section 10.3.4.1.1 to the specified chip or write to CLKCTRL.OSC20MCALIBA and run the kernel at the adjusted frequency. For series production, of course, it is better to use the first version or calibrate each piece is unthinkable. Or the programmer can decide to use the calibration constant from SIGROW but must copy it to the given register.
Regards RS
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5920
Location: Holland

blank.gif
PostPosted: Tue Aug 11, 2020 10:49 am    Post subject: Reply with quote

Quote:
The latter is
CLKCTRL.OSC20MCALIBA (address 71 bits 5: 0) from which the calibration constant of the RC oscillator should be read after restart (if I understand correctly). It can be seen that there is a value that is not listed for any of the calibration constants, so in my humble understanding something does not belong there.


Indeed that is odd. i also took a new chip and when i print the value for clkctrl_osc20mcaliba I get 9E which should not be possible.
the pdf :

These bits change the frequency around the current center frequency of the OSC20M for fine tuning.
At Reset factory calibrated values are loaded based on FREQSEL bits in FUSE.OSCCFG.


So this indeed means that either a wrong value is loaded or that some other default is loaded which is not accessible to the user. or that i dont get it Very Happy

_________________
Mark
Back to top
View user's profile Visit poster's website
SZTRAD

Bascom Member



Joined: 30 Dec 2019
Posts: 165

blank.gif
PostPosted: Tue Aug 11, 2020 11:17 am    Post subject: Reply with quote

The value of 9E is 8bit right? The actual value is 1E, 8 and 7 bits you have to mask.
Based on FREQSEL in FUSE.OSCCFG, you only select the fundamental frequency. The calibration is taken from the CLKCTRL.OSC20MCALIBA register. And to get it right, you have to put it there. If you have an oscilloscope (I have it on the way because mine will no longer measure) and you want to try it, set PB5 to oscout and measure it.
RS
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5920
Location: Holland

blank.gif
PostPosted: Tue Aug 11, 2020 11:44 am    Post subject: Reply with quote

yes it is 8 bit as it is an 8 bit register.
even if i mask the bits out i get 1E which does not match the fuse bytes : 0F (5V) and 09 (3V)
it does not make much sense to me. but i will test it later. gonna have a break now

_________________
Mark
Back to top
View user's profile Visit poster's website
SZTRAD

Bascom Member



Joined: 30 Dec 2019
Posts: 165

blank.gif
PostPosted: Tue Aug 11, 2020 11:50 am    Post subject: Reply with quote

However, I wrote in the message above that the value in the calibration register does not correspond to what they have stored there and that it will probably be some strange.
That's why I put a list of values from the processor there.
RS
p.s. Why is config sysclock = 16mhz not supported?
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5920
Location: Holland

blank.gif
PostPosted: Tue Aug 11, 2020 9:23 pm    Post subject: Reply with quote

i tested but when i write the offset into the calib register the frequency is way off. it goes from 20 Mhz to 15 MHz.
But i also asked Microchip support since the docs are not really clear about it.

config sysclock also should work for 16mhz. if not send a ticket to support. remember, the forum is not the support system. things get lost when all kind of new questions are added to a topic.

i also checked the baud offset and that seems to work. i only could not really measure the actual baud. but at high baud rate it all kept working fine.
i think it is simplest if i add a sub that you can call with a param for the osc value so as a user you can adjust the baud in a simple way using the offset from the chip.

_________________
Mark
Back to top
View user's profile Visit poster's website
SZTRAD

Bascom Member



Joined: 30 Dec 2019
Posts: 165

blank.gif
PostPosted: Wed Aug 12, 2020 8:36 am    Post subject: Reply with quote

Hello Mark
I am aware that this is not a support point for the system, but since I have experienced that a lot of people run into the same problem and then solve the same thing unnecessarily and overwhelm the support, I write it here specifically.
I'll have a moment today so I'll try to check it and send the results. I have to use another chip because 1604 doesn't have the system frequency set to pin and 1606 didn't stand my attempts.
For Config Sysclock = 16mhz, Prescale = 1, the compiler throws an Invalid parameter for CONFIG parameter or value [16MHZ] error.
I'll explore it too.
RS
Back to top
View user's profile
Skrivo

Bascom Member



Joined: 15 Jul 2020
Posts: 11

slovenia.gif
PostPosted: Wed Aug 12, 2020 12:27 pm    Post subject: Reply with quote

SZTRAD wrote:
Hello Mark
I am aware that this is not a support point for the system, but since I have experienced that a lot of people run into the same problem and then solve the same thing unnecessarily and overwhelm the support, I write it here specifically.
I'll have a moment today so I'll try to check it and send the results. I have to use another chip because 1604 doesn't have the system frequency set to pin and 1606 didn't stand my attempts.
For Config Sysclock = 16mhz, Prescale = 1, the compiler throws an Invalid parameter for CONFIG parameter or value [16MHZ] error.
I'll explore it too.
RS


I also get error for "Config Sysclock = 16mhz". Only for 20MHz compiler works. But at least for ATtiny3217 there is one fuse bit where you can select internal clock 16MHz or 20MHz (20MHz is default).
Back to top
View user's profile
SZTRAD

Bascom Member



Joined: 30 Dec 2019
Posts: 165

blank.gif
PostPosted: Wed Aug 12, 2020 2:28 pm    Post subject: Reply with quote

She is not a mistake according to the help there is only a 20mhz option. That's why I asked if it was not supported. But I know about switching fuses, but if you need to set up a prescaler, the choice must be there or you have to do it manually.
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5920
Location: Holland

blank.gif
PostPosted: Wed Aug 12, 2020 6:42 pm    Post subject: Reply with quote

there is only 1 osc. by default it is 20 mhz. and with the fuse settings it can be set to 16 mhz too. but it is one and the same osc.
so this is more like a name issue.
the only things really important is the $crystal setting. the sysclock opttions should match that.

So : Config Sysclock = 20mhz , Prescale = 1 is ok for $crystal = 20000000
in case you set the fuse byte to 16mhz, you would have something like this :
Config Sysclock = 20mhz , Prescale = 1 is ok for $crystal = 16000000

of course this is probably unclear when reading the source.
so 2 options :
A : Config Sysclock = 16_20mhz
or
B:Config Sysclock = 16mhz 'which would of course just enable the same osc.

let me know.

_________________
Mark
Back to top
View user's profile Visit poster's website
SZTRAD

Bascom Member



Joined: 30 Dec 2019
Posts: 165

blank.gif
PostPosted: Wed Aug 12, 2020 8:34 pm    Post subject: Reply with quote

I'm sorry I translated it and understood if someone read what was here.

It will be because there are actually 4 options (2 bits) and here are 5 options, so you have no way to handle it. I forgot that the switch is part of the fuses and they can only be changed via UPDI.
Maybe a bad idea, but I would rename the option to an internal oscillator or something shorter so you don't have it. The description evokes that it will make the change automatically. I wouldn't put much frequency into it, I'll explain why.
At low supply voltage, the maximum frequency is 5MHz and the programmer must then remember. By the way, you actually have this made up. You don't really know the power supply, but you could control the prescaler and crystal. I can quite imagine how good it will be to look for a timing error when someone overlooks this and sets it both differently.
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5920
Location: Holland

blank.gif
PostPosted: Wed Aug 12, 2020 8:49 pm    Post subject: Reply with quote

i did not meant that it would work now. as implemented there is only 1 option for the 20/16 mhz osc and it is named 20mhz.
what i wrote is that it can be changed and there is feedback required.
so 20MHZ can become 16_20MHZ

or, 16MHZ can be added as an option but indeed that would give the idea that you can change it which is not the case.

_________________
Mark
Back to top
View user's profile Visit poster's website
SZTRAD

Bascom Member



Joined: 30 Dec 2019
Posts: 165

blank.gif
PostPosted: Thu Aug 13, 2020 9:05 am    Post subject: Reply with quote

I understood what you meant, just a little later than usual. Smile
I will try the dependence of the frequency on the supply voltage of what it actually does. My point is that you actually calculate all the time constants, if I understand correctly, from the $ crystal directive, and here I see a bit of a problem not to forget it. That variable frequency is the vice of current processors. I don't know why manufacturers don't add one extra counter in which one would see what it's on.
I'm going to test it and share the results
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
Goto page 1, 2  Next
Page 1 of 2

 
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