PDA

View Full Version : please read it ( real time)



moud_man
- 12th September 2005, 09:24
hi all

i am not a beginner but something better i have used picbasic pro i found it well but

in my trip with the pic i was choosing between many compilers (and use it some time knowing their adv. and disadv.) and finally i started with pic basic pro it has more and more features

the problem is

i attend to do a clock project and i want more than 98% acc. before using picbasic pro i was using mplab with picc compiler it is great in the simulation and counting time (real time) elapsed so i can calc. the 1 sec interval before i burn the pic

when i was trying do that project with picbasic pro i made all of thing but stops at

KNOWING THE 1 SEC INTERVAL BEFORE BURNING

IS THERE ANYTHING TO KNOW THE REALTIME ? IS THAT IN THE ICD?

please support

thank you

bye

Melanie
- 12th September 2005, 10:12
Are your trying to work out a Second?

Pause 1000

There's a second, but not knowing what you are trying to do makes answering difficult. Calculating PICBasic instructions is NOT the way to go. Different instructions have differing execution times, and even then those times may vary according to other events.

There are several Timer threads on this forum (Olympic Timer is one example) if you did a search.

Bob_W
- 12th September 2005, 12:18
98% accuracy won't cut it for any clock project I'm aware of. That would mean an inaccuracy of around 2 seconds a minute. Take a look at this code http://www.picbasic.co.uk/forum/showthread.php?t=190 This allows you to time down to 1/100th of a second with whatever accuracy your timebase (crystal) is. This is a hardware solution using hardware counters / timers that are included with many PICs. Much easier, and more accurate than counting instructions.

moud_man
- 13th September 2005, 01:02
hi
1st thnx for repl.

>>>i already have seen that link before i post the thread and....

i embeded it in my project code of the real time clock but it wasnot a second

the display that appear in the 2 seven segmant changes (sometims one second and sometimes 1.5 second it is not steady in spead

i know that the code that the timer is embeded in may be the reasone

that is why i am asking my question is there any method to calculate the real time of simulation like mplab ide?

i mean if there a one i can reduce the 1 /100 frac. ti 1/99 to fast the sec unit and simulat untill i reach the desired value

i know that i can try by burning the chip and run the circuit in the real life every time a make a modification in the code to get the final value and the nearest acc. but..................


are not you see that it is a very very very hard method ???


thnx for ....

bye

Darrel Taylor
- 13th September 2005, 04:26
Whether it's Melanie's Olympic Timer, or my Elapsed Timer (wasn't specified). I can guarantee that if you are getting 1.5 second periods... the problem is in your program. Both Timer programs have been scrutinized thoroughly by many different people.

Unless you figure out what the problem is, this probably won't work either. However, this is the method you'll need to use, to measure exactly how long it takes to execute any block of PBP code.

instruction execution time
http://www.picbasic.co.uk/forum/showthread.php?s=&threadid=365
<br>

crematory
- 13th September 2005, 23:07
Hello

You can use one of maxim's real time clocks, the calculate sec,min,hour, day........

You can obtain an accuracy of 100% if you know how to use it well, also a nice feature is that you can use the built-in functions of I2C in PICBasic Pro to communicate with such RTCs.

I never have seen exact 1 sec displayed at exactly 1 sec duration, its some how 1 sec and 0.000034 some fractions...

So you better let the RTC calculate, and you control, its a nice idea, while you were thinking of a simple clock, you can do a full calender.

paul borgmeier
- 14th September 2005, 04:13
If you are interested in changing your approach, I posted some picbasic pro programs that can keep time at +/- 2 seconds per day (no RTC required). These are in the “Code Examples” Section at:

(Easy and Accurate Clocks without RTC IC)
http://www.picbasic.co.uk/forum/showthread.php?t=2129.

Both programs require a 4.000MHz Crystal, use TMRO, but do not require preloading counters. The programs are short as well. Good Luck.

Paul Borgmeier
Salt Lake City, Utah
USA

moud_man
- 15th September 2005, 11:59
hi all

i know that you arenot understanding me but all of your words are very usefull to me .

the missunderstanding is that i am building a clock project (you know, if i am building any other project i wouldnot need the time acc. ) that need a very high acc. that is it. ok!

i will upload to you my project code so you can really understand me, there are notes On it :

1-i am putting the Elapsed Timer,this code will calculate a very accurate 1 sec every a 100 ticks ***BUT THAT IS THE CASE IF THE ELAPSED TIMER CODE IS ALONE IN THE PROJECT****
2-the pic is driving a tow seven segment (if you want to build) and rotate the display around the tow seven segmant by porta.0 and porta.1 that is the main project code.
3-the dispaly is updated every one sec. of the ELAPSED TIMER CODE
4-the 2 seven segment is in the inverted mode that why i am putting 255-()
my observation is:

the display of the 2 seven segment is very well the problem is that there are some seconds that the project updates the display for more that 1 sec. and as the number increase the period of the sec. become shorter near to the actual one THe most long period of second is from 0 to 1 like (20 > 21)i donot know why?
No, i almost know, that instant is in the conditioning code of the program and it take more instruction cycles to excute is that correct?
if yes and i hope that it is the case what is the sol.

i had an idea i tryied to insert a condion "if " (like in the transition from 0 to 1 as i mentioned ) and will not do some thing like if d1= 100 then d1= d1 ,but it
doesnot work why again?
i want the soluion by editing the code and send it to me back or any thing ....

i am in the begining of the project in the issue of second i want to proceed in it to the hours but that problem is blocking me from that but it is the most important one, it is the base of the project


THE TIME

Darrel Taylor
- 16th September 2005, 16:38
moud_man,

Although your program is doing things it doesn't need to be doing. There's nothing in there that would cause the described problem. The instructions there will execute in only a few microseconds, and there won't be a problem of not having enough time to make it through the loop.

So let's look at the hardware instead.

Are you using transistors to drive the commons of the LED's? The PIC output's can only source 25ma. It takes more than that to drive a seven segment LED.

Are you using one of those Proto-Boards with a thousand holes that you just plug stuff into? If yes, where are the crystal and capacitors located? Are they very close to the chip? Long wires to the crystal will cause unstable frequencies. Especially if they are right next to high current outputs such as you are using on PORTA.0. The more segments that are lit, the more interferance you would see.

What kind of power supply are you using. Is it capable of providing at least 150ma while still maintaining +5V?

Now, back to the program. The Elapsed Timer keeps track of the seconds, minutes, hours, and days. There's no need for the Update: routine to try to count it again. Just use the variables that are already there. Hint: DIG.


***BUT THAT IS THE CASE IF THE ELAPSED TIMER CODE IS ALONE IN THE PROJECT****That is incorrect. I currently have the Elapsed Timer running in 3 different commercial products with many other things going on at the same time.
<br>

moud_man
- 19th September 2005, 12:17
hi

sorry for delay that is because of my prescaler is asigned to 256 ('_')

well i will give you my answers and give you some ques (ques. ans.)


1- ques. what is the things that my program is doing and it doesn't need to do?
2- ans. i donot use a transistor to drive the 7-segmant i am using direct pluging from the pic , the 7.s is a common cathods that the pic sink current from it by a 1k ohm resistor.
3- ans. yes i am using one of those Proto-Boards with a thousand holes that i just plug stuff into,and the cristal is very close to the chip .

4- ans. i am using 7805 regulator
5 - ques. i dont understand what you mean with that no need for the update function? your variables canot be used because i am using tow seven segmant every one has a 1 variable controling it (d1, d2) if you know a method to extract those from your variable "Seconds" plz tell me

waiting to answers

thnx for repl.
bye for now

Darrel Taylor
- 19th September 2005, 18:24
(1,5) I guess the Hint didn't work. You can use the DIG function to extract the individual digits.
<pre> d1 = Seconds DIG 0<br> d2 = Seconds DIG 1</pre>Then you don't need to re-count everything.

(2) For common cathode 7 segment displays, you should have seven resistors, 1 to each Anode, around 270-330 ohms. The cathodes should have an NPN transistor (1 per digit) with a 10K resistor going from the PIC (PORTA.0 and PORTA.1) to the BASE of the transitors. Emitters connect to ground, and Collectors go to the cathodes.

The transistor will invert the signal, so instead of putting a LOW on the pin to turn on a digit, you would make it high.

(3) OK, the crystal is close to the chip. Good. What about the capacitors? No long wires?

(4) 7805 is OK, do you have good sized caps for filtering? And more important, do you have 0.1uF capacitor between +5V and GND? Close to the chip? For decoupling.
<br>
P.S. "my prescaler is asigned to 256 ('_')", good one :)

moud_man
- 20th September 2005, 14:38
now i understanded the HINT

what amazing (dig ) function do it is very very helpfull in my case

you know

with your code and your hint i can update my project before i completely build it !!!!!!!!! that is the truth

frist of all thank you for help

---------------------->
1- i donot have any capacitor in the power circuit.
2-i am using a 2 capacitor with the crystal.
3-the desister!!!

i cannot know really what type of 7 segmant i am using common(cathod or anode)

but the common line must kept high and the other terminal i will give it low to power the segmant assocciated that is it,,, what type is it? common cathod or
anode?


till now i didnot modify my code with the amazing (DIG) function but i will try it now


thnx a lot for help i will update the result sooooooooooooooooooooooooooon wait for me


bye for now