Wednesday, 22 February 2012

Sugru: So, what to do with it?

Some time ago I decided that I'll need to look and test this relatively new material called Sugru. In simplified terms, it's yet another kind of moldable plastic. I would say it is kinda like self curing silicone, freshly out from the bag it's soft to handle and sticks well to various materials. During some hours at the room temperate, it will dry and Sugru become rubbery like material. There are no resellers at this part of the world so I ordered my first 12 minipacks directly from manufacturer.

Packing is functional, and in a way these aluminium bags do look kinda stylishly futuristic and flashy. Outermost was the normal brown envelope (with address label), inside it a single bigger aluminium bag with ziplock. Inside this bag were twelve 5gram packages of Sugru (assorted colours) and short instruction and inspiration booklet for helping one to get started.

I really like their slogan "hacking things better", it tells a lot about the attitude this startup company works. Their website has plenty of user posted pictures and stories how this new material has helped these people. 

For myself, I have not yet decided what to build/hack with this first, but I allready have some ideas so I'm quite sure I'll be able to use all these packs while the material is fresh. Even though the Surgru is well packed to those individually sealed aluminium foil packs, it will stay fresh only about six months. So, expect to see something more interesting coming with Sugru on it.

Friday, 3 February 2012

Living in Freezer, or Got the package, 2032 batteries and other neat things.

Sorry.. It's been way too long time without updates, I'll try to be more punctual. Freezer related stuff will be At the end.. Just have to put one picture for a teaser.



The parts I ordered at the end of December have finally arrived. I'm sure I could have sourced most of them locally, but the price of projects could have raised a lot. The most important was the 20-pack of 3032  lithium batteries (under  3€) and single lens sunglasses  ... (these links open sellers page on new window, go see them. I'll wait here).

I'm sure someone clever reading this post may well guess what's I'm building, but if you'll comment this project, please don't spoil until I have the prototype made. I will then shoot a video of it, though I may need to find someone volunteering to be front of the camera :-)

According the feedback on sellers page, there can be some duds amongst those 3032 batteries. So I checked the voltages with a multimeter and they seem to varies between 3.1 to 3.4 volts. According the typical data sheet (pdf file) these voltage levels indicates these batteries are essentially new. The first voltage drop at the begin is really sharp and the nominal battery voltage is 3 volts.

During the use the battery voltage will keep  relatively steady around 2.9V until at the end voltage sinks rapidly towards 2.0V which is the official cutoff voltage. So, these batteries are just perfect to use with low power microcontrollers without need of any voltage regulation. And with low enough static power drain, there's not even need to add any kind of power switch at the circuit.

--- And Back to Freezer part.. These photos are taken with my trusty old E-510 digital SLR with Zuiko 14-54 lens. That does not sound like worth mentioning, until I remind that lately we have been having temperatures between -20 to -29 Celsius (-4 to -20 Farenheit) and I spend 2 hours finding the right shots. These images are Straight-from-camera Jpegs, with no post processing (website does scaling).


First two pictures are from University campus area and the last one from city harbour.






Wednesday, 18 January 2012

Timer Interruptus...

Slowly but steady goes the progress.I have now added Timer 2 interrupt handler and real time (1ms accurate) clock to my code. With this timer system I don't need to use busy looping for time keeping and I can later adjust the system for other real.time needs.

There are two important key parts to consider at this version of program. The interrupt service routine and the Timer2 initialization routine.

The interrupt service routine itself consists of three parts. At beginning, it saves the W and STATUS registers so that those can be used at interrupt without distrupting the main program. I have selected unbanked RAM (at 0x70-0x7f) for storage cause those ram locations are always available. Also it's essential that these same registers are restored before returning from the interrupt handler.

Middle part of the routine looks quite a simple for now. There is just increment of the multibyte millisecond counter and reset of timer interrupt flag. This code will grow at the future depending what applications I'll make with this micro controller.

Next likely parts will be implementing interrupt based software serial port, transmitting for debug purposes. Most likely I'll use 9600bps and try to keep the code minimal. After that the next possible direction is to make test routines for the A/D converters.

After those.. I hope I'll have all the parts for an application I've been wanting to make for some time now, the parts are in Slow-mail coming from another side of the earth so there is no  telling when they manage to appear.

--- Cut here.. Code follows

; minimal -led blinker
; V2 with Timer2 interrupt

; Uses Timer2 to generate 1ms timer interrupt

;PortC pins:
; RC:0 = digital out, led active high

  #include p16f616.inc 
  __config _INTOSCIO & _WDT_OFF  ;   8 Mhz int-osc with IO:s
      

 ; define Data memory
inner equ 0x20
outer equ 0x21
 
 ; Bank shared memory (0x70-0x7f) used for Interrupt
 ; Interrupt backup registers
int_w          equ 0x70
int_status     equ 0x71
int_pclath     equ 0x72 ; not yet used at interrupts
int_indf    equ 0x73 ; not yet used at interrupts

 ; Debug serial port (Note.. buffer location not yet determined
ser_tx        equ 0x74  ; Zeroes reg after send
ser_rx        equ 0x75  ; 0 = no data
ser_status    equ 0x76  ; Todo! ; Define modes/error codes


 ; 24-bit ms tick counter (allocation for 32-bit int)
ms_32     equ 0x7c
ms_high equ 0x7d
ms_med  equ 0x7e
ms_low  equ 0x7f
               
  ; Start from reset vector
  
  org 0x00 ; obvious, but just in case.
  goto Main ; Skip over interrupt vector

  org 0x04 ; Interrupt vector
Intserver
  ; Save W, STATUS  (3 cycles)
  movwf int_w
  swapf STATUS,W ; only way to move status without affecting the Z-flag
  movwf int_status

  ; Real interrupt routine (remember to clear the interrupt)
  ; note: We have no idea about status flags (including RP0)
  ; Since this interrupt happens every 2000:th cpu clock, we'll just
  ; increment the ms-counters 
  movlw 0x01
  addwf ms_low, F
  btfsc STATUS, C ; if carry not happen skip increment
   addwf ms_med, F
  btfsc STATUS, C ; if carry not happen skip increment
   addwf ms_high, F
  bcf PIR1, TMR2IF ; Clear interrupt 


Intserver_end
  ; Restore W, STATUS and return from int (6 cycles)
  swapf int_status, W
  movwf    STATUS 
  swapf int_w, F
  swapf int_w, W  ; return W without messing with Status flags   
  retfie ; return with interrupts enabled.

  org 0x100  ; main program
Main
 ; Init IO ports
  BCF STATUS,RP0 ;Bank 0
  CLRF PORTC ;Init PORTC
  BSF STATUS,RP0 ;Bank 1
  CLRF ANSEL ;digital I/O  (disable Analog Inputs)
  MOVLW 0xFE ;Set RC<5:1> as input
  MOVWF TRISC ;and set RC<0> as outputs
  BCF STATUS,RP0 ;Bank 0

 ; Init Timer2 and real time clocks
  movlw 0x00
  movwf ms_high
  movwf ms_med
  movwf ms_low
 
 ; Sample of Timer2 settings for various interrupts at 8MHz xtal.
 ; Values in decimal.
 ; Clk    PR2    Pre    post    Usage
 ; 2000    125    16    1        1ms timer for real time system clock
 ;  208    208     1     1         9600 bps Tx async debug serial
 ;   69  69     1    1        9600 bps Rx async debug serial (3* subsample)
 ; Last one will tax system badly

 clrf TMR2
 bcf PIR1, TMR2IF ; Clear interrupt (should be anyhow)

 bsf STATUS, RP0 ; Bank1
 movlw 0x7d ; 125 decmal
 movwf PR2
 bsf PIE1, TMR2IE ; Allow timer2 interrupt.
 
 bcf STATUS, RP0 ; bank0
 movlw 0x06 ; Prescaler *16 + OscOn. 
 movwf T2CON ; Set t2 scalers + start the timer  
 bsf INTCON, PEIE ; Enable periferal int
 bsf INTCON, GIE ; Global interrupt enable
 

Loop
  movf  ms_med,W 
  movwf PORTC    ; Blink period of 512 ms

  goto  Loop             ;Do this repeatedly

  end                    ;All things must end someday