Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Untested: 9600 baud low CPU overhead interrupt & dual timer full duplex UART

Status
Not open for further replies.
Strange
unsigned char QTXControl is a number from 0 to 10
if (QTXControl != 0) works
if (!QTXControl) does not

Is the shortcut only for boolean?

! is a logical operator. You could write your working expression as either:

Code:
if (QTXControl != 0)

// Or (this one sometimes preferred stylistically)
if (QTXControl)

// Or
if (!(QTXControl == 0))

The equivalent for your second statement would be:

Code:
if (!QTXControl)

// Or
if (QTXControl == 0)

So we can see they are opposites of eachother.
 
Yes, I did check before posting using the most recent XC8 in both pro and free mode with a very large project. In both the compiler is sensible enough to understand that single bit operations can be achieved with a btfsc/btfss (target was 18F).
...

Great info, thanks for posting your results. I did notice you tested the bit IOFS, which I assume is a hardware register flag? Did you try with blah.F0 etc, ie testing a bit within a user variable?

Compiler optimisation is a fun thing to poke around at, but maybe we could start a thread for further discussion if required?

Sure, I'll be in that and can post some MikroC examples. :) That might be better than disrupting Bill's thread with low-level C-asm specific stuff.
 
Hi Bill,

So where are you at now with your subsystem code? Have you measured the actual overhead in the ISR during rx active/idle and tx active/idle?

I did a bit-banged 9600 baud full-duplex subsystem years ago in assembly language using a single timer running at 3X the bit rate for 9600 baud (34.5 uS). It can be found in the PICLIST source code library. The ISR used 34 cycles (RX idle) or 35 cycles (RX active) which is ~50% overhead when using a 4-MHz clock.

Cheerful regards, Mike
 
Hi Mike, I read that code you did, nice work.

The code offloads the heavy lifting to your built in peripherals.
RX is edge driven by INT0 and no oversampling as the bits are sampled at as close to 1/2 way through the next bit as possible, based on a timer IRQ that's been synced and 1/2 baud clock delayed to the INT0 interrupt. I was considering making this a high priority IRQ if my other routines take too much time.
TX has its own clock and just chugs out one bit at a time every 104µS. I'll have to run it through the simulator to count the clock cycles.

I've had it working in hardware using Swordfish BASIC, just haven't tested it in XC8.
 
The code offloads the heavy lifting to your built in peripherals.

Exactly! That is the reason why assembly programming is getting obsolete. Chips have built in peripherals for almost everything. There is no need to highly tune every single instruction any more. Just write code that initializes peripherals correctly and there you go.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top