Tuesday, 27 October 2015

microcontroller - Maximum attainable delay with Micro controller


I am designing a microcontroller based delay circuit to implement delays of 2 hours, 1 hour, 45 minutes, and 30 minutes. The circuit will automatically turn on off a relay after this time period has elapsed.


I am stuck with a narrow selection of microcontrollers available locally in market:



  • 89C51

  • 89C52

  • 89S51

  • 89S52

  • 89C2051


  • PIC 16C71

  • PIC 16F84


I have checked the datasheets of these microcontrollers but there is no information about the maximum delay they can produce.


What is the maximum delay that can be produced with these microcontrollers?



Answer



The delay can be as long as you want. If a timer won't give you the delay you need, simply increment a register, or several registers, each time it overflows. Here is a simple program using Timer0 that illustrates the technique:


        #include    "P16F88.INC"

#define LED 0


errorlevel -302 ;suppress "not in bank 0" message

#define RB0 0
#define INIT_COUNT 0 ;gives (255 - 199) * 17.36 = 972 us between interrupts


cblock 0x20
tick_counter
temp

endc

;reset vector
org 0
nop
goto main

;interrupt vector
org 4
banksel INTCON

bcf INTCON,TMR0IF ;clear Timer0 interrupt flag
movlw 0x00 ;re-initialise count
movwf TMR0
decf tick_counter,f
retfie

main:
banksel OPTION_REG
movlw b'00000111' ;prescaler 1/128
movwf OPTION_REG ;giving 7.3728 Mz/128 = 57600 Hz (period = 17.36 us)

banksel TMR0
movlw 0x00 ;initialise timer count value
movwf TMR0
bsf INTCON,GIE ;enable global interrupt
bsf INTCON,TMR0IE ;enable Timer0 interrupt
banksel TRISB
bcf TRISB,LED ;RB0 is LED output
banksel 0

mainloop:

goto mainloop

bsf PORTB,LED
call dly
bcf PORTB,LED
call dly
goto mainloop

dly:
movlw 20

movwf tick_counter
dly1:
movf tick_counter,f
skpz
goto dly1
return

end

No comments:

Post a Comment

arduino - Can I use TI's cc2541 BLE as micro controller to perform operations/ processing instead of ATmega328P AU to save cost?

I am using arduino pro mini (which contains Atmega328p AU ) along with cc2541(HM-10) to process and transfer data over BLE to smartphone. I...