Searching \ for '[PIC] need to shave off half an instruction' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/devices.htm?key=pic
Search entire site for: 'need to shave off half an instruction'.

Exact match. Not showing close matches.
PICList Thread
'[PIC] need to shave off half an instruction'
2012\01\15@002301 by Bob Blick

face
flavicon
face
I have an existing small PIC project that produces an output on one pin
based on the high bit of a register. In order to save an external
inverter, I'd like to also output the complement on another pin. For the
sake of argument let's say it is an oscillator that blinks an LED or
drives a transducer.

The target is a 16F627A and any pins are fair game, but glitches are not
OK to the two pins, so no math or rotates directly on the ports.

It is OK to do anything to any of the other pins.

It is OK for there to be a little latency, and either port A or port B
is OK. Or even both ports, though I don't see how that could get any
faster.

Here's the fastest thing I could come up with:

movlw 0x55
btfss bigreg,7
movlw 0xAA
movwf PORTA

This is almost fast enough, if I could shave an instruction off one of
the two conditions it would be enough for me.

Any suggestions?

Thanks, Bob

-- http://www.fastmail.fm - Does exactly what it says on the tin

2012\01\15@003824 by Scott

picon face
{Quote hidden}

Let's assume you're using PORTA bits 0 and 1 (and you stated no other
pins mattered).
You could use swapf and do it in two instructions (if PORTA is
initialized as shown below):

;Initialize PORTA with 0x21 (or 0x12).

btfss bigreg,7
swapf PORTA


-Scott

2012\01\15@004019 by Scott

picon face
>
> Let's assume you're using PORTA bits 0 and 1 (and you stated no other
> pins mattered).
> You could use swapf and do it in two instructions (if PORTA is
> initialized as shown below):
>
> ;Initialize PORTA with 0x21 (or 0x12).
>
> btfss bigreg,7
> swapf PORTA
>

Also, keep in mind "read-modify-write" issues

2012\01\15@005656 by RussellMc

face picon face
Stirrings from long ago.
Idea starters. Or not.

Writing to a control register may affect pin level differently depending on
what is in the pin's data register.
Without looking at your PIC I don't know if there is any way that this may
be applied but it may be adding or removing a pullup, converting from input
to output etc.

Also, in the definitely naughty department::
- Behaviour of a pin that varies depending on external load level.
- RMW attributes in conjunction with any above.


2012\01\15@013659 by Bob Blick

face
flavicon
face
On Sun, Jan 15, 2012, at 12:38 AM, Scott wrote:

> Let's assume you're using PORTA bits 0 and 1 (and you stated no other
> pins mattered).
> You could use swapf and do it in two instructions (if PORTA is
> initialized as shown below):
>
> ;Initialize PORTA with 0x21 (or 0x12).
>
> btfss bigreg,7
> swapf PORTA

PORTA isn't a full byte, but using PORTB instead, it still won't have
the desired effect. What it does is leave the port alone in one
condition and toggle it in the other, rather than having one pin always
follow and the other be the inverse.

Thanks for the suggestion, though, it's one I hadn't tried!

Cheerful regards,

Bob

-- http://www.fastmail.fm - Access your email from home and the web

2012\01\15@024709 by Scott

picon face
>> Let's assume you're using PORTA bits 0 and 1 (and you stated no other
>> pins mattered).
>> You could use swapf and do it in two instructions (if PORTA is
>> initialized as shown below):
>>
>> ;Initialize PORTA with 0x21 (or 0x12).
>>
>> btfss bigreg,7
>> swapf PORTA
>
> PORTA isn't a full byte, but using PORTB instead, it still won't have
> the desired effect. What it does is leave the port alone in one
> condition and toggle it in the other, rather than having one pin always
> follow and the other be the inverse.
>

Hi Bob,

Now I'm a bit confused.
What is the desired behavior, step by step?

I'll throw out another suggestion: how about an xor of 0x03?

movlw 0x03
btfss bigreg,7
xorwf PORTA

-Scot

2012\01\15@030611 by cdb

flavicon
face
:: movlw 0x55
:: btfss bigreg,7
:: movlw 0xAA
:: movwf PORTA

Just in thinking mode.

Why not:

movlw 0x55
btfss bigreg,7
rrf PORTA,F
movwf PORTA

Colin
--
cdb, spam_OUTcolinTakeThisOuTspambtech-online.co.uk on 15/01/2012
Web presence: http://www.btech-online.co.uk   Hosted by:  http://www.justhost.com.au
 This email is to be considered private if addressed to a named  individual or Personnel Department, and public if addressed to a blog,  forum or news article.

2012\01\15@031505 by IVP
face picon face
> Any suggestions?

If I understood the question

movlw 0x80
xorwf bigreg,w
movwf porta

Jo

2012\01\15@031826 by Bob Blick

face
flavicon
face
On Sun, Jan 15, 2012, at 02:47 AM, Scott wrote:

> Now I'm a bit confused.
> What is the desired behavior, step by step?

One pin follows the high bit of bigreg
Another pin is the complement of the first pin.

>
> I'll throw out another suggestion: how about an xor of 0x03?
>
> movlw 0x03
> btfss bigreg,7
> xorwf PORTA

That also toggles whenever the high bit of bigreg is set, rather than
shadowing it.

Thanks!

Bob

-- http://www.fastmail.fm - IMAP accessible web-mail

2012\01\15@032350 by Bob Blick

face
flavicon
face
On Sun, Jan 15, 2012, at 09:14 PM, IVP wrote:

> movlw 0x80
> xorwf bigreg,w
> movwf porta

That gives one output pin, but I need two outputs, one following bit 7
of bigreg and one being the opposite.

Thanks!

Bob

-- http://www.fastmail.fm - Does exactly what it says on the tin

2012\01\15@040506 by Wouter van Ooijen

face picon face
> Here's the fastest thing I could come up with:
>
>   movlw 0x55
>   btfss bigreg,7
>   movlw 0xAA
>   movwf PORTA

What's that bigreg, is its format out of your control?

Some PICs have a hardware comparator, could that used?

--
Wouter van Ooijen

-- -------------------------------------------
Van Ooijen Technische Informatica: http://www.voti.nl
consultancy, development, PICmicro products
docent Hogeschool van Utrecht: http://www.voti.nl/hvu
C++ on uC blog: http://www.voti.nl/erblog

2012\01\15@043940 by Steve Smith

flavicon
face

Ok it's a few more instructions but the latency is shorter

Assuming port is set already with complementary pins

comf        PORTA ,w
Btfss        bigreg,7
Movwf PORTA

That will reverse the pin states on event

(I think)

Steve

{Original Message removed}

2012\01\15@060138 by IVP

face picon face
>> movlw 0x80
>> xorwf bigreg,w
>> movwf porta
>
> That gives one output pin, but I need two outputs, one
> following bit 7 of bigreg and one being the opposite.

Ah, I did misunderstand

Can you use any other bits in bigreg ?

Or, as Steve said, pre-set the port

2012\01\15@064045 by Jan-Erik Soderholm

face picon face


Bob Blick wrote 2012-01-15 06:23:
> I have an existing small PIC project that produces an output on one pin
> based on the high bit of a register. In order to save an external
> inverter, I'd like to also output the complement on another pin.

Not on the 16F627A, but it seems as the Configurable Logic Cell (CLC)
module on other devices would be able to do this in hardware with
proper setup. Mirror the invers of one I/O pin on another I/O pin.
I guess at least, the module is a bit complex...

There was a thread on the use of the CLC module a few days ago,
so I thought this was at least semi-OT...

Jan-Erik.



{Quote hidden}

2012\01\15@080814 by smplx

flavicon
face


On Sat, 14 Jan 2012, Bob Blick wrote:

{Quote hidden}

bcf        STATUS,C
rrf        bigreg,w
addlw        0x40
movwf        PORTA

if you can ensure that the carry flag is in a known state as a side effect of previous instructions then you could eliminate the "clear carry".

NOTE: if carry is set use "addlw 0xC0" instead


Regards
Sergio Masc

2012\01\15@112017 by John Gardner

picon face
If other than '627 is possible, there's the CLC, as someone suggested.

Also, don't some parts allow changing the clock on the fly? I have'nt
done this, so not sure how practical...

Jac

2012\01\15@120503 by Kerry Wentworth

flavicon
face
I don't see the downside of Wouter's suggestion of using a voltage comparator.
Output the bit on A0, which is connected to A1.
Set comparator1 to compare the voltage on A1 to 2.5V from the voltage reference.
Output comparator 1 results to A3.
A3 will always the the inversion of A0.
Why wouldn't that do what you want?

Kerry



Bob Blick wrote:
{Quote hidden}

>

2012\01\15@134810 by Bob Blick

face
flavicon
face
Yes, I think that is the perfect solution. Sergio's code is good but the
same number of instructions.

Using Wouter's idea of the comparator I can use the same code I always
used, but save an external inverter by using the internal comparator.

Thanks to everyone!

Best regards,

Bob

On Sun, Jan 15, 2012, at 12:03 PM, Kerry Wentworth wrote:
{Quote hidden}

-- http://www.fastmail.fm - The professional email service

2012\01\15@175523 by IVP

face picon face
> Using Wouter's idea of the comparator

Internal comparator briefly flicked through my head. Got me
to re-read the datasheet anyway ;-)

I've used the comparators only once, a long time ago, as a
motor stall detect. Not a feature that gets mentioned much.
Less so than the ADC

Jo

2012\01\15@180430 by jim

flavicon
face
Also, you could double the processor speed, and get twice the instruction
resolution.

Jim

-----Original Message-----
From: .....piclist-bouncesKILLspamspam@spam@MIT.EDU [piclist-bouncesspamKILLspamMIT.EDU] On Behalf Of
IVP
Sent: Sunday, January 15, 2012 4:55 PM
To: Microcontroller discussion list - Public.
Subject: Re: [PIC] need to shave off half an instruction

> Using Wouter's idea of the comparator

Internal comparator briefly flicked through my head. Got me
to re-read the datasheet anyway ;-)

I've used the comparators only once, a long time ago, as a
motor stall detect. Not a feature that gets mentioned much.
Less so than the ADC

Jo

More... (looser matching)
- Last day of these posts
- In 2012 , 2013 only
- Today
- New search...