Problem with understanding a digital logic

1. pwrte

Hi,
I have the following options which sets/resets bits of a particular 14-bit word. Upon bitwise "AND"ing the selected options starting from initial all '1' value i.e 3FFF I get the final output word.

WDT: ENABLED = 3FFF
DISABLED = 3FFB

PWRTE: DISABLED = 3FFF
ENABLED = 3FF7

OSCLIIATOR: RC = 3FFF
HS = 3FFE
XT = 3FFD
LP = 3FFC

CODE PROTECT: DISABLED = 3FFF
ENABLED = 000F

Suppose selected options are
WDT= DISABLED (3FFB)
PWRTE = ENABLED (3FF7)
OSC. = LP (3FFC)
CP = DISABLED (3FFF)

Then the final word is (3FFF AND 3FFB AND 3FF7 AND 3FFC AND 3FFF) = 3FF0

My problem is suppose if I have word 3FF0 how do I find out which of the above options were selected? •

2. Re: Digital Logic Problem

Well CMOS, I can't really tell the difference between what you called "A: ENABLED", "B: DISABLED", "C: P", "D: DISABLED" and ("C: Q" and "C: R" or "C: S"), but if we name the bits of your 14-bits word as [W13..W0] (W13 MSB), you could test (logical AND with '1') the four least significant 4 bits of your final word (i.e. W3, W2, W1 and W0).
The combination of logical '0's you get would indicate the selected "options".
3FF0h --> [W3..W0]=0000, which means:
D disabled (because result > 0Fh);
B enabled (W3=0);
A disabled (W2=0);
C: R (W1=0);
C: Q (W0=0);
or
C: S (W1=0 and W0=0)
or I totally missed your question... •

3. Re: Digital Logic Problem

Hi
ENABLED, DISABLED are just the option names. These are bit values and could be named anything. I am concerned with the values of these options. I have edited my pervious post to make it more clear.

This is related to configuration word of PIC16F84A. It has 4 options to be selected by user in its config. word and depending on the selected options the config word is determined. In my last post ANDing hex values of selected options, you get the config. word.

Now I want to do the reverse of it. That is if config. word is given to me and I have the above given Hex values of each option, how do I determine which of the options are selected. I need to perform some logical operation between given config. word and each of the option value to determine whether it is selected or not. But I am not able to figure out which logical operation would reveal that!

I hope I am clear with my question this time. •

4. Re: Digital Logic Problem

Its very simple!
From ur data ...
Code:
WDT: ENABLED = 3FFF
DISABLED = 3FFB
This means bit 2 is for WDT it is 1 for WDT Enable
0 for WDT DISABLE
PWRTE: DISABLED = 3FFF
ENABLED = 3FF7
This means bit 3 is for PWRTE it is 1 for PWRTE Enable
0 for PWRTE DISABLE

OSCLIIATOR: RC = 3FFF
HS = 3FFE
XT = 3FFD
LP = 3FFC

This means bit 1 to 0 is for OSCILLATOR it is 11 for RC
10 for HS
01 for XT
00 for LP

CODE PROTECT: DISABLED = 3FFF
ENABLED = 000F
This means bit 13 to 4 is for CODE PROTECT it is 1111111111 for DISABLE
0000000000 for ENABLED
This explains...

Now Suppose I have register settings as 3FF2
This means CODE PROTECTION is ENABLED because bits 13 to 4 are all set to 1;
OSCILLATOR is set to HS because bits 1 to 0 are set to 10;
PWRTE is DISABLED because bit 3 is set to 0;
WDT is DISABLED beacuse bit 2 is set to 0; 5. Re: Digital Logic Problem

Hi nand_gates,
Looking at those options you can easily make out which bits indicate which settings. I am writing code to display configuration word settings. And my problem is that after reading the configuration word from PIC, I need to dissect it into four of the above listed options and display it. And I need to do this only by using the value of configuration word and the individual values of the above options that I have. I cannot hard-code any bit numbers because these options are different for other PICs.

So what logical operation between configuration word and option values will reveal the selected option? 6. Re: Digital Logic Problem

Not sure I fully understand the question but

If CONFIG AND 0003 = 0 then OSC is LP
If CONFIG AND 0003 = 1 then OSC is XT
If CONFIG AND 0003 = 2 then OSC is HS
If CONFIG AND 0003 = 3 then OSC is RC

If CONFIG AND 0004 <>0 then WDT is active otherwise WDT inactive.

If CONFIG AND 0008 <>0 then PWRTE is active otherwise PWRTE inactive.

If CONFIG AND 3FF0 <>0 then CODE PROTECT is inactive otherwise active.

1 members found this post helpful. 7. Re: Digital Logic Problem

Hi Colbhaidh,
Thats exactly what I wanted. First I have to invert option values and then AND with config. word. If I get non-zero result that means that option is selected.

But there is one problem. I get 3 non-zero result while checking for oscillator option. IS there any way you can think of which will give me only one non-zero result for the selected option and zero for all others. That will make my coding work a bit easy.

Thanks for the help! •

8. Re: Digital Logic Problem

You basically need a bit mask that contains 1's for all the bits of interest.

Since the oscillator option is encoded in bits 0 and 1, the bit mask will contain 1's in those positions. (= 0003) ANDing the bit mask will extract the option bits, leaving the other bits 0.

Inverting the option with value 0, will produce the bit mask with extra 1's in don't-care bit positions. --[[ ]]--