PIC compare problem (assembler)

Hi all

I have a small problem and I need a hint

Basically I read an ADC value and read it out on 16 LEDs. It also has a minimum value, but if min == current value then the minimum value is not displayed. Currently the min value is hardcoded to 2-3 less than the current. It simply uses the ADC value and there are now 3 DECF to get a min value.

Still, this acts funny:

; min only when it is not the actual value MOVF ADC_RESULT, W SUBWF MIN_DISP, W BTFSC STATUS, Z GOTO _not_mode_2 ; here I show the min value

If my ADC result is 9 or more, then it works. Currently my min value will be 7 by default (7 and 9), and when ADC=9 it works, but when ADC=8 then it does not set the Z flag. When using 9 and 6 the same occurs. ADC must be 9 or more for the Z flag to be set. My readings work in all ways except this weird card. 9 is when the upper part is in use, so I wonder what happen if the current and min are in the same part/port

If I comment the bit check and goto out, then it works, and shows the min value just as expected.

But I cannot see the difference between 8 and 9.

What am I not seeing here?

WBR Sonnich

Reply to
Sonnich Jensen
Loading thread data ...

I don't know, SUBWF should always set the zero flag based on the result of MIN_DISP - ADC_RESULT.

Suggest you use the MPLAB simulator and step through it to see what's going on.

Best regards,

--
Best regards,  
Spehro Pefhany 
Amazon link for AoE 3rd Edition:            http://tinyurl.com/ntrpwu8 
Microchip link for 2015 Masters in Phoenix: http://tinyurl.com/l7g2k48
Reply to
Spehro Pefhany

If all else fails try manually dis-assembling the btfsc status,z opcode just in case the assembler z definition got scrambled and it is actually testing the dc flag. Just a crazy idea born of experience.

piglet

Reply to
piglet

I think you need to check the C and DC flags as well. The SUBWF will give you a negative result as well as zero. Like

Reply to
Martin Riddle

On a sunny day (Tue, 12 May 2015 12:43:31 -0700 (PDT)) it happened Sonnich Jensen wrote in :

I never use the ADCs with 8 bit compare, as the output is 10 bits on my PICs. Without looking deeper, that pops up the question if your result is properly right aligned (see ADC init) and if you are not overflowing the lower 8 bits.

So what happens if you do this?

#define ADC_RESULT D'7' movlw D'7'

SUBWF MIN_DISP, W BTFSC STATUS, Z goto no

call say_yes ; or bsf test_port, 1, or something like that, and remember to test your test port TRIS etc blah blah. return

no: call say_no ; or bcf test_port, 1 LED? return

Hey I will have to write some PIC18 asm today... so this is the warm up.

F*ck do not even have the hardware yet. MPlab? You guys must be kidding.

I was reading in the news a while ago an about 9 year in Germany old took his fathers car and drove it into the city. Did not get very far before he crashed. He told the police he trained on his PC simulator, whats that game?

Never mind, I tried it in a F100 super sabre. And with the car too of course.

So, in C, if(kid < 10) say_no else say_yes?

nuf I think.

Reply to
Jan Panteltje

If the minimum value is 9, then the Z flag will only be set when the ADC value is 9. That's its function - it tells you the result of subtracting one from the other is zero.

Sylvia.

Reply to
Sylvia Else

On a sunny day (Wed, 13 May 2015 16:26:52 +1000) it happened Sylvia Else wrote in :

He talks about '==' meaning equal. in that case using the Z flag is correct.

Maybe he cannot formulate his problem?

When you can formulate the problem, then writing the code is easy. In the other case you can write code forever and it will never be right. :-)

Reply to
Jan Panteltje

You need to check for the C flag (carry).

When Min_value becomes more than ADC sample value then C will be set, otherwise, all results from 0 and up are ok.. If you do detect a C flag setting, then simply set the final results to 0 if you are not dealing with +/- values

Also, remember to clear the C flag prior to this operation because using the wrong math instructions can lead to random C flags being used in the process from some other point of code and throwing your results off by +/- 1

Jamie

Reply to
M Philbrook

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.