Internal Oscillator calibration

Go To Last Post
84 posts / 0 new

Pages

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 you can resolve 724ppm in a single character, and 14 characters sent without gaps can resolve to 50ppm

Sadly, the gap is not likely to be constant (IRQ's or polling buffer empty effects)...but maybe the avg is? 

 Crazy pinout restrictions make things tough!  

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


Thank you Guys for all your suggestions. Little Background.

I had done this projects with Tiny2313 with External Crystal 8MHz. Everything was fine. 

As the request from the customers, Requiring compact design.

I have chosen Tiny412. (That is my major design fault). I should have chosen 14 Pin uC with External crystal.

Back to the Topic.

When the uC receives a command (consist of device ID and time count for relay ON time) from a smart phone. the relay should turn on & stays in that states until the time is elapsed.

For this time count. i'm using Timer Interrupt, resolution set to 100milli seconds. All i need to do is to calibrate this timer value. 

As suggested by many, Taking UART incoming character timings from the Bluetooth module, seems to be good idea.

 

But How do i connect to uC, (Bluetooth Tx is connected to Rx of uC) Only left with single GPIO i.e RST/UPDI Pin. 

 

And many thanks for all your suggestion.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i have used PWM to generate 100KHz, On the scope its reads as 101.882KHz

It is possible you are already getting 100.0000 KHz...maybe your scope timebase cal is off  a Hz or two...until you cal your scope, you don't know.

Once you have a definitive way to measure, you can find out.   Also, if you can assure the timebase is stable over temperature, then you can slightly tweak the number of pulse counts to get to 30mim. 

 

Say, for example, if 30 min would perfectly take 2000000 ticks---you might need to adjust it to 2000021 ticks (must be less than 55ppm, here 110 counts)...then the ppm temperature/time drift of the RC timebase will be your enemy.

 

If you were"desperate"  you could use a stopwatch to monitor the timeout & simply adjust the count capare up/down  until you get the exact delay...slooow, but doable with successive approx, homing it in. However, it's hard to stop a stopwatch by hand down to 0.1 sec.

 

Are you building 2 of or 2000 of these?...if building a quantity, would be easier to relayout for a bigger chip.

    

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

Last Edited: Wed. May 13, 2020 - 06:18 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I don't think you need any additional connection. The RX pin is already there. While the USART is receiving the bytes you can still sample the pin as if it were an IO pin. So as the data comes in you measure the pulse widths, find the smallest, and use that to calibrate the timer. Leave the oscillator alone.

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

david.prentice wrote:

i2C based 4 Digit 7 segment multiplexed display: 2 GPIO Pins.   multiplex needs 20% timing

Buzzer: 1 GPIO    timing is not important

 

Apropos of absolutely nothing, but once I built six-digit clock(/timer/counter/thing)s out of three two-digit displays, paralleled and multiplexed of course - and it turned out the display multiplexer frequency was just what I needed to run the piezo buzzer...   Convenient, that.  laugh  Of course, those were the same clocks that used an external 32.768kHz Xtal, and proved miserably inaccurate as timepieces without extensive calibration.   S.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

More usefully:

 

bspembed wrote:

But How do i connect to uC, (Bluetooth Tx is connected to Rx of uC) Only left with single GPIO i.e RST/UPDI Pin.

 

Put a bootloader in it.  Then TEST AND TEST AND TEST and when you're happy, blow the RST-DISABL fuse and there's your extra I/O pin.  We had an article about that awhile ago...  Expect to wreck a lot of chips (and quite a few boards) before you get it right.  S.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 While the USART is receiving the bytes you can still sample the pin as if it were an IO pin.

It seems like a single solitary pulse is too little to give needed resolution.  Ultimately need to resolve timebase to about 1 part in 18000.  But if the pulse is 1/9600, that corresponds to a sampling rate of  9600*18000 = 172.8 MHz !  If higher bauds are used, it is even worse.

Now, you might be able to repeat this over many many pulses (say 100) to avg & increase the apparent resolution.  If the random dithering is equally balanced, then maybe there is a bit of hope.  But all of this might rapidly grow into a full research project. 

 

 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

bspembed wrote:
As the request from the customers, Requiring compact design.

 

For that, go to a 4-layer board (move all those ground planes out of the way) and surface-mount on all the small passives (resistors, capacitors, diode) and stick them on the back.  The crystal too.

 

Given that AC-DC convertor and that relay, plus the bluetooth module and connectors, you're not going to get much smaller than you already have.

 

You could even stack two boards up - logic underneath the big power stuff.  S.

 

Edited - it's an AC-DC convertor.

Last Edited: Wed. May 13, 2020 - 06:51 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You can calibrate once at manufacture.  i.e. to about 0.5% accuracy for the RC.  And give you a software adjustment too.

You can "check calibration" with every Bluetooth message.    You count over a multi-character message.    This can trim your software adjustment over time.

 

Seriously,  no one is going to worry about 9 seconds in 30 minutes (if you don't tell them).

Switching a courtesy light or enabling a security lock are unlikely to be critical.

 

However accuracy is very important for an IED.   However sophisticated your "software adjustment" or ageing checks,  you can't risk any errors.

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

avrcandies wrote:

It seems like a single solitary pulse is too little to give needed resolution.

 

Oh no, I'm not suggesting a single bit, I'm saying use the whole message.

 

Think about it, the serial comms from the BT module is likely to work with basic oscillator calibration as you've got several percent to play with. So the comms into the uC will work whatever. The timing of the output can't start until the message has been received. So you have the luxury of the whole message to average out the width of a single 1/9600 bit.

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi OP please give us the baud rate, and the speed of the AVR you expect to use, so we can make some calculations.

 

For the internal osc:

I will kind of repeat #46

How accurate will the it be if OP in the 100 ms timer tick sometimes change the osc calibration byte, so over 256 interrupts (25.6 s) it perhaps have had it at one speed 100 times and the other 156 times the other, does that give any stability problems or other problems ?

 

I have never see any real data for how the internal osc change with age, are there any? (with the new chips without a real crystal osc I guess the question become more and more relevant ) 

Or actual have some one chips they know the changes of.

 

   

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I imagine, you (or someone else) has written a companion phone/tablet APP and there will be knock on issues with this.

 

Therefore my solution to this unsatisfactory mess is to think again about re-packaging the existing design.

 

bspembed wrote:
As the request from the customers, Requiring compact design.

 

Looking at your box photo and estimating measurements: - 120mm x 80mm. That not exactly huge. What is/will your new size be ? When you include a programming header; a not very different 100 x 80mm perhaps ?

 

You haven't posted a picture of your project in it's installed state. I imagine an intolerable mess of wires.

 

  1. What is that single wire for ? Does it exist for installed systems ?
  2. Do you think the customer wanted a more compact system vs enclosure ?

 

PS You've got mains on loudspeaker wire WTF: Choose Brown/Blue or even Black/White at least.

PPS: What's to stop someone mixing up connections and wiring mains straight across the relay contacts.

PPPS: Where are your fuses ?

 

Last Edited: Wed. May 13, 2020 - 09:34 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ATtiny414 + 32k crystal + rtc. Rtc has ~30us resolution and will be plenty accurate for what you do, also can use to calibrate main clock enough to not have to worry about uart. Now you have a few more pins to work with and can also keep updi as a programming only pin. An extra 10 cents + crystal will most likely be worth it.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Communication speed: 9600 Bits/seconds

AVR Speed: 4MHz (16 / 4)

BT Message will be <BSPBMC_05> for 5 minutes, <BSPBMP_10> for 10 Minutes ... <BSPBMC_30> for 30 Minutes.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


N.Winterbottom wrote:

 

  1. What is that single wire for ? Does it exist for installed systems ?
  2. Do you think the customer wanted a more compact system vs enclosure ?

 

PS You've got mains on loudspeaker wire WTF: Choose Brown/Blue or even Black/White at least.

PPS: What's to stop someone mixing up connections and wiring mains straight across the relay contacts.

PPPS: Where are your fuses ?

1. Single Black wire is a Four core flat cable for I2C Display.

2. Compact Enclosure. 

It's my mistake, i have chosen 412. (414, 14 pin would be better option with external crystal) .

Thanks for pointing out for all the hardware details. Will be taken care in the new design.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am intrigued.

 

A punter sits in a Massage Chair.

 

Either she or the Salon operator sets the "Massage time" via a mobile phone.

 

And it is important to have 0.1 second timing accuracy ???

 

I suspect that it takes a minute or two for the punter to position herself at the start.  A minute or two to get up and leave.   A minute for Salon staff to clean, prepare for the next customer.

 

Even with microsecond timing accuracy you will not get an extra customer 30 minute session into your working day.

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

With the odd placement of Gnd and Vcc perhaps you could place a 414 with 6 unused pins nc (2 will then be the 32768Hz xtal that could be placed on top of the chip), until you get at new version of the pcb.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

>Need to measure a time of 30 Minutes with an accuracy to +/- 100milli seconds.

 

From the last picture, I can't imagine where the precision is needed, and I have a good imagination.

 

Ok, you can keep the tiny412 now.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

bspembed wrote:

I have chosen Tiny412. (That is my major design fault). I should have chosen 14 Pin uC with External crystal.

Back to the Topic.

Can't you call the 412 based one a "prototyping experiment" and now redesign for a more appropriate chip? If this is all about board space then just go for a non-DIP (ie SMT) package but get a micro with enough pins and facilities to do all you require.

 

(like others I am rather intrigued to know why a massage requires such accurate timing constraints? Does the customer pay exactly by the minute/second?)

Last Edited: Wed. May 13, 2020 - 11:34 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


david.prentice wrote:

Even with microsecond timing accuracy you will not get an extra customer 30 minute session into your working day.

David.

I'm not worried about getting more customer.  Our device should be precise at least 1 second. 

 

Last Edited: Wed. May 13, 2020 - 11:48 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I guess you can't count on the time between each char, but you can look at the B there you can time 7 bits (the edge of the beginning of the last bit).

So there are 2917 CPU clk's to be used for speed measurement, that will be a resolution of about 0.03% that should work.

 

Add:

No that is an error on 5 sec (And there will be some added jitter error). (20 MHz could bring it down to about 1 sec )

But if the bluetooth module always spend the same time between chars it could work on the hole string.

 

Last Edited: Wed. May 13, 2020 - 11:44 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I bet that the Bluetooth will send N chars @ 9600 baud without any gaps.   Look at any of your USART transmissions.

Of course you will be checking for gaps as part of any sophisticated "check calibration from received Bluetooth" function.

 

I am still intrigued by the I'm not worried about getting more customer.  Our device should be precise at least 1 second. 

 

Hey-ho.   I am not in the Massage business.

 

I can see that you could eject a customer from the chair at the end of her session.     The screams might discourage the next customer.

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You can't get any of these chips in dip.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

david.prentice wrote:

And it is important to have 0.1 second timing accuracy ???

Absolutely - You won't need to refund any customer who complains his/her massage was 100ms too short. cheeky

 

  1. I really can't see that you'll significantly decrease the size. Isn't your box hidden within the electric chair anyway ? There should be plenty of room underneath or even the back of all sprung chairs I've seen. (Office & Dining chairs excepted). Just re-package the old design.
  2. Most mobile phones are pretty good at timekeeping. Why couldn't the APP send time re-synchronisation updates to your chair controller every few seconds. It's an APP update obviously, but the older controllers would surely ignore the new "time-synch" commands.

 

 

 

 

Last Edited: Wed. May 13, 2020 - 11:57 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


Hi all,

After tunning calibration value for internal oscillator and compensating the remaining error in Timer period value, would able to get precision within 1 seconds.

Used incoming BT data as time reference. 

Thanks all of you for the valuable suggestions & feedback. 

 

Prashanth

 

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Why not just add a few seconds to the timer to ensure the customer gets his full allotted time? Seems cheaper than spending hours trying to achieve a perfect timing interval for this particular case. YMMV

 

David

Last Edited: Wed. May 13, 2020 - 02:56 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Not that I've ever had a massage in any form but I can't help thinking that the last thing you might be doing during such a thing was running a stopwatch to ensure you were getting your money's worth to the exact second??

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You'll probably find a "good enough solution"  by now. 
 

Lessons learned---if someone is building a timer, start with a solid timebase!   Many others have been through the same wringer before you!

Your project looks very nice!

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

bspembed wrote:

Communication speed: 9600 Bits/seconds

AVR Speed: 4MHz (16 / 4)

BT Message will be <BSPBMC_05> for 5 minutes, <BSPBMP_10> for 10 Minutes ... <BSPBMC_30> for 30 Minutes.

That 9 char string should be enough.

 

david.prentice wrote:

I bet that the Bluetooth will send N chars @ 9600 baud without any gaps.   Look at any of your USART transmissions.

^^ This 

Capture those messages on a scope, and check their duration.

9*(10/9600)/(1/4M) = 37500 sysclks   or 26.7ppm is the best precision you can get.

If you cannot map a timer capture onto the UART pin, a SW uart can do both RX and timing.

Using a uart interrupt alone to capture a timer, will be more coarse,  as the UART usually samples at 16x baud rate, so you have a granularity of  9*10*16  = 1440 steps in a packed string.  (694ppm)

That's ~1.25 seconds, so might be good enough ?

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

will send N chars @ 9600 baud without any gaps

It would be interesting to take a look, however the look has to be real good, since you need to resolve any variations in the realm of 1 in 18000 total.  

As stated, you can set a scope marker at the very beginning & very end & see how much variation you get, again to 1 part in 18000 (but hard to visually see).  It's prob much easier to just set a counter in the avr & spit out the count totals (from begin to end) & see how steady they are.  That lets you know if there is reasonable hope to average them. 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sounds like a lot of work when there's simpler and cheaper alternatives - eg an ESP32 module will do bluetooth and wifi and has a crystal oscillator, so no timing issues. It would even serve a web page so the customer doesn't need to download an app. Even cheaper if you want to forgo bluetooth is the esp8266.

 

The electrical safety of the board does seem a little suspect at first glance.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:

Not that I've ever had a massage in any form but I can't help thinking that the last thing you might be doing during such a thing was running a stopwatch to ensure you were getting your money's worth to the exact second??

 

I could see it as a problem with the Department of Weights and Measures (or whatever it's called, in your country(/state/planet).  E.g. the guys that make sure your gas pump pumps out exactly 5 gallons(/litres/hogsheads) when it says it has, or that a 1 pound(/kg/ton) sack of flour contains exactly one...  They could well be very persnickety that if you paid for a 5 minute massage, you get exactly 300 seconds of massage.  Dunno if their timing equipment is good to 0.1 seconds, though.  indecision  S.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:
The electrical safety of the board does seem a little suspect at first glance.

Indeed - Hence my "Electric Chair" comment previously.

Pages