Wednesday, October 27, 2010

Transcendent Wonder

It's fall and it just snowed.

So I had to get up in the dark and shovel the driveway, and the snow was so heavy I finally got out the snow blower.  So there I was feeling sorry for my self.  All this hard work and I just wanted to sleep.

When I got done I came inside and started breakfast for the kids, and decided to do the dishes too.
I was feeling even more angry, depressed, it's dark out, cold, no help...

    I stopped and I looked
    Each drop of water, unique.
    Hands washing plates clean.


All the anger and self pity evaporated.

Transcendent Wonder.

It's all around us all of the time.

TF

Tuesday, October 26, 2010

The Depth of Children

So, this morning while getting ready for school, my 12 year old son asked,
"Why do people have syntax in speaking when no other animal does."

Wow, the other day we were talking about what is unique about humans and the main thing I told him was that we have syntax in language, and no other animal does.
So then he looked it up on Wikipedia yesterday, "syntax", and then asked the question.
So this morning we discussed evolution and how every trait is either useful or vestigial.
Syntax is useful because of very precise communication and survival.
Tail bones in humans are vestigial.

Then got onto the anthropic principle and how the world is the way it is because if it wasn't we wouldn't be here to ask why it is the way it is. Syntax is much like that.  If we didn't have syntax we wouldn't be able to think about thinking and ask such a question.

Never underestimate the intelligence and depth of children!

TF

Monday, October 25, 2010

How Cool are Wavelets

Ok, Todays topic, Wavelets.
Wavelets can be used to detect wave forms of some shape and frequency.
This is much like a poor man's FFT.

Wavlets work like this...
You have a 'template' wave shape that you are trying to detect.
For example a wave might look like this...

This is a kind of random wave shape but lets assume it is important to detect when this wave form happens in some data stream.

The incoming data stream might look like this...

The red wave to the right is the input data.
Hidden in there is the blue wave form with some noise.

What we do is convolute the input wave form with the wavelet. By convolute we mean take each point in the wavelet and multiply it by the corresponding point in the input data stream and do that for every possible position along the input data stream.
Thus we 'scan' the input stream with the wavelet generating a correlation factor for each point along the input data stream.

Like this...

for i=0 to in.length
sum[i] = 0;
for k=0 to wavlet.length
sum[i] += in[i] * wavelet[k];

Then the sum array will tell you how much a given point in the input correlates to the wavelet form.

If you study this algorithm you will see that where the wavelet is high and the input is high you get a large positive number. If the wavelet is negative and the input is negative you again get a large positive number.

If the input is zero and the wavelet is not zero
you still get zero, and also if the wavelet is zero and the input is not zero you still get zero.

If the input is the inverse of the wavelet then the
correlation will be negative.

A few notes: The wavelet must be normalized. The ideal is that the peak wavelet value is 1.0. Or you can make the integral of the wavelet be zero. It depends on what result you want.

The wavelet also has a frequency. You can stretch
or shrink the wavelet length to detect different frequencies of the wave form.

A specific frequency detector wavelet looks like this...


This wavelet will detect a specific frequency. The more cycles in the wave the narrower the
frequency detection.

This wavelet is a low pass filter...
And this is a high pass filter...

The cool thing here is that the wavelet can detect a specific wave shape and timing without the more complex math of a complete FFT. Also with out knowing exact frequencies and such, you can detect a specific wave shape.

Very useful for heart beat detection, specific vibration modes, and many other uses.

There have been zillions of academic papers written analyzing specific wave shapes and exactly how they filter or detect frequencies. But to use wavelets it is not necessary to understand all the theory.

TF

Friday, April 30, 2010

BMP085 C Code for ARM Processor

I have debugged this code for the BMP085 pressure and temperature sensor.

(Note: I found this but do not yet have source: More precise calcs)

The examples in the data sheet assume an incorrect C operartor order.

Also in Arduino kits the int is a short and a long is a 32 bit int.

On my processor ( LM3S1607 ) an int is 32 bits.

So in this code everything is an int or unsigned int. Never short or unsigned short.

Also Arduino example code assumes the oversampling to be 0 and here we can set it to higher resolution.

The b3 = ... is where parenthesis are needed to get it right.

Enjoy.



int x1, x2, x3, b3, b5, b6, p;

unsigned int b4, b7;


x1 = ((BaroState.rawTemperature - Baro_ac6) * Baro_ac5) >> 15;
x2 = (Baro_mc << b5 =" x1" temperaturetenthc =" (b5">> 4;

b6 = b5 - 4000;
x1 = (Baro_b2 * (b6 * b6 >> 12)) >> 11;
x2 = Baro_ac2 * b6 >> 11;
x3 = x1 + x2;
// Error in the BMP085 spec sheet math.  Extra parens needed at the V's
//    V                              V
b3 = (((Baro_ac1 * 4 + x3) << Baro_oss) + 2) >> 2;
x1 = Baro_ac3 * b6 >> 13;
x2 = (Baro_b1 * (b6 * b6 >> 12)) >> 16;
x3 = ((x1 + x2) + 2) >> 2;
b4 = (Baro_ac4 * (x3 + 32768)) >> 15;
b7 = (BaroState.rawPressure - b3) * (50000 >> Baro_oss);
p = b7 < x1 =" (p">> 8) * (p >> 8);
x1 = (x1 * 3038) >> 16;
x2 = (-7357 * p) >> 16;
BaroState.pressurePa = p + ((x1 + x2 + 3791) >> 4);
NavState.baro = BaroState.pressurePa;

Saturday, January 16, 2010

LM3S1607 internal clock set

On the stellaris chips setting the clock up can be a challenge.

The prototype boards use external clock crystals.
The setup is like this...

SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);

To get the internal clock I use this...

SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_INT);

TF

More...

Watch out! The internal oscillator on the LM3S1607 is only +- 30 % at 12 Mhz.
That means that UARTS will not work reliably at all.
So thats why the eval board has a crystal on it.

TF

Thursday, January 7, 2010

UART1 on LM3S9B92

Ok,
I just spent 2 days hammering away at getting UART1 to put out a signal on the TI LM3S9B92-B eval board.

The sample code called hello.c talks to UART0 and works fine.

If you try to switch to UART1 or UART2 it does not work.
SO I extracted the driverlib calls out to an easily switchable linear piece of code, like this...
(The blog post code mangles the C code a bit. The for loops are munged.)

int
main(void)
{
int uartIdx = 1;
volatile unsigned long i;
SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
SYSCTL_XTAL_16MHZ);

if(uartIdx == 0)
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200,
(UART_CONFIG_PAR_NONE | UART_CONFIG_STOP_ONE |
UART_CONFIG_WLEN_8));
}
else
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
GPIOPinTypeUART(GPIO_PORTD_BASE, GPIO_PIN_2 | GPIO_PIN_3);
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);
UARTConfigSetExpClk(UART1_BASE, ROM_SysCtlClockGet(), 115200,
(UART_CONFIG_PAR_NONE | UART_CONFIG_STOP_ONE |
UART_CONFIG_WLEN_8));
}

for(i=0; i<100000;>
{
}
//
while(1)
{
if(uartIdx == 0)
{
UARTCharPut(UART0_BASE, 'K');
}
else
{
UARTCharPut(UART1_BASE, 'K');
}
for(i=0; i<100000; i =" i"> {
}
}
}

But UART1 was stubbornly silent.

Here is the corrected code, notice that I have to explicitly set the pins up...

int
main(void)
{
int uartIdx = 1;
volatile unsigned long i;
SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
SYSCTL_XTAL_16MHZ);

if(uartIdx == 0)
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200,
(UART_CONFIG_PAR_NONE | UART_CONFIG_STOP_ONE |
UART_CONFIG_WLEN_8));
}
else
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
GPIOPinTypeUART(GPIO_PORTD_BASE, GPIO_PIN_2 | GPIO_PIN_3);
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);
UARTConfigSetExpClk(UART1_BASE, ROM_SysCtlClockGet(), 115200,
(UART_CONFIG_PAR_NONE | UART_CONFIG_STOP_ONE |
UART_CONFIG_WLEN_8));
GPIOPinConfigure(GPIO_PD2_U1RX);
GPIOPinConfigure(GPIO_PD3_U1TX);
}

for(i=0; i<100000;i++>
{
}
//
while(1)
{
if(uartIdx == 0)
{
UARTCharPut(UART0_BASE, 'K');
}
else
{
UARTCharPut(UART1_BASE, 'K');
}
for(i=0; i<100000;i> {
}
}
}

I think what is happening is that the in circuit debugger sets up the UART0 since that is used often in sample code. None of the example code shows this solution.

Any way, I hope I have saved someone some time.

TF

P.S. The signals out of the chip are inverted from standard RS232. It is expected that your circuit will use drivers that convert the 0 to 3 volt TTL output to inverted -5 to + 5 volt RS232.
Thus if you directly wire a DB9 connector to a chip port and then into a PC serial port, it will not work.

Friday, November 20, 2009

How Not To Make A Corporate Web Site

Ok, Time to blow off some steam.

I think I have found the worst large corporation web sit there is.
www.motorola.com

What I was trying to do is simply find the manual for a Motorola XTS 5000 portable radio so I can hook it up to a PPP serial port on my Vista laptop.

Sounds easy, huh?

Well I tried the obvious, I googled Motorola XTS 5000 manual.
All the results are for very unsafe web sites for manuals, none of which actually have the manuals.

(Annoyed)

A few links were to www.motorola.com, but all actual documents were just marketing brochures with no details.

Their search function is so broken as to be nearly useless.

(Anger level rising, 1 hour wasted)

I finally called support and was told that all those manuals are on Solutions - Motorola USA
though "solutions" was obviously used as a euphemism for "marketing".
But I would need to register to get an online acocunt and it would take two days.

So I went to the site to sign up. Wow, I think the signup form was designed by committee where any field that was suggested was put in.

Ok, this is silly. All I wanted was to find an online manual for a radio. Instead I got a process that would make passage of Obama's Medical Fiasco look easy.

So while I waste two work days waiting for a simple piece of information, I noticed that there is a feed back email address. Ohhhh, nifty. So I careful write a short email about the shortcomings of the site. Yup, you guessed it, the email bounced.

So If it wasn't for the fact that my job requires that I get this software written...

Ok, I'm done. All better now.

Oh, and let me theorize how the web site got this way...
All the CXX managers of Motorola fought over getting their pet project in, and the web designer inside Motorola was ignored. Nobody any where the top of the organization has ever actually used the site to try to do anything remotely like what a customer would do. The web site is obviously organized by someone who is thinking about what they want the customer to see, and has no idea at all about what the customer actually wants.

TF

Three days later, after the weekend, yet another hurdle to cross.
This is regarding your account with us. Will you be reselling our products? Or will it be for your own company use?
If for company use than please state you are taxable. If for resell then fill out the attached tax cert and fax back
to NNN-NNN-NNNN

Aaaaaargh!

TF