• AVR Freaks

remove a zero

Page: < 12345.. > >> Showing page 5 of 8
Author
kurt
Senior Member
  • Total Posts : 121
  • Reward points : 0
  • Joined: 2017/05/07 13:18:17
  • Location: 0
  • Status: offline
Re: remove a zero 2018/02/13 14:29:39 (permalink)
0
i've tried XT and HS  both with a 4mhz, crystal   on the crystal is written 4.000mhz . 
but in the data sheet i can not find that there is a failback to the internal oscillator 
 
how do i say it?
If you use an external oscillator of 4 mhz. and i use the interrupt function with an output to determine if the pic runs at the clock speed as specified does it always perfectly match.  Now for example if i do my calculations with clockspeed, prescaler etc interrupt has to occur every 0.256 but with my tools i measure 0.262.  this deviation is that also normal for external oscillator or can you just say that if you expect 0.256 with external oscillator you will get 0.256
#81
qɥb
Monolothic Member
  • Total Posts : 3332
  • Reward points : 0
  • Joined: 2017/09/09 05:07:30
  • Location: Jupiter
  • Status: offline
Re: remove a zero 2018/02/13 15:04:54 (permalink)
0
Yes, but only if your calculations are correct.

This forum is mis-configured so it only works correctly if you access it via https protocol.
The Microchip website links to it using http protocol. Will they ever catch on?
PicForum "it just works"
#82
1and0
Access is Denied
  • Total Posts : 11774
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: remove a zero 2018/02/13 15:27:45 (permalink)
0
Is your "tool" calibrated?
#83
dan1138
Super Member
  • Total Posts : 4173
  • Reward points : 0
  • Joined: 2007/02/21 23:04:16
  • Location: 0
  • Status: offline
Re: remove a zero 2018/02/13 15:44:02 (permalink)
0
I am beginning to wonder if the Original Poster can find the help needed on this forum.
 
The way the OP posts code without using code-tags makes the code hard to read.
 
Not posting complete code that builds makes it impossible to point out the common problems that confuse most developers new to the Microchip tools. I suspect that the configuration words are in the "header.h" file. If this is true then the OP can expect problems in future projects that have multiple ".c" files where each includes the "header.h" file.
 
The OP could provide some better feedback on the code from my post #42.
 
When kurt replies with "this is something totally.............." this seem to me not all that informative.
 
Perhaps the OP could just try the code an report what it does or fail to do in their hardware.
post edited by dan1138 - 2018/02/14 13:31:30
#84
Gort2015
Klaatu Barada Nikto
  • Total Posts : 4014
  • Reward points : 0
  • Joined: 2015/04/30 10:49:57
  • Location: 0
  • Status: offline
Re: remove a zero 2018/02/13 15:54:54 (permalink)
0
The internal oscillator has a 1% +/- deviation.
You can fine tune that with OSCTUNE.
 
Time can be hard to judge, do you have access to an atomic clock?
https://time.is/

MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
https://www.youtube.com/watch?v=Iu1qa8N2ID0
+ ST:Continues, "What Ships are Made for", Q's back.
#85
PStechPaul
Super Member
  • Total Posts : 2993
  • Reward points : 0
  • Joined: 2006/06/27 16:11:32
  • Location: Cockeysville, MD, USA
  • Status: offline
Re: remove a zero 2018/02/13 17:28:01 (permalink)
0
My Fluke 45 DMM has a frequency measurement accuracy of 0.05% + 1 count, up to 1 MHz.
 
A digital frequency/interval counter is usually much more accurate. Here is some information on how to use one properly: https://www.electronics-notes.com/articles/test-methods/frequency-counter-timer/how-to-use-frequency-counter-interval-timer.php
 
My HP5316A has a timebase accuracy of about 5 PPM.
https://www.mods.dk/manual.php?brand=hewlett_packard
 

 
#86
kurt
Senior Member
  • Total Posts : 121
  • Reward points : 0
  • Joined: 2017/05/07 13:18:17
  • Location: 0
  • Status: offline
Re: remove a zero 2018/02/14 12:32:47 (permalink)
0
my tool is a fluke 289 is brand new 
i'am also sure that my calculations are correct
 
#87
qɥb
Monolothic Member
  • Total Posts : 3332
  • Reward points : 0
  • Joined: 2017/09/09 05:07:30
  • Location: Jupiter
  • Status: offline
Re: remove a zero 2018/02/14 12:39:33 (permalink)
+2 (2)
 
kurt
..
i'am also sure that my calculations are correct

I wish I always knew I hadn't made a mistake. Have fun solving your problem, I'm out of here...

This forum is mis-configured so it only works correctly if you access it via https protocol.
The Microchip website links to it using http protocol. Will they ever catch on?
PicForum "it just works"
#88
dan1138
Super Member
  • Total Posts : 4173
  • Reward points : 0
  • Joined: 2007/02/21 23:04:16
  • Location: 0
  • Status: offline
Re: remove a zero 2018/02/14 13:45:30 (permalink)
+1 (1)
kurt
my tool is a fluke 289 is brand new 
i'am also sure that my calculations are correct

@Kurt,
 
Should you really seek help please post a link to a complete PIC18F2220 project that builds without warning or errors, that shows your implementation of the 7-segment LED display refresh and the ADC measurement.
 
If you do not have such a sample project then please try the code I posted in your hardware and report what it does.
 
If neither of these actions appeal to you then please continue in your present methods of replies. There are any number of members eager to bait troll here.
#89
Gort2015
Klaatu Barada Nikto
  • Total Posts : 4014
  • Reward points : 0
  • Joined: 2015/04/30 10:49:57
  • Location: 0
  • Status: offline
Re: remove a zero 2018/02/14 15:31:49 (permalink)
0
Post your calculations.
 
Sure or 100%?

MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
https://www.youtube.com/watch?v=Iu1qa8N2ID0
+ ST:Continues, "What Ships are Made for", Q's back.
#90
PStechPaul
Super Member
  • Total Posts : 2993
  • Reward points : 0
  • Joined: 2006/06/27 16:11:32
  • Location: Cockeysville, MD, USA
  • Status: offline
Re: remove a zero 2018/02/14 15:43:28 (permalink)
+1 (1)
One parting shot before I, too, bail on this. The Fluke 289 has a frequency accuracy of 0.005%, or 50 PPM, and the 5 digit display will show the clock frequency as 4.0000, which is +/- 0.0001, or an additional 25 PPM. So there is an uncertainty of 75 PPM, which is 6.5 seconds/day or 45 seconds per week.
 
http://en-us.fluke.com/pr...timeter.html#techspecs
 
Most watches are better than that, so a good way to measure frequency without a lab grade counter/timer is to start a stopwatch at the same time as you start clocking an unsigned long in the PIC, and then stop them both after 24 hours. You should be able to synchronize the start/stop within 100 mSec, so you can see timing error to 0.1/86400 = 1.2 PPM.

 
#91
kurt
Senior Member
  • Total Posts : 121
  • Reward points : 0
  • Joined: 2017/05/07 13:18:17
  • Location: 0
  • Status: offline
Re: remove a zero 2018/02/17 11:31:23 (permalink)
0
  my calculation goes like this
4 mhz = 4000000
4 cycles is one instruction
so  4000000/4 = 1000000 instructions/cycle
1000000/ (prescaler 256) / 3906.25   (t0  per second)
(adjustable prescaler (TOPS bits  for example 101)) = 64
3906.26 / 64 = 61.0351563 (times per second t0 will overflow)
1/61.0351563 = (t0 will overflow every) 0.016384 second
0.016384 /1000   = 16.384 ms    interrupt occur according to my calculation
 
in my interrupt i have this code: LATCbits.LATC7 ^= 1;
i connect my fluke 289 dmm to latc7 and i measure a duty cyle of 16.5ms 
i've created this calculation in excel so i can change it in a second for any other
'tops' bits setting without any calculation error. but every time thers's a little difference in between
my calculation and measurement. in my headerfile i've changed OSC to HS.
 
any tips how i can post my complete code
post edited by kurt - 2018/02/17 11:52:29
#92
PStechPaul
Super Member
  • Total Posts : 2993
  • Reward points : 0
  • Joined: 2006/06/27 16:11:32
  • Location: Cockeysville, MD, USA
  • Status: offline
Re: remove a zero 2018/02/17 12:37:23 (permalink)
0
[code ]Put code here[/code ] (remove spaces)
 
Is the difference between expected and measured greater than the specs for the Fluke 289? Have you tried tweaking the crystal capacitors?

 
#93
Gort2015
Klaatu Barada Nikto
  • Total Posts : 4014
  • Reward points : 0
  • Joined: 2015/04/30 10:49:57
  • Location: 0
  • Status: offline
Re: remove a zero 2018/02/17 15:21:58 (permalink)
0
Using floating points will lose accuracy.
Work with numbers that can be divided without any remainder.
 
If I wanted an interrupt every 5th of a second.
Different chip but same principle.
 
fcy = 40,000,000 Hertz, prescaler = 256
 
Inversion to get time:
MPUTIME: 1 / 40,000,000 * 256PS = 0.000,006,4 seconds
MYTIME:   1 / 5 = 0.2 seconds
 
Period = MYTIME / MPUTIME - 1 = 31,249
 
 
 

MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
https://www.youtube.com/watch?v=Iu1qa8N2ID0
+ ST:Continues, "What Ships are Made for", Q's back.
#94
kurt
Senior Member
  • Total Posts : 121
  • Reward points : 0
  • Joined: 2017/05/07 13:18:17
  • Location: 0
  • Status: offline
Re: remove a zero 2018/02/25 13:58:27 (permalink)
0
this weekend i did some study about the oscillator and i came to the conclusion that the difference i have between calculated and measured is because the inaccuracy of my measurement device. also i studied the data sheet and by setting the 'config1h' bit to HS i select external oscillator and if i remove the crystal during testing i noticed a difference in duty cylce of my interrupt service routine. but while writing this, i start to wonder, what would happen if i put an 8 mhz crystal in my project instead of 4mhz, my duty cylce would half ?.  and by setting 'config1h' to hs i can omit the osccon setting, right'
 
also i attached a picture of my project i guess you all wondered what it would look like
also i attached the code
 
give my your thoughts

Attachment(s)

Attachments are not available: Download requirements not met
#95
Gort2015
Klaatu Barada Nikto
  • Total Posts : 4014
  • Reward points : 0
  • Joined: 2015/04/30 10:49:57
  • Location: 0
  • Status: offline
Re: remove a zero 2018/02/25 14:26:42 (permalink)
0
I've just re-activated an external RTC.
It has not be used in around 8 months.
 
It was 6 seconds out.
I recken that I could improve on that.
 
Next time I'll set it by an atomic clock instead of the pc clock that I compared it with.
 
 

MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
https://www.youtube.com/watch?v=Iu1qa8N2ID0
+ ST:Continues, "What Ships are Made for", Q's back.
#96
kurt
Senior Member
  • Total Posts : 121
  • Reward points : 0
  • Joined: 2017/05/07 13:18:17
  • Location: 0
  • Status: offline
Re: remove a zero 2018/03/02 12:10:53 (permalink)
0
piece by piece i try to update my project and so i came to the conclusion that i need to use an average time calculation in my software,  underneath is the code i have so far i will put this in my interrupt service routine
only thing is, how do i get the measured value to measure1 and the next time the isr is triggerd to measure2
and the next time isr triggers to measure 3 ........to measure 4   and than start over to measure 1
 
 
{
measuredvalue??             // of this i need average 
temperature = (measure1 + measure2 + measure3 + measure4); // add up measured values 
averagetemp = (temperature <<2);   // devide by four
}
#97
Gort2015
Klaatu Barada Nikto
  • Total Posts : 4014
  • Reward points : 0
  • Joined: 2015/04/30 10:49:57
  • Location: 0
  • Status: offline
Re: remove a zero 2018/03/02 12:29:56 (permalink)
0
Try that:
volatile int avg;
 
INTERRUPT CODE:
 
static int cnt = 4 - 1, total = 0;
 
total += <reading>;
 
if(!--cnt){cnt = 4 - 1; avg = total << 2; total = 0;}

 
 

MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
https://www.youtube.com/watch?v=Iu1qa8N2ID0
+ ST:Continues, "What Ships are Made for", Q's back.
#98
kurt
Senior Member
  • Total Posts : 121
  • Reward points : 0
  • Joined: 2017/05/07 13:18:17
  • Location: 0
  • Status: offline
Re: remove a zero 2018/03/02 13:47:16 (permalink)
0
hey gort,  thanks  but can you explain each line what exactly happens
 
#99
qɥb
Monolothic Member
  • Total Posts : 3332
  • Reward points : 0
  • Joined: 2017/09/09 05:07:30
  • Location: Jupiter
  • Status: offline
Re: remove a zero 2018/03/02 14:24:50 (permalink)
0
kurt
averagetemp = (temperature <<2);   // devide by four

I think you will find that shifting left MULTIPLIES by four, not divides.
Don't try to be too cute. Just do a divide by 4 and the compiler will use a shift to do it...
averagetemp = (temperature / 4);   // divide by four

This forum is mis-configured so it only works correctly if you access it via https protocol.
The Microchip website links to it using http protocol. Will they ever catch on?
PicForum "it just works"
Page: < 12345.. > >> Showing page 5 of 8
Jump to:
© 2021 APG vNext Commercial Version 4.5