View Full Version : assembly lang code help with timer interrupts
Hey
Im trying to write code to have a 2ms overflow so i can sample ecg waves at 500Hz i have hit a brick wall with this timer interrupt and any help would b greatly appreciated
Thanks
$MOD52
rd1 equ P0.0 ;Read signal P0.0
wr1 equ P0.1 ;Write signal P0.1
cs equ P0.2 ;Chip Select P0.2
intr equ P0.3 ;INTR signal P0.3
adc_port EQU P2 ;ADC data pins P2
adc_val EQU 30H ;ADC read value stored here
org 0H
start: ;Start of Program
acall conv ;Start ADC conversion
acall read ;Read converted value
mov P3,adc_val ;Move the value to Port 3
sjmp start ;Do it again
conv: ;Start of Conversion
clr cs ;Make CS low
clr wr1 ;Make WR1 Low
nop
setb wr1 ;Make WR High
setb cs ;Make CS high
wait:
jb intr,wait ;Wait for INTR signal
ret ;Conversion done
read: ;Read ADC value
clr cs ;Make CS Low
clr rd1 ;Make RD1 Low
mov a,adc_port ;Read the converted value
mov adc_val,a ;Store it in local variable
setb rd1 ;Make RD1 High
setb cs ;Make CS High
ret ;Reading done
END
It would appear that you are using an Intel 8051 family micro-controller. But that is just a guess since there is a lack of needed information in your post.
To get help, you need to supply some specific and detailed information. To start with -
What exact chip model.
What is connected to what (attaching an image or .pdf of your schematic would help.)
Explain what works, what you are trying to do, what does not work.
You are calling the input an interrupt, but it appears to be just a signal from an external source. Is it in fact the handshake from the ADC saying that the conversion is done?
You mention 2ms overflow. What exactly does that mean (I am an EE with about 30 years experience in microprocessor/micro-controller design and assembly language programming and that statement does not say anything.) Do you want to use a 2ms timer to trigger the ADC conversion? If so, you would need to configure one of the on-chip timers and then write code to wait for it in a loop (or use it as an interrupt input), then call your conv subroutine.
I cannot promise I will be able to specifically help, even after you post the necessary information. It has been a long time since I have used this chip. You would be better off finding a programming forum dedicated to the 8051, where currently active programmers could probably help you off of the top of their head.
But, no matter where you ask, you need to state what you current have and what you are trying to accomplish. Don't forget that we only see the information you supply in your post. While someone might be familiar with the chip and the programming language, without all the other details of what you are doing, they won't be able to help.
Hey.
Thanks for the reply
Basically the system i have is a ecg sensor i designed and built (the usual amplifiers and filters) this is connected to an ADC0804 (Analog Devices) from here it is interfaced to an 8051 (aduc831).
The ECG Sensor is constantly taking samples and what i want to do is have this code preform a conversion in the ADC every 2ms and show the results. I figured the way about doing this would be to set up a timer to overflow every2 ms. Im not sure if im right or not?
The code i posted works and downloads to the boardfine fine(no bugs etc) and gives samples however not at 500Hz.
For some reason it s not letting me attach a dig.
However if you look at the adc0804 s data sheet you can see that it has an external clock also which can be set to a specific frequency. should this be set to 500Hz too?
Thanks again for the reply and very grateful for any help
Hmm. You are apparently not using the ADC built into the aduc831?
Unless you are interested in saving power, there is no point in reducing the clock. The minimum is 100kHz anyway, which would give about 1500 samples per second, but the conversion time would go from 100uSec to 640uSec.
With the current code, where it loops waiting for the conversion to complete (as apposed to using an interrupt to signal when the conversion is complete) the time spent waiting in the loop is lost, so increasing that amount of time will mean that your main code will have less time to process/store/display the data (or what ever you would like it to do.)
Using one of the on chip timers in an auto-reload mode to generate an interrupt, which then uses your existing code to start the conversion is the correct way of doing this.
About the only other improvement would be to use the ADC INTR signal as an external interrupt. This would allow the "wait:" part of your "conv:" code to be eliminated (the conv code would just return from the interrupt back to your main code loop) and the interrupt from the ADC INTR signal would invoke your "read:" code.
vBulletin® v3.6.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.