Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to make delay in Codevision for more than 16 bit counter for (8MHZ) clock?

Status
Not open for further replies.

Elnegm

Member level 1
Joined
Jun 28, 2005
Messages
33
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
1,524
Hi
I want to know the code does code vision make for thier dellay function in milisecond and microsecond ,Are they do it by timer or by loop and i need to know how to make delay in timer for time value larger than 16 bit counter for (8MHZ) clock
Thanks in advance
 

codevision watchdog timer

hi

The delay in codevision is made using the watchdog timer, so if you are using the watchdog timer - which is very recomended to use the WDT - the delay function will work fine but it will disable the watchdog timer. take care in using this function and it would be better to re-engineer your software to lessen the use of delay functions or preferably elliminate it at all. if you still need a delay function do your own delay function using any other timer than the watchdog timer. this brings us to the delay larger than the value of the 16-bit counter for the 8MHz clock that you have.

their are two potential solutions:
1) you configure your timer to issue an interrupt every well known time 1 or 5 seconds as your need, this means that you configure your timer to auto reload. and in the interrupt service routine you use a global variable to count the interrupts occurred, that is to increment the global variable in the ISR. So any where else in the program (may be in your long delay function) you can loop indefinetly waiting this variable to reach a certain value generating a delay that could reach 65535 times the time base of the auto-reload timer that you use, that if the global variable is a 16 bit variable.

2) the other solution is to use the application note from atmel

http://www.atmel.com/dyn/resources/prod_documents/doc1268.pdf

this application note enables you to generate long delays without using the CPU to handle the interrupts of the timer this will enable you to put the CPU in sleep mode if you are generating a log delay.

if you need any more help feel free to pm me

salam,
shereef
 

    Elnegm

    Points: 2
    Helpful Answer Positive Rating
watchdog timer codevision

When you compile, codevision creates an .ASM file

there you can see what is it doing
 

delay in codevision

Depending on the microcontroller clock frequency the CodeVision compiler uses the macros DELAY_USB (microseconds Byte) or DELAY_USW (microseconds Word) to obtain a delay of 1 microsecond. The function delay_ms includes references to the appropriate macro to obtain the delay in milliseconds. The function delay_ms automatically resets the watchdog timer every 1ms by generating the wdr instruction.

The following code has been generated for an ATmega16 and a clock frequency of 8 MHz. In this case to obtain a delay of 1 microsecond the macro _DELAY_USW is used:


.MACRO __DELAY_USB
LDI R24,LOW(@0)
__DELAY_USB_LOOP:
DEC R24
BRNE __DELAY_USB_LOOP
.ENDM

.MACRO __DELAY_USW
LDI R24,LOW(@0)
LDI R25,HIGH(@0)
__DELAY_USW_LOOP:
SBIW R24,1
BRNE __DELAY_USW_LOOP
.ENDM


_delay_ms:
ld r30,y+
ld r31,y+
adiw r30,0
breq __delay_ms1
__delay_ms0:
__DELAY_USW 0x7D0
wdr
sbiw r30,1
brne __delay_ms0
__delay_ms1:
ret
 

codevisionavr watch dog

correct me if i'm wrong but the wdr instruction is added by codevision to make sure "your" watchdog won't reset during these delays. It is'nt using it to generate any delays..
 

watchdog timercodevisionto use

Yes, you are right.
The wdr instruction is added by codevision to make sure "your" watchdog won't reset during these delays.
 

watch dog +codevision

**********
; Delays Library
;**********************************************************************
INCLUDE "p16F876A.inc"
ERRORLEVEL 0,-305,-302
;*******************************
; Imported Data
;*******************************
EXTERN W_TEMP , S_TEMP , DelayCount
;*******************************
; Exported Subs
;*******************************
GLOBAL DelayMSec , DelayUSec
;**********************************************************************
DelayCode CODE
;**********************************************************************
movlw B'00100000'
movwf STATUS
movlw B'11100000' ; Timer0 in Timer Mode Prescaler 1:2
movwf OPTION_REG
bsf PCLATH,3
bcf PCLATH,4
goto $
;*******************************
DelayUSec ; Delay of value W USeconds ( 4 < delay <256 )
;*******************************
NOP
NOP
NOP
NOP
addlw 0x0FB

sublw .254 ; 1 Inst = 1/5usec
nop
addlw 1
btfss STATUS, Z ; Delay Loop = 5 inst * 5/2 = 2u
goto $-3 ; Total Delay = W reg usec

nop
nop
NOP
NOP
NOP
NOP
return
;*******************************
DelayMSec ; Delay of value W in msecs
;*******************************
NOP
NOP
NOP
NOP

movwf DelayCount ; 1 Inst = 2/5usec
MSecLoop
movlw .250
call DelayUSec
movlw .250
call DelayUSec
movlw .250
call DelayUSec
movlw .250
call DelayUSec

clrwdt
decfsz DelayCount ; Total Delay = W reg msec
goto MSecLoop

NOP
NOP
NOP
NOP
return
;*******************************
end
;**********************************************************************
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top