Rick Swift & Apple & Embedded I make things. Sometimes, I’ll talk about it here.

My Gorram Frakking Blog

Soekris net4521 Single Board Computer

I got my net4521 a few days ago, and after borrowing a CF card ('cause I stupidly forgot to get one of my own), I had it up and running Pebble Linux (from Tor Amundson) in no time. A few days later the CM9, miniPCI 802.11a/b/g card, arrived.

I've been poking at getting the 802.11 card up-and-running, and met with some success. Right now a kind soul is helping me learn how to use buildroot to build a Linux from the ground up for use on this box. We'll see how that goes, and I'll try to post the steps here.

Damned Hotlinkers

I discovered that the vast majority of the bytes I was serving was due to sites that hotlink, that is, sites that use image src URIs that refer to my site (thereby stealing my bandwidth), rather than copying the image to their own site and serving it themselves. Using Apache's RewriteEngine, as described in this article, allows me to refuse to serve images referred by any page not my own.
Hopefully this will put a stop to the practice. I currently only FORBID the request, but I may serve up some obnoxious image instead. Not yet sure.

Cingular GPRS and Mac OS X

I just subscribed to the $20/mo, 10 MB/mo plan that Cingular offers. Unfortunately, while you can use your cell phone to subscribe, and they can give you all the information you need (although it's like pulling teeth to get Mac info...like so many others, they only officially support Windoze), you can't download the necessary modem script to enable the whole thing to work.
They recommend you download GPRS Script Generator, which requires that you pay the $10 shareware fee before you can generate the necessary script. Fortunately, a very quick search on Google turned up an article on how to configure the Mac for Cingular Motorola use. It provides a modem script that seems to work well.
I have a RAZR V3, and I modified the script to connect at 115200 bps (rather than the default 57600). It worked great!
This is all temporary, of course, 'till I get my 3G card. We'll see how smoothly that goes...

Is Big Brother Listening? I Have a Conversation for Him

4:55:56 PM jfm: he's syrian?
4:55:59 PM jr: YEP
4:56:06 PM jfm: then tell him this may be his last chance
4:56:25 PM jr: the FBI investigated me last time i did a consulting gig for him
4:56:29 PM jr: large wire transfers
4:56:30 PM jfm: no shit?
4:56:33 PM jr: yep
4:56:36 PM jfm: how large?
4:56:41 PM jr: i'm probably on some watch list
4:56:45 PM jr: few hundy k
4:56:46 PM jfm: that's so fucked
4:56:49 PM jfm: you terrorist
4:56:53 PM jr: i'll never tell
4:56:54 PM jfm: i don't know you
4:57:04 PM jr: by the way, you should get that anthrax I ordered in your name
4:57:09 PM jfm: where's "remove from buddy list"
4:57:13 PM jr: and how many copies of the Q'uran did you need?
4:57:15 PM jfm: LALALALALA I can't hear you LALALALA
4:57:18 PM jr: haha
4:57:25 PM jfm: you using adium?
4:57:25 PM jr: Insh'Allah
4:57:30 PM jr: yep
4:57:34 PM Encrypted OTR chat initiated. jr's identity not verified.
4:57:40 PM jfm: hrm
4:57:42 PM jr: haha
4:57:53 PM jfm: it says Encrypted OTR chat initiated. jr's identity not verified.
4:57:58 PM jfm: but the lock shows locked
4:57:59 PM jr: see? now THAT looks suspicious
4:58:02 PM jr: same on my end
4:58:11 PM jfm: 'zactly why everyone should be encrypted all the time
4:58:37 PM jfm: i suppose I can just verify you
4:58:45 PM jfm: here's hoping it's really you
4:59:00 PM jfm: it seems to be ecrypted
4:59:11 PM jr: the NSA's really good at impersonating people but they're terrible at humor
4:59:15 PM jr: yep
4:59:22 PM jr: seems to be
4:59:35 PM jfm: HAHA
5:00:51 PM jfm: is this encrypted test test test
5:01:05 PM jfm: hmm. send me something
5:01:48 PM jfm: looks like it's encrypted, but not our screennames
5:01:56 PM jfm: so, They still know I'm talking to you
5:02:25 PM jr: ah yes
5:02:30 PM jr: blah blah blah
5:02:33 PM jfm: oh well, good enough for me
5:02:47 PM jfm: tcpdump is cool
5:03:10 PM jr: this is the point in our conversation where we run out of things to say and yet feel obligated to continue chatting because we went through all the trouble of encrypting
5:03:22 PM jfm: ROTFLMAO hAHAHAHAHA
5:03:39 PM jr: actually, this is the point in the conversation where I get up to pee before I soil myself
5:03:46 PM jfm: that's going into my blog

ATmega32 PWM

This note briefly describes how to set up PWM on an ATmega32. In this instance, Timer/Counter 1 (16-bits wide) is used to set up a Fast PWM-mode PWM wave to drive a typical R/C servo. The PWM period is 20 ms (50 Hz), and the pulse width varies from 0.9 ms to 2.1 ms.

With a 16 MHz clock, the full 16-bit count wraps around in about 780 µs. Since we need a PWM period of 20 ms, this is clearly too fast. Prescaling Timer/Counter 1 by dividing the sytem clock by 64 gives us a full-count period of 50 ms. By setting the upper limit of the count using ICR1 to 12500, this results in the desired 20 ms period.

Update: I’ve gotten some math wrong in the preceding paragraph, and I'm not sure what I was thinking. It seems that a full 16-bit count would take 4.096 ms at 16 MHz. Also, the comments in the code regarding prescaling values don’t all agree. Sorry about that. I hope you can still find this useful.

To get the appropriate servo pulse width between 0.9 ms and 2.1 ms, the OCR1A register is loaded with values between 225 and 525.

Circuit Set-up

Please excuse the lack of a schematic; I simply don’t have time to create one right now.

The ATmega32 is set up to run with a 16-MHz crystal oscillator. On the PDIP 40 package, the following pins are connected:

Pin Description Connections & Use
6 PB5/MOSI ISSP
7 PB6/MISO ISSP
8 PB6/SCK ISSP
9 RESET Through 10 kΩ resistor to Vcc, N.O. switch to GND, ISSP
10 Vcc Power, 0.1 µF ceramic cap to GND, ISSP
11 GND Ground, ISSP
12 XTAL1 To 16 MHz crytsal, 10 pF ceramic cap to GND
13 XTAL2 To 16 MHz crytsal, 10 pF ceramic cap to GND
19 PD5/OC1A To Servo signal line
30 AVcc Power, 0.1 µF ceramic cap to GND, ISSP
31 GND Ground, ISSP
40 PA0/ADC0 To LED, LED to 470 Ω resistor, resitor to GND

Fuse Set-up

The fuses are set for a 16 MHz external crystal oscillator.

Name Description Value
Fuse Lo Fuse Low Byte 11101111b, 0xEF
Fuse Hi Fuse High Byte 10001001b, 0x89

Register Set-up

The following registers are set, in this order. Although the order isn’t strictly necessary, some subset of it might be (be specific).

Name Description Value
DDRA Port A Direction 00000001b, 0x01 (PA0 output, rest input)
DDRA Port B Direction 00000000b, 0x00 (all input)
DDRD Port D Direction 00110000b, 0x30 (PD4, PD5 output, rest input)
TCCR1A Timer/Counter 1 Configuration A 10100010b, 0xA2 (OC1A & OC1B set at BOTTOM, clear on compare match, WGM=14 [fast PWM, ICR1 is TOP])
TCCR1B Timer/Counter 1 Configuration B 00011011b, 0x1B (prescale ClkI/O/64)
ICR1 In Fast PWM mode, becomes TOP 12500d (20 ms PWM period with ClkI/O/64 prescale)

Code

#include <inttypes.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/signal.h>
#define kPinInitCompleteLED         PA0
#define kDelay                      10000
#define kReverseDelay               300000
#define kLowerLimit                 300                 //  Min 225 == 0.9 ms
#define kUpperLimit                 450                 //  Max 525 == 2.1 ms
int
main()
{
    volatile long       d;
    short               dir = 1;
    
    //  Set LED output pins…
    
    DDRA = _BV(kPinInitCompleteLED);
    DDRB = 0;                                           //  Port B inputs
    
    //  Set up OCR pins (PD4, PD5) as outputs (00110000)…
    
    DDRD = _BV(PD4) | _BV(PD5);
    
    //  Set up Timer 1. Timer 1 should reset when
    //  it reaches TOP = ICR1 (WGM13:0 = 1110b). On
    //  compare match clear output, at TOP set (COM1A1:0 = 10b).
    
    TCCR1A = _BV(COM1A1) | !_BV(COM1A0)                 //  Both PWM outputs set at TOP,
                | _BV(COM1B1) | !_BV(COM1B0)            //    clear on compare match
                | !_BV(FOC1A) | !_BV(FOC1B)             //  PWM mode, can't force output
                | _BV(WGM11) | !_BV(WGM10);             //  Fast PWM, TOP = ICR1
    
    TCCR1B = !_BV(ICNC1) | !_BV(ICES1)                  //  Disable input capture noise canceler,
                                                        //    edge select to negative.
                | _BV(WGM13) | _BV(WGM12)               //  Fast PWM, TOP = ICR1
                | !_BV(CS12) | _BV(CS11) | _BV(CS10);   //  clk(i/o) / 1024
    
    //  PWM duty cycle…
    
    OCR1A = kLowerLimit;
    OCR1B = kLowerLimit;
    
    //  PWM period…
    
    ICR1 = 12500;
    
    //  Show initialization complete…
    
    PORTA = _BV(kPinInitCompleteLED);
    
    //  Loop forever steering left-to-right-to-left…
    
    OCR1A = kLowerLimit;            //    Min value == 0.9 ms
    while (1)
    {
        d = kDelay;
        while (d--);
        
        OCR1A += dir;
        
        if (OCR1A < kLowerLimit)
        {
            OCR1A = kLowerLimit;
            dir = 1;
            d = kReverseDelay;
            while (d--);
        }
        
        if (OCR1A > kUpperLimit)    //    Max value == 2.1 ms
        {
            OCR1A = kUpperLimit;
            dir = -1;
            d = kReverseDelay;
            while (d--);
        }
        
    }
    
    return 0;
}