The Philippine Electronics and Technology Forum
May 17, 2012, 06:38:44 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Search Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: Delay in Z8 encore  (Read 1281 times)
bryanleo
LR44 Battery
*

Pogi/Ganda Points: 0
Offline Offline

Posts: 4


« on: September 27, 2008, 12:35:25 AM »

Hi

How do you incorporate delay?

And how is the delay_milliseconds() used? <-- will this be enough?

The reason, I'm asking this is that my MCU is polling a multiplexer. I wanted to incorporate a delay so that it would read data slower so that I can transmit data slower as well.

Thanks,
Bryan
Logged
The Philippine Electronics and Technology Forum
« on: September 27, 2008, 12:35:25 AM »

 Logged
mArKhAo
Gas Turbine
**

Pogi/Ganda Points: 69
Offline Offline

Gender: Male
Posts: 2278


point and shoot


« Reply #1 on: September 27, 2008, 12:36:57 AM »

hehe. si sir.paranz ang makakasagot nyan. Cheesy
Logged

cut my heart out, for a souvenir....
The Philippine Electronics and Technology Forum
« Reply #1 on: September 27, 2008, 12:36:57 AM »

 Logged
paranz
Moderator
Nuclear Reactor
*****

Pogi/Ganda Points: 171
Offline Offline

Gender: Male
Posts: 4512


1/4W resistor specialist


« Reply #2 on: September 27, 2008, 09:48:30 AM »

you can use a software delay, which is not accurate.

Code:
void delay(void)
{
     int i;
     for(i=0;i<0xFFFF;i++)
            ;                                //do nothing
}

the problem above is that the exact amount delay is difficult to set (by trial and error?). Just try changing 0xFFFF to any value you deem acceptable

Or you can use the Timer module (hardware-based delay) in the mcu. The 40-pin Z8 encore have 3 Timers, you can use one of these initialized in ONE-SHOT MODE. In ONE-SHOT mode, the Timer will overflow only once. This is an accurate hardware-based delay.

Logged
The Philippine Electronics and Technology Forum
« Reply #2 on: September 27, 2008, 09:48:30 AM »

 Logged
bryanleo
LR44 Battery
*

Pogi/Ganda Points: 0
Offline Offline

Posts: 4


« Reply #3 on: September 27, 2008, 11:51:09 AM »

Thanks a lot!  Grin
I will try this out later.


By the way, what is the rough estimate in seconds of the delay of the 0xFFFF value?
Can the delay be extended by adding another loop inside the for loop like....

void delay(void)
{
   int i,j;
   for(i=0;i<=0xFFFF;i++)
      for(j=0;j<=0xFFFF;j++)
         ; //do nothing
}
Logged
beginner wan
Diesel Generator
*

Pogi/Ganda Points: 46
Offline Offline

Gender: Male
Posts: 1454


Think Positive! Matutupad yang dream mo!


WWW
« Reply #4 on: September 27, 2008, 12:11:39 PM »

pwede po yan.. pero mas maganda ata kung tatawagin mo nalang yung delay function na dalawang beses..

like..

{.....
  delay();
  delay();
  ...
}

at least, pwede ka magdelay ng mas mabilis.. Cheesy
Logged

i;0.?QrEpM?4DEZZ]bkH{w@F<38.Jq@92Ds3KPQj60?EA7U\3M<A84J|AI.H
R@>&?Ej,@;5H)o::7KE/:?QcXf?gX'39=,Z_Q[eYXc
paranz
Moderator
Nuclear Reactor
*****

Pogi/Ganda Points: 171
Offline Offline

Gender: Male
Posts: 4512


1/4W resistor specialist


« Reply #5 on: September 27, 2008, 01:01:18 PM »

yup tama po kayong dalawa  Wink
Logged
mochini77
Size AA Battery
****

Pogi/Ganda Points: 5
Offline Offline

Gender: Male
Posts: 136


The only thing that is permanent is change.


WWW
« Reply #6 on: September 29, 2008, 02:51:15 PM »

You can also try to use the sample code below to introduce a specific time delay in your application.
Take note that it uses timer interrupt which depends on your clock frequency.

You just need to call Delayms (x) where x is in milliseconds.
e.i.
     Delayms (100);

Code:
#include <ez8.h>

/* Function Prototypes and Definitions */
#define SET 1
#define RESET 0

void Init_Timer0(void );
void Delayms (unsigned int milliseconds);

unsigned char  Millisecond_50=RESET;
static unsigned int s_Ticks,s_Current_Milliseconds; /* Used by delayms() & isr_timer0() */

void Init_Timer0(void)
{
     T0H = 0x00; /* Start value = 0 */
     T0L = 0x00;
     T0RH = 0x4E; /* 1ms reload counter with 20MHz system clock */
     T0RL = 0x00;
     T0CTL = 0x01; /* Continuous mode; clock divide by 1 */
     IRQ0ENH |= 0x20; /* Timer 0 has normal priority */
     IRQ0ENL |= 0x20;
}

/*  Interrupt service routine for Timer0 */
#pragma interrupt
void isr_Timer0(void)
{
     SET_VECTOR(TIMER0,isr_Timer0);
     s_Ticks++; /* at every 1ms increment counter */
     if(s_Ticks==50)
     {
          Millisecond_50=SET; /* Set flag on 50ms timeout */
          s_Ticks=0; /* Reset counter */
     }
     s_Current_Milliseconds++ ; /* counter used for Delayms() funciton */
}

/* This function provides delay in milliseconds */
/* milliseconds Delay duration in milliseconds  */
void Delayms (unsigned int milliseconds)
{
     s_Current_Milliseconds = 0;
     T0CTL &= 0x7F; /* Disable Timer0 */
     T0H = 0x00 ; /* Restart from 0 */
     T0L = 0x00 ;
     T0CTL |= 0x80 ; /* Put On Timer0 */
     while (s_Current_Milliseconds < milliseconds); /* wait till specified timeout occurs */
}
Logged

bryanleo
LR44 Battery
*

Pogi/Ganda Points: 0
Offline Offline

Posts: 4


« Reply #7 on: September 29, 2008, 07:42:12 PM »

Salamat sa inyong lahat! Smiley geleng
Logged
'yus
Technical People
Nuclear Reactor
*****

Pogi/Ganda Points: 289
Offline Offline

Gender: Male
Posts: 4199


oops, kernel panic!


WWW
« Reply #8 on: March 22, 2009, 07:11:04 PM »

meron bang timer calculator for zilog? Huh
Logged

join PhilRobotics - Philippine Electronics and Robotics Enthusiasts Club
paranz
Moderator
Nuclear Reactor
*****

Pogi/Ganda Points: 171
Offline Offline

Gender: Male
Posts: 4512


1/4W resistor specialist


« Reply #9 on: March 22, 2009, 07:51:39 PM »

^ wala. Hand calculation lang ang gamit for using hardware timers
Logged
SpongeBob
Lead Acid Battery
*******

Pogi/Ganda Points: 33
Offline Offline

Posts: 660


« Reply #10 on: March 23, 2009, 12:01:17 PM »

kung ano value ng reload at prescaler yun ang delay

Time-Out Period = (Reload Value x Prescaler Value) / System Clock Frequency (Hz)
Logged
'yus
Technical People
Nuclear Reactor
*****

Pogi/Ganda Points: 289
Offline Offline

Gender: Male
Posts: 4199


oops, kernel panic!


WWW
« Reply #11 on: April 08, 2009, 05:11:40 PM »

galing sa "Z8 Encore XP F0823 Series Product Specification"
Quote
Table 101. Oscillator Configuration and Selection
Clock Source:
Internal Precision
RC Oscillator

Characteristics:
 • 32.8 kHz or 5.53 MHz
 • ± 4% accuracy when trimmed
 • No external components required
 • Unlock and write Oscillator Control

Required Setup:
Register (OSCCTL) to enable and
select oscillator at either 5.53 MHz or
32.8 kHz
kanina ko lang nabasa.. 4% accuracy pala.. Undecided  Cry


EDIT: magkaiba nga pala ang definition ng "Precision" saka ng "Accuracy" Cheesy hehe
Logged

join PhilRobotics - Philippine Electronics and Robotics Enthusiasts Club
piona
Hydroelectric
***

Pogi/Ganda Points: 118
Offline Offline

Posts: 3072


earth - evils = heaven


« Reply #12 on: April 08, 2009, 06:40:07 PM »

yah tama ka Yus, +/-4% accurate siya sa designed freq, at stable naman ang freq niya......siguro sa range ng operating temp. niya
Logged

love without accomplishing the laws, is complicated - sshrekk
The Philippine Electronics and Technology Forum
   

 Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  


Related Topics
Subject Started by Replies Views Last post
anu pa po ang ibang code sa turbo c na pedeng ipalit sa delay?
Microcontroller/Microprocessor Unit Projects and Programming
fran2no 0 476 Last post February 22, 2010, 10:52:05 PM
by fran2no
how to make an exact 1 second delay using TMR0?
PIC Microcontrollers
chimes27 4 606 Last post September 24, 2010, 11:02:02 AM
by chimes27
Delay using assembly
PIC Microcontrollers
doodleskram 0 92 Last post October 17, 2011, 09:05:36 PM
by doodleskram
VB.Net Multithreading SerialPort Communication DELAY
Absolute Beginner Technical Discussion
jedllenado 7 260 Last post January 17, 2012, 02:20:39 AM
by jedllenado
millis instead of delay question
Microcontroller/Microprocessor Unit Projects and Programming
gabajols 0 124 Last post February 07, 2012, 10:08:12 AM
by gabajols
increment decrement delay
Microcontroller/Microprocessor Unit Projects and Programming
martinanaya 4 217 Last post February 15, 2012, 04:21:28 PM
by gwapa
Should there be really a delay between UART-TX transmission?
Computer Interfacing and Digital Communications
marcelino 19 318 Last post March 26, 2012, 01:47:15 AM
by kmb36td
Powered by MySQL Powered by PHP Powered by SMF 1.1.15 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!