Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple counter and delay

Status
Not open for further replies.

vix

Programmer
Mar 28, 2002
11
0
0
GB
Hi,
I have never used assembly language before, but I have to write some code for a microcontroller and am a bit stuck - if anyone could help i'd really appreciate it!

The basic problem is, first, I have to write two delays that will last 10 microseconds and 10 milliseconds respectively. (My controller is running at 4 MegaHertz) then, I have to create a counter that will count from when a bit is set to when the bit is not set, am not really sure how to do this. For the delays, I think I would need to use DECFSZ but i'm not certain. Can anyone help please?

Vix
vicky.a.roberts@lycos.com
 
What is the chip manufacturer etc? Although assembly is simular between chips there can be quite fundamental differences in how the same task is acheived.

Usually, if you go to the manufacturer's web site you can download techinical specifications including the machine code operations. Reading this will give you an idea of what functions the chip performs, also this may give you a new approch to problem solving.

I take it you have an assembler for your microcontroller? If not try a search on which is always a good source of technical info.

0000:0000:0000:0000h
The people who have nothing to say and say it too loud have little knowledge, It's the quiet ones you need to worry about!
 
Mitsubishi & Toshiba microcontrollers have these functions built in.
The cycle time of chips is unreliable as a clock becuase it can change on each cycle depending on the current task. Use the clock pulse to increament your counters but make sure you use a pulse that is alot slower than the microcontroller cycle time or you may loose some pulses!
anyway, calculate how many pulses at 4mhz will take to 10msec. when the bit switch energises put this value into a register and decreament at each pulse. when the zero flag occurs the 10msec has elapsed and the delay can energise.

stopwatch:timed bit (a), bit switch (b) and result register (c)
if (a)=off then set (b)=off
if (a)=on and (b)=off then set (c)=zero, set (b)=on
if (a)=on and (b)=on and (clock pulse 4mhz)=on then increament (c) by 1

(c) will give you a run time counter as well as a timed event value. rescale using divide to give to msec etc.
straiph
0000:0000:0000:0000h
The people who have nothing to say and say it too loud have little knowledge, It's the quiet ones you need to worry about!
 
Thanks - it's a Microchip PIC16F62X, I have got the list of operations, but i'm not sure how to do the delay still. I think (if what I worked out is correct) that I will need 40 instructions to create a 10microsecond delay.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top