PIC10F Assembly “Hello World”

August 15th, 2009

So for a project, I’m using a PIC10F due to their very small size (in a SOT23-6, wow) and low cost.  They don’t have interrupt support, but they do have a timer, watchdog timer and a comparator.  You can do some fairly funky things with them.  However, I’m opting to use assembly for this project since it’s probably going to be simpler this way, as the stuff I need to do is very timing critical (reading sensors without interrupts = lots of polling).  Also I think I can squeeze the size of the program down better than a C compiler might do.

But I ran into a roadblock.  There are no documentations of assembly code listings for the PIC10F, and very few resources online.  So here’s a little snippet for you, which blinks an LED on pin GP2:

	list      p=10F222            ; list directive to define processor

#include
        ; processor specific variable definitions

    #define LightOn bsf GPIO,2  ; turn drive output on
    #define LightOff bcf GPIO,2 ; turn drive output off

;**********************************************************************
	ORG     0x1FF             ; processor reset vector
	ORG     0x000             ; coding begins here

    cblock 0x18 ; this is where we declare what to call user memory locations
      DelayTime:3       ; reserve 3 locations for delay counters
     endc

	goto Init
Start:
	clrwdt
	LightOn
	call Delay
	LightOff
	goto Start

Init:
    movwf   OSCCAL      ; load factory osccal value at start-up
    bcf     OSCCAL,0    ; do NOT output osc/4 on GP2 (IR sensor input)
    movlw   b'00000000' ; set all GPIO low at startup
    movwf   GPIO        ; load port latches
    movlw   b'00000000' ; All GPIO pins are outputs
    tris    GPIO        ; set I/O directions
    movlw   b'11011000'	; wake-up on pin change disabled, weak pull-ups off
                        ; Timer0 clock select on GP2 internal
    option              ; write to OPTION_REG

    ; clear all user RAM/variables on boot

    movlw  0x10         ; initialize pointer
    movwf  FSR          ; to RAM start
	goto Start

Delay					  ;
    movlw   D'2'          ; 2 = a delay period of approximately 500mS

Delay2                    ;
    movwf   DelayTime     ; pre-load W & enter at Delay2 for different delays
    movlw   D'232'        ;
    movwf   DelayTime+1   ;
    movlw   D'255'        ;
    movwf   DelayTime+2   ;
Dloop
    clrwdt                ; 1
    decfsz  DelayTime+2,f ; 1
    goto    $-2           ; 2/1
    decfsz  DelayTime+1,f ; 1
    goto    $-4           ; 2/1
    decfsz  DelayTime,f   ; 1
    goto    $-6           ; 2/1
    retlw   0             ; 2

	end

Delay routine and general structure is shamelessly stolen from Bruce on PICbasic.co.uk.

Hopefully, someone will find this useful :)

Lounge on the Farm: Outside Broadcast for CSR (Part III)

July 14th, 2009

We did it! High fives all round.

After a lot of preparation, sweat and blood we managed to broadcast live, for 11 hours a day for 3 days, from a pigshed in the middle of nowhere. Here’s a little tour of our makeshift station:

This is the Edit Suite and Tech Corner, fully set up. As I mentioned in Part II, we have the encoder on the back wall which encoded audio from the studio (coming up next), and sent it over the point to point wireless link. The edit machines saw a lot of action, as we (the tech team) dashed about the site transporting Marantz recorders from the various stages back to base to be edited for broadcast. They were also used to edit interviews and other bits of audio for broadcast. Once the editing was complete, the data was transferred to the Playout machine in the Studio, where they were added to the database and played out on air.

Here’s the studio. Presenter goes behind the desk, guests and co-hosts in front. We did a lot of mic swapping, and patching over the course of the weekend to accomodate different requirements. The studio ended up being used not only for live interviews and shows, but also for live musical performances! Below we see the rather excellent Harp for Hangovers performing a live set in the studio. We also had Lucy Kitt perform two tracks for us. The quality was excellent, and far better than we expected.

All in all, it was a very successful OB. The editing team have got many hours of live recordings to work with, which will hopefully start being played out on FM in the near future. As one of the OB’s I’ve helped with, I was extremely impressed at how smoothly it went. There were a few hicups, but nothing that caused any significant problems for the running of the TX. High fives indeed!

You can see the rest of my photos for the event on my flickr tag “lotf”.

Lounge on the Farm: Outside Broadcast for CSR (Part II)

July 10th, 2009

CSR is doing an outside broadcast at the music festival called Lounge on the Farm, and broadcasting live (right now as of this writing) on the Internet and on FM 97.4MHz in Canterbury. I am a volunteer for Engineering, and the team had the challenge of making all this possible.

On Thursday morning at about 1030 we rocked up to the “venue” in The Kitchen van. We found a pig/horse/cattle shed, complete with straw and cobwebs, and various forms of Hanging Death.

We got the farmer to remove the hanging guttering you see in the above picture, and we removed most of the dangling bits of wood in the roof and put duct tape over all the sharp bits on the walls.

After a large amount of sweeping and clearing, we manage to get it into a semi-decent state so we can start putting all of the kit into the “rooms”. Meanwhile, we were setting up the 5GHz link between the pigshed and the site office where there is an Internet connection.

Here we have a wind up stand, with a crossbar holding an point-to-point wireless link we got from Solwise, and a FM antenna for our radio tuner in the studio.

Once we had the client end of the wireless link in position, we were ready to install the other end. Fortunately, we had found a place to mount the other side that was in perfect line of sight to the receiver. However, it was a little bit scary.

Here we see a terrified looking Rich on the top of a bent lighting mast, and a bit of CAT5 flying down to the portacabins below. We then ran the CAT5 through a window in the site office and into the kitchen (!!) where they have their ADSL router. We installed the Power over Ethernet Injector (which we were praying would work over that length of cable), and plugged it in. And what do you know, it worked perfectly first time.

Once the Internet connection was up, we set about building the transmission equipment.

We’ve got a little AMD Semperon machine which has a DI coming from the studio on the other side of the shed, which is then encoded into AAC+ by SAM Broadcaster and sent over the network connection to the station on the Canterbury campus. We chose AAC+ due to its ability to encode to high quality over very low bitrates. This also means that we don’t need very much bandwidth to provide the stream, which is very good when you’re out in the sticks! It’s quite resilient to packet loss too, as we found.

Most of the networking kit is running off a UPS – mainly so that if the power fluctuates (which is does, quite a lot) then we don’t break the power supply too much, and the link won’t go down (causing a lengthy rebooting process, and potential dead air).

Next to Tech Corner (also known as Rat corner, due to there being a dead rat lying there when we arrived), we have 2 edit stations, where the producers can download content from the recorder units we are using on the stage, and edit them for playout using Audacity.

And finally, the studio.

The studio consists of 4 mics, 2 mixers, a playout system, 2 CD decks and an outboard with compressors and a Saphire 90 sound card. We ended up using SAM Broadcaster for playout. There’s an area for guests in front of the desk, and 2 presenters behind it.

So far, the broadcast has been going beautifully – there was a power outage this morning (we think the main stage is using the same power feed as us, and the breakers tripped). After our Engineers moved the power over to a genny feed, we were back up and running.

I wasn’t actually on site today, however I will be there tomorrow and I hope to post an update from the pigshed!

Lounge on the Farm: Outside Broadcast for CSR (Part I)

July 6th, 2009

Since April I’ve been volunteering some of my free time to work with the Tech team at Canterbury Student Radio CSR FM (broadcasting on 97.4 FM in the Canterbury area, as well as streaming on the Internets). It’s great fun, and gives me lots of freedom to work on interesting projects.

So far, I’ve been involved in building Linux servers, helping maintain Windows Servers, writing perl scripts, doing analog circuit design, building an Asterisk PBX, customising Cisco 7960G IP Phones, as well as lots of other odds and ends.

CSR is going to be broadcasting from the music festival in Canterbury called Lounge on the Farm. This is quite a technical challenge, as you might imagine. Broadcasting from a farm in the middle of nowhere is quite tricky. I’ve been helping out with the preparation for the Outside Broadcast, which will be going live on air this coming weekend (11th -13th July 2009).

We built 4 Windows XP computers to use on Lounge on the Farm to do an outside broadcast for CSR

One for encoding, one for playout (using JAZZLER , apparently) and two with Audacity for audio editing.

300g disks are in the playout and edit machines. And shared with peer to peer file sharing. All set up so all machines can see all drives.

Job is what one might call a good ‘un.

Colour Code

May 25th, 2009

Something I came up with this afternoon with the help of Fluffy, and for a project that we’ll be doing in the somewhat near future.

It’s a code, using colours. See if you can crack it ;)