Configurable polarity of I/O

FreeEMS topics that aren't specific to hardware development or firmware development.
User avatar
nitrousnrg
LQFP144 - On Top Of The Game
Posts: 468
Joined: Tue Jun 24, 2008 5:31 pm

Re: Configurable polarity of I/O

Post by nitrousnrg »

1. True, you need two edges. What difference does it make to have it hardware inverted? You can configure the polarity using only one instruction...
Either you want:
* rising or falling edge, no difference between them. (that was my case. I was able to measure precisely the falling zero crossing, but not the rising one).
* both edges. There you can't avoid the extra ISR code, but again, what difference does it make to select polarity externally?

I'm not convinced at all about making rpm input hw-configurable...

2. ok, anyway it was a dead end if PITs only trigger rising edges on port T :-)
Marcos
User avatar
Fred
Moderator
Posts: 15431
Joined: Tue Jan 15, 2008 2:31 pm
Location: Home sweet home!
Contact:

Re: Configurable polarity of I/O

Post by Fred »

nitrousnrg wrote:1. True, you need two edges. What difference does it make to have it hardware inverted? You can configure the polarity using only one instruction...
<snip>
* both edges. There you can't avoid the extra ISR code, but again, what difference does it make to select polarity externally?
The difference is that if you have hardware configuration you CAN avoid that extra ISR code. Now, educate me, how do you do edge config with one instruction?? Show me, please.
DIYEFI.org - where Open Source means Open Source, and Free means Freedom
FreeEMS.org - the open source engine management system
FreeEMS dev diary and its comments thread and my turbo truck!
n00bs, do NOT PM or email tech questions! Use the forum!
The ever growing list of FreeEMS success stories!
User avatar
nitrousnrg
LQFP144 - On Top Of The Game
Posts: 468
Joined: Tue Jun 24, 2008 5:31 pm

Re: Configurable polarity of I/O

Post by nitrousnrg »

Looking at the schematic, you're using PT1 and PT2, so I guess you are using the ECT.
The edge interrupt polarity is configured with the register TCTL3 or TCTL4. Page 325 of the datasheet.

Each pin has an EDGxA and EDGxB, which selects between:
0 0 capure disabled
0 1 capture on rising edges
1 0 capture on falling edges
1 1 capture en both edges

I did this with microchip and atmel microcontrollers. I'm sure Freescale micros behaves the same way.
Marcos
User avatar
Fred
Moderator
Posts: 15431
Joined: Tue Jan 15, 2008 2:31 pm
Location: Home sweet home!
Contact:

Re: Configurable polarity of I/O

Post by Fred »

Those bits are configured at init time, and not again. When you receive an interrupt, you can tell if it was going from high to low or vice versa due to the current state and the fact you know there was just a transition. You might run xyz code on rising and abc code on falling. These code snippets might be different. In order to run the correct code snippet for the correct edge, you either need the signal to be correct, or software to invert the boolean that describes wich edge itis, based on config. This is how my code used to look :

Code: Select all

        /* Set up edges as per config */
        unsigned char risingEdge;
        if(fixedConfigs.coreSettingsA & PRIMARY_POLARITY){
                risingEdge = PTITCurrentState & 0x01;
        }else{
                risingEdge = !(PTITCurrentState & 0x01);
        }

        if(risingEdge){
Maybe it could be more efficient than that (while still being clear!!) but even so, it's a bit ugly and horrible.

The other option is to not hve the code, and not have the hw invert on the board, and expect users to configure it external to the box in their wiring, but I think that's pretty horrible too. Having a pair of pads to bridge and configure inside the box, once, at install time, is nice.

Fred.
DIYEFI.org - where Open Source means Open Source, and Free means Freedom
FreeEMS.org - the open source engine management system
FreeEMS dev diary and its comments thread and my turbo truck!
n00bs, do NOT PM or email tech questions! Use the forum!
The ever growing list of FreeEMS success stories!
User avatar
nitrousnrg
LQFP144 - On Top Of The Game
Posts: 468
Joined: Tue Jun 24, 2008 5:31 pm

Re: Configurable polarity of I/O

Post by nitrousnrg »

Ah, you do have the code to select polarity by software. And you really want a switch to select it by hardware, ok.
The other option is to not have the code, and not have the hw invert on the board, and expect users to configure it external to the box in their wiring, but I think that's pretty horrible too. Having a pair of pads to bridge and configure inside the box, once, at install time, is nice.
Well, I don't see having to solder as a nice/handy thing (I know, its diy! but I'd like plug&play solution)
If we put the polarity selector on our hardware, we are adding a few nsec delay, a few extra mA (I don't really care), another thing that can fail, footprint, and cost a few cents more.
If we implement it on the software, you add usecs into the ISR, and goes against code legibility. The user can mess this out if it is too easy to change, just as well as any other configuration parameter.

Couldn't we provide software methods of hw debugging for this? Like saving the time between tooths; if there are too many inconsistences the PC should show a pop up (say base time T+-sigma (deviation), or 2T+-sigma is OK, if we're close to 1.5T then lets check the polarity).
I don't think you like the bridge just because, you are thinking in the user, and as a user, I'd prefer to have the pop up and make a few clicks, rather than get the soldering iron.

You already took a decision about this, I won't argue more.
Marcos
Post Reply