PDA

View Full Version : Timing in PICBasic Pro commands



freelancebee
- 9th September 2005, 17:02
Hi All:
Thank you for your threads and posts by reading
them I was able speed up process of learning PICs.
I could not find information about time intervals
or chart for specific statements or commands.
In applications where time is critical is best way
to calculate time needed for specific group of
PicBasic statements or group of assembler
statements or single command to avoid a mistakes.
In Visual Basic Timer function can be used
to record the starting and ending times
for a series of commands.
What kind of software tools I able to use
when compile program to calculate time
needed to run specific group of commands?
I appreciate your help.
Best Regards,
Leonid

Bruce
- 9th September 2005, 18:49
Use Timer1 something like this;


DEFINE OSC 20
DEFINE LOADER_USED 1

Symbol T1IF = PIR1.0 ' Timer1 TMR1IF overflow flag bit
SYMBOL TMR1ON = T1CON.0 ' Timer1 ON/OFF control bit
T1CON = 0 ' Prescaler = 1:1, Timer off
Cycles Var Word ' Holds Timer1 counts

Main:
TMR1H = 0
TMR1L = 0
T1IF = 0 ' Clear timer1 int flag
T1CON = 1 ' Start timer

' --- Insert PBP commands or groups to time below
' --- MAX time @ 20MHz = 65,536 x 200nS = 13.1072mS
' --- MAX time @ 4MHz = 65,536 * 1uS = 65.536mS
' --- with 1:1 prescale on TMR1.

serout2 0,16416,["ABC",13,10] ' Send 5 bytes at 19,200 bps

' ----------------------------------------
T1CON = 0 ' Stop Timer1
Cycles.lowbyte = TMR1L ' Get low byte
Cycles.highbyte = TMR1H ' Get high byte

' Display Time result
Hserout ["Timer1 Ticks = ",Dec Cycles,13,10]
IF T1IF THEN
HSEROUT ["TMR1 Over-flow, add 65,536 cycles to result",13,10]
T1IF = 0
ENDIF
PAUSE 1000

Here:
Goto Here ' Sit & spin after measurements

freelancebee
- 10th September 2005, 22:01
Hi Bruce:
Thank you for your time.
The code you wrote will really help.
Thank you again.
For some kind of tasks need 36 hours to complete production cycle.
During this working time cycle PIC has to work by changing output codes
depends from pre-programmed time intervals for example 90 minutes and
preprogrammed speed, temperature, or current=load and real conditions
on sensors.
Time=0
Start speed1, temperature1, or current=load1......
Time 90 min
Speed2, Temperature2, Current load 2......
Time 180
Speed3, Temperature3, Current load3.......
....
Time 2160 min = 36 hours
Stop
What is your suggestion or what kind solution for 36 hour cycle is real
and cheapest one:
- use external pre-programmed IC Timer on interrupt
- Use external EEPROM as counter and flag on interrupt
- use sources of PIC - EEPROM counter and flag on interrupt
Thank you again.
Best Regards,
Leonid

mister_e
- 10th September 2005, 23:47
Tons of different way i guess but one of my favourite is an external RTC like DS1307. You can even use an internal timer to do it too. OR depending what else your PIC do, do everything in a loop with a mix of PAUSE and incrementing few variables like secondes/minutes/hours/day/week/month/year

mister_e
- 11th September 2005, 00:50
and that thread should give you an easy to implement solution
http://www.picbasic.co.uk/forum/showthread.php?t=190