![]() |
![]() |
![]() |
|
|
|||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
|
|
Thread Tools | Display Modes |
|
|
(permalink) |
|
Peace to all,
How do we implement it in assembly? Say I want to jump if Accumulator is greater than 27D? Is there a fool-proof way of doing it? At the moment I am checking the Accumalator say for 28D, and when it reaches it I jump, this is using CJNE. But its not giving me a reliable result as it may not be passing 28D due to other cycles being spent before the accululator being checked using CJNE so the 28D value may not be there when the CJNE instruction is being executed (though I have tried to implement ways to ensure 28D is reached on the CJNE instruction). So is there a proper way to do it? ie. where whatever the value of Accumulator is, as long as it is greater than 28D, it will jump. Suppose it is 35D, it will jump... Many thanks for your help. This message board has been a great help! Last edited by AceOfHearts; 16th July 2007 at 06:03 PM. |
|
|
|
|
|
|
(permalink) |
|
Perhaps you might try mentioning the processor you're using? - if it was a PIC (which it isn't) the PICList has plenty of details.
|
|
|
|
|
|
|
(permalink) | |
|
Quote:
Appologies, it is an 8051. Many thanks. |
||
|
|
|
|
|
(permalink) |
|
Are you using this method of comparison?
Code:
CJNE A, #27, NOT_EQ EQ: ;A=27 SJMP END_CMP NOT_EQ: JC A_LESS A_GREATER: ;A > 27 SJMP END_CMP A_LESS: ;A < 27 END_CMP: ;Finished
__________________
"There is no way to peace, peace is the way!" Last edited by kinjalgp; 16th July 2007 at 10:59 PM. |
|
|
|
|
|
|
(permalink) | |
|
Quote:
http://www.atmel.com/dyn/resources/p...ts/doc0509.pdf Good Hunting PS I knew which processor you were talking about. CJNE is kinda unique, and some of us are fortunate to know more than one processor family. Last edited by Papabravo; 17th July 2007 at 11:15 AM. |
||
|
|
|
|
|
(permalink) |
|
kinjalgp, I was not monitoring the carry flag at all.
papabravo, thanks for this method. This sounds like it will work! Many thanks. |
|
|
|
|
|
|
(permalink) |
|
Small detail, don't forget to clear the carry flag before your subb instruction otherwise you will end up with a bug.
Sometimes it work because the carry was cleared by previous instructions Sometimes it won't work because the carry was set by previous instructions |
|
|
|
|
|
|
(permalink) |
|
Many thanks.
I am actually programming an 8051 for an ultrasonic rangefinder (SRF05) and trying to use this method to ascertain if the signal from the device has been on for a certain period of time (the length of this signal tells us the range). Basically above a certain time period, object is out of range. And when within this time period, it is within range. So far, I have not got it to work as I want! |
|
|
|
|
|
|
(permalink) | |
|
Quote:
__________________
"There is no way to peace, peace is the way!" |
||
|
|
|
|
|
(permalink) | |
|
Quote:
or this one: http://instruct1.cit.cornell.edu/cou...7/jjl49_mar97/ Should be the starting point of every US porject How do you generate the US burst? |
||
|
|
|
|
|
(permalink) | |
|
mcs51mc,
SRF05 sends out 8 cycles of U.S. bursts upon a trigger. So all I do is triffer the relevant pin SRF05. kinjalgp, I dont have an oscilloscope so I cant test whats going on at the hardware level. At the moment, when I download the program and connect it up on the breadboard, The object detected and object not detected LEDs come on and off randomly regardless of distance of an object in fron of the sensor. Sometimes I notice some consistancy, but it is pretty random most of the time. If I keep an object at close range without moving it, the LEDs keep switching. Here is the code: Quote:
Last edited by AceOfHearts; 20th July 2007 at 04:00 PM. |
||
|
|
|
|
|
(permalink) | |
|
Quote:
I think your idea is to stay here as long P0.0 is high so you should jump to "REMAIN1" not "REMAIN". In the mean time T0 is counting 1ms intervals (if you have a 12MHz xtal). What happens after that line is complete unclear to me. According to what I read in the SRF05 spec, you should divide the measured time by 58 to get distance in cm. Where is your division? Unless you just want to know if the US see something and check for 30ms time-out of the SRF05 Explain your DELAY_FIFTY: routine |
||
|
|
|
|
|
(permalink) | |
|
Quote:
I am not looking to measure any distance numerically to any precision. All I want to do is detect if something is there at close range (at roughly any distance at first) and turn on P1.0 and P1.1 pff if anything is detected, and vice versa if nothing is detected. If I may run through the MONITOR bit with you... basically, P0.0 is measuring the echo pulse. At REMAIN1 it is checking to see if it still at logic 1, if it is, it jumps to REMAIN. Bear in mind Timer 0 is rolling all this time. At REMAIN, we transfer TL0 into R5. BTW, the CJNE instruction there is commented out and it not part of the code. We then subtract R5 (which has the the Timer value) from the accumulator which has the decimal 100 in it. At the beginning , 100 minus R5 will give ninety-something as the timer had just started. Carry flag will not be sat. We check to see if carry is not set, if it is not set, we jump back to REMAIN1 to check if P0.0 is still at logic 1. if it is, we again jump to REMAIN and minus the timer value from the accumulator. This time, the timer will have an even larger value, hence the accumulator will decrease by more in this go...if after several cycles of P0.0 being at logic 1 and performing this routine, the accumulator reaches below zero, carry flag is set and detected. It means P0.0 has stayed on for too long and so no object has been detected. P1.1 will be set and P1.0 is cleared. If P0.0 is detected as low before the the carry flag is detected, it means there is an object there and P1.0 is set and P1.1 is cleared. I expect the lights to remain constant when a object is fixed in front of the sensors, but they keep alternating; as if the objects kep moving randomly - in and out of range. About the DELAY_FIFTY, it is not actually delaying for 50 milliseconds, but much longer. This is so that I could see the SFR06 LED flash...I dont have an osciloscope; I wanted to make sure everything happened before I trigger the next one, just until I get it working. Thanks. Last edited by AceOfHearts; 23rd July 2007 at 08:47 PM. |
||
|
|
|
|
|
(permalink) |
|
Basicly you just want to know if there's something in front of the SRF05. You must drop the "close range" in you first sentence because the SRF05 detects over the complete range (not found in datasheet(?) of SRF05
Now I understood your algorithm. But it's too complicated to only detect presence/absence of object Some problems in you code: 1) 100-TL0 is done only once, next time you pass the SUBB the acc still holds 100-TL0 from previous pass. 2) You have to clear the carry flag before the SUBB instruction What I would do: Code:
orl P0,#00000001b ;P0.0 is input mov TMOD, #01 ;Prepare T0 to time P0.0 mov TL0, #0 mov TH0, #0 jnb P0.0, $ ;Wait for +edge of echo pulse setb TR0 ;Echo pulse active, start timer jb P0.0, $ ;Wait for -edge of echo pulse clr TR0 ;end of echo pulse is stop timer mov a,TL0 ;Load LB timed value clr c subb a,#29 ;Time out SRF05 is 30ms jc ObjectDetected clr P1.0 ;No object: led off jmp AGAIN ObjectDetected: setb P1.0 ;Object: set led on jmp AGAIN To evaluate it you can use the CJNE instruction in combination with the carry flag. That you will have greather, equal and less situations. Put each one on a different output led and see what happen... This code can easily be modified to calculate the distance to the object. Please notice that I didn't check that code with the assembler, just typed it while I was thinking, so a typo is always possible |
|
|
|
|
|
|
(permalink) |
|
Hi there,
thanks for the code...I really appreciate it. I am going to look at it further to see how I can adapt it to what I need. But very quickly, the problem I see is that as I am using a crystal of 11.0592MHZ, each cycle is 1.085uS, so for 30ms, I will need 30ms/1.085uS = 27650 cycles which LB of T0 will not represent 2^8=256. I think I can use HB of T0...(2^16) - (2^8) = 65280 max.; lowest value on HB would be 256, next highest 512 etc. Thanks again. Last edited by AceOfHearts; 25th July 2007 at 01:58 PM. |
|
|
|
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Latest |
| Need help with Intel Assembly Language and PIC16F877 | avinsinanan | Micro Controllers | 10 | 4th March 2008 10:02 AM |
| Need some help with a code provided by ATMEL | ikalogic | Micro Controllers | 1 | 23rd January 2007 02:45 PM |
| Assembly? | Marks256 | Micro Controllers | 43 | 28th July 2006 03:44 PM |
| Learning Assembly Programming Language | Johnson777717 | Micro Controllers | 4 | 22nd March 2004 02:00 PM |
| Assembly Language Question | Jeggyman | General Electronics Chat | 6 | 30th January 2004 09:53 PM |