Posts

Showing posts from 2012

Using Audacity as an Oscilloscope

Image
A good oscilloscope is hard to afford. Spending money on a mediocre one doesn't seem to justify the stiff cost of even low-end scopes. In the meantime, I found a workaround! :-) Why did I need an oscilloscope? I've been wanting to crack my truck's keyless entry transponder code for a while now. I finally got around to it and succeeded with the help of a $5 315 MHz wireless receiver module from sparkfun.com, an old headphone cable, and a free audio editing program named Audacity. Below is a screenshot of the captured code:
With an old broken headphone (2.5 mm) jack, I connected the receiver's output to the input of my laptop. 
Note: This could be dangerous! Do not do this unless you know what you're doing. Connecting a high powered circuit to your computer's sound card will probably fry the sound card and your computer!  Once connected, I powered up the receiver from a USB port and hit record while simultaneously hitting the lock button on my truck transponder. …

Simulink on Arduino!

From the Mathworks website:

Run Simulink models on supported target hardwareSimulink provides built-in support for prototyping, testing, and running models on low-cost target hardware, including Arduino®, LEGO®MINDSTORMS®NXT, PandaBoard, and BeagleBoard. You can design algorithms in Simulink for control systems, robotics, audio  processing, and computer vision applications and see them perform with hardware. This hardware support is also available inMATLAB and Simulink Student Version.
http://www.mathworks.com/discovery/simulink-target-hardware.html?s_tid=hp_mi_edu-hw_0912

Once I get it working, I'll post a short tutorial.

Cool Matlab discoveries!

I just discovered two very neat and useful Matlab functions on http://people.csail.mit.edu/jskelly/blog/

1) Matlab has the ability to take a symbolic expression and convert it to Latex. I find this especially useful when I solve a complex problems and the output has a lot of different braces, etc. Simply render the Latex output and see the output more "Mathematically".

2) Matlab also has hash tables similar to Perl!

EDU>> variable = containers.Map
variable = 
  containers.Map handle   Package: containers
  Properties:         Count: 0       KeyType: 'char'     ValueType: 'any'
  Methods, Events, Superclasses
And adding values:
EDU>> variable('Peter') = 'Paul'; EDU>> variable
variable = 
  containers.Map handle   Package: containers
  Properties:         Count: 1       KeyType: 'char'     ValueType: 'any'
  Methods, Events, Superclasses

EDU>> variable('Peter')
ans =
Paul


The Sentients: Making an Exception

A quick story I had to write for my Mobile Robotics class. We had to write a Sci-Fi story involving a team of mobile robots.

Making an ExceptionA swarm of robotic creatures, known as Sentients, is the sustaining force behind our planet’s civilization. They are responsible for transporting and moving everything on the planet to its destination. They are small and modular, run off the energy transmitted by the sun, and have a device in them that cancels the planet’s gravitational effect on them. This allows them to fly very efficiently.
One Sentient could easily fit in the palm of one’s hand. It has a small hand like claw with full degrees of freedom in any direction. It looks like something between a human hand and the tentacles of an octopus. When larger deliveries were to be made, say for example delivering and moving a piano, dozens of Sentient robots would form an enclosing structure around the package, and in unison, pick the item up and deliver it to its destination.

These creatur…

Tracking an LED with OpenCV

Image
I have become very interested in using webcams to track objects and calculate their relative position in a space. My trusty friend OpenCV 2.4 came in handy. I used Harpia on Ubuntu 10.04 to generate some old, flaky code to track the green LED on an Arduino Mega. I pulled all the functions out of the Harpia code and put them in my own C program. (Code on Github shortly) Since LEDs have a pretty steady color, I took a photo of the LED with the webcam I was using, and then calculated the color value the LED was emitting. From this, I can output X,Y coordinates for the LED in the frame. Below is a quick video I made showing the tracking interface:


Gauss-Seidell Iterative Method for Power Flow Analysis

Probably the most exciting and interesting thing I learned this Summer in school is using the Gauss-Seidell Method to solve a Power Flow Analysis problems

The Matlab code below is posted on Git.

{edit} Code is not working. I get a slightly different answer than what I'm supposed to. I've got to run through it but I'm a bit too busy with school right now. :-)

Good Engineering Student Study Habits

One of the lessons any Engineering student learns is that no matter how smart you think you are, there will always be one or more classes that will force you to work hard. For most, that means most classes. Here are some lessons I've learned. They are common-sense, but not commonly followed.
Take Notes! Hearing, writing and seeing new concepts and information is crucial to learning. Pay attention, interact with the instructor, and take copious notes.Review. Review class notes every day some time after class. Every day you go to 3 or more technical classes learning things that you probably never imagined existed before. When you learn things in class, they are in your short-term memory, but with so much information to cram into your brain, much is easily lost without further review. A good practice is to create time slots for each class you attended each day and review your notes for that class. You'll find places where you didn't finish out a sentence or equation. Fill in t…

Estonian

Image
Our Electrical Engineering Department at Auburn University has a list service that they use to send out email notifications. Usually it's general stuff such as recruitment events, new classes opening up, etc. The other day, when I opened up an email from them, Google Chrome thought the email was in Estonian! See screenshot below... :-)


Computer Systems Class Notes 2012/04/16

Mon Apr 16 11:08:14 CDT 2012
Serial: • Serial transfer
– Single-bit Data Width
– Simpler Interface, less hardware • Transfer modes
– Simplex (only send or receive)
– Half duplex
– Full duplex • Asynchronous serial transfer (SCI)
– No common clock
– Each character is framed by a preceding ‘start’ bit, LSBÆMSB, and one or more
‘stop’ bits.
– “1 to 0” transition (following the stop (& mark) bits of 1) signals the beginning of a
character.
– High overhead since each character is framed individually. • Synchronous serial transfer
– Common clock
S
– Low overhead [SYN] [SYN] [STX] [pure data bytes] [ETX] • Interface -------------
----> | interface | ----->
-------------
Parallel data bus Serial data line – Conversion between ‘serial’ and ‘parallel’
– Framing
– Handshaking
• HCS12 Serial I/O
- Both asynchronous and synchronous serial I/O interfaces • Asynchronous Serial Communication Interface (SCI)
– UART UART (Universal Asynchronous Receiver-TT itt ) ransmitter) • Sy…

Computer Systems Class Notes 2012/04/11

Wed Apr 11 11:02:35 CDT 2012Memory:
A15 A11 A7 A3 A0
chip 0 address range: $0000 - $0FFF (0000 0000 0000 0000 ->
0000 1111 1111 1111)
chip 1 address range: $1000 - $2FFF (0001 0000 0000 0000 ->
0001 1111 1111 1111)
chip 3 address range: $2000 - $3FFF (0011 0000 0000 0000 ->
0011 1111 1111 1111) A15-A12 Decoder Enable
A11-A08 Chip Select
A07-A00 Address within a chip |==========| |==================|
A13------------|1A 1Y0|o----------|A11-0 D7-0 |
A12------------|1B 1Y1|o-----| | |
| 1Y2| | |CS(bar) R/W(bar)|
==== | 1Y3| | ==================
A15--| OR |----|1E | |
A14--| | | | |
==== | | |
==========
Alas, drawing in ASCII isn't very efficient...moving on... 16-bit uprocessor (16 address bits A15-0)
The data bus is 8-bits wide. (…

Computer Systems Class Notes 2012/04/09

Mon Apr 9 11:02:24 CDT 2012
# Memory Systems:
Memory System Hierarcy
-Disk, ROM, RAM, Cache
# Memory module (chip) org.
- On-chip (address) decoder, cell array
Address Decoding
# Memory Remapping
# Memory Expansion RAM (Random Access Memory) ROM (Read-Only Memory) Types of ROM:
* Mask-programmed ROM (MROM)
-factory set.
* PROM (Programmable ROM)
-fuses --irreversable
* EPROM (Erasable PROM)
-erases with UV light
* Flash EPROM
-usec-faster --erase block by block
* EEPROM (Electrically Erasable PROM) RAM: Static and Dynamic
* Static
-Each cell is a flip-flop storing 1 bit of info. * Dynamic RAM
-Each cell is a capacitor...needs to be refreshed periodically to retain the 1-bit info.
-Cheap
-A refresh is accomplished if you read and then write back.
Refresh overhead 4 Mbyte DRAM: refreshed 4 msec
(2048 * 80e-9) / 4e-3 = blah RAM Structure:
- Select
- Data In
- Data Out
- R/W
- 1-byte contains 8 memory cells.
- Common data lines such as Select and R/W.
- Wit…

Innovative Humanitarian Products Organization

I am able to proudly say I'm part of the IHPO (Innovative Humanitarian Products Organization). We design and develop products that are cheap and able to make a difference in the developing world. Our first product was an electrical device (our founder, Grant Moore is an Electrical Engineering student), which uses salt water to make chlorine for sterilizing water, etc.

We are currently entered into a competition to win $5000 and need everyone's help. The competition gives $10,000 for the presentation with the most views, and $5000 for the 2nd - 5th places. We are currently in 5th place, but to solidify our win, we'd still love as many views as possible. Watch the presentation below or click the link:

http://portal.sliderocket.com/BMNDW/IHPO

Computer Systems Class Notes 2012/03/26

Mon Mar 26 11:04:47 CDT 2012 IT_Keyboard
Lines 1
Coum 8
And last option: 6 Not on exam:
*Direct memory access controller.
*LCD information Important:
* Sect 4.3 Write Subroutine which parameters are passed via registers, memory, and stack. * Address passing: diff between passing a value -vs- and address.
Difference between passing data and addresses (4-3-4).
* Sect 4-2: What happens when we use subroutine instructions when bsr/jsr/rts are executed.
* Never jump out of a subroutine using branch instructions.
* Implement the following C-code in assembly:
// (from Chapter 3):
while( m < n ) {
k = k+1;
if(k > 5){
m=k^2;
}else{
m=n/4;
}
// assume m,n,k are unsigned.
// assume all fit in 8-bits.
while:
ldaa m
cmpa n
bhs done
inc k ;k=k+1
ldaa k
cmpa #5
bhi k-gt_5
ldaa n
lsra
lsra
staa m
bra while k-gt_5:
tab
mul
stab m
bra while done:
** Write a program to compute the following functions: var1 = minimum(4l,5)
var2 = maximum(4l,10)
whe…

Computer Systems Class Notes 2012/03/21

Wed Mar 21 11:47:05 CDT 2012
main:
Enable the timer (TSCR1)
clear the TOF (TFLG2)
Perform operations (toggle and LED)
call delay
loop
delay:
Init a counter (# of TOF)
Wait for TOF (TFLG2)
Reset TOF (TFLG2)
Decrement counter
Return

Keep track of your IP address and internet connectivity

Below is some code I wrote to email me whenever my computer's IP address changes and log it to a file. I nifty side effect is it keeps track of when my internet connection is down as well. Copy this code and insert your own email address and run on a schedule such as cron.

No post for today's Computer Systems

We covered the all to crucial and important interrupts in Computer Systems today but alas, I was still occupied with Digital Electronics and the wonderful and sometimes mysterious world for transistors and couldn't take real good notes. For my own review and the benefit of the world, I'll write up a summary of HCS12 interrupts when time permits. Sorry...

Using Google Command Line Tools to post my Computer Systems Notes

Below is some code I wrote to post my Computer Systems notes online every day after class:


  1 #!/usr/bin/env perl
  2 use strict;
  3 use warnings;
  4 
  5 unless(defined $ARGV[0]){
  6    print "$0 [file to post]\n";
  7    exit;
  8 }
  9 my @date = ($1,$2,$3) if $ARGV[0] =~ m/Computer_Systems_(\d{4})(\d{2})(\d{2}).txt/g ;
 10 my $title = "Computer Systems Class Notes ".join('/',@date);
 11 my @infile = `cat $ARGV[0]`;
 12 my @template = `cat blank.html`;
 13 # Get rid of blank lines...
 14 my $tmp = pop(@infile);
 15 while($tmp =~ m/^\s*$/g){
 16    $tmp = pop(@infile);
 17    #print "tmp got $tmp\n";
 18 }
 19 push(@infile,$tmp);
 20 open(FH,">$ARGV[0].html");
 21 foreach(@template){
 22    if(m/{{{TITLE}}}/g){
 23       $_ =~ s/{{{TITLE}}}/$title/g;
 24    }
 25    if(m/{{{BODY}}}/g){
 26       $_ =~ s/{{{BODY}}}/@infile/g;
 27    }
 28    if(m/^\s*$/g){
 29       next;
 30    }
 31    print FH "$_";
 32 }
 33    close(FH);
 34 #  
 35 print "goog…

Class Notes 2012/02/13

; #1 Write a program to compute the following
;A1 = (B1 - C1) - (D1 + 8)

;Use only direct/extended addr. for all memory references.

ldea B1; A=B1
suba C1 ; A = (B1-C1)
ldab D1 ; B = D1
addb #8 ; B = (D1 + 8)
sba ;
staa A1 ;

;Use only constant offset indexed addr. for all memory references.

ldx #A1
ldaa 1,x ;A=B1
suba 2,x ; A=(B1-C1)
ldab 3,x ;B=D1
addb #8 ;B= D1+8
sba ;A=(B1-C1) - (D1 + 8)
staa 0,x ; staa x


;Use auto-increment indexed addr. for all mem references.

ldx #A1 ;
ldaa 1,+x ; A = B1
suba 1,+x ; A = (B1 - C1)
ldab 1,+x ; B = (D1)
addb #8 ; B = (D1 + 8)
sba ; A = (B1-C1) - (D1 + 8)
staa 3,-x ; A1 = A


;Use register offset indexed addr. for all mem references.
ldx #41
ldab #1
ldaa b,x ; A = B1
ldab #2
suba b,x ; A = (B1 - C1)
ldab #3
suba b,x ;A = (B1 - C1) - D1
suba #8 A = B1 - C1 - D1 - 8
ldab #0
staa b,x A1 = A

;Define 2 20-byte arrays,
; 1) Copy one byte at a time, using indexed add…

Class Notes 2012/02/10

ORG $800
vec1 dc.b 1,2,3,4,$FF
vec2 dc.b 0, $FF, 3, 5, $80
count ds.b 1
ORG $4000
ldx #vec1 ; x->vec1
ldy #vec2 ; y -> vec2
ldab #5 ; init loop counter
clr count ; clears the count
loop: ldaa 1,x+ ;vec1[i] -> A
cmpa 1,y+ ;compare vec1[i] with vec2[i]
blt next ;if vec1[i] < vec2[i] then branch
inc cont
next: dbne b, loop dec. loop counter + branch if it's !=0

Next example: Write a program to compute the dot product of vectors a + b. Assume the vectors contain unsigned 8-bit values and ignore any carries...

a (dot) b = sum from i to n of a_i*b_i = a1*b1 + a2*b2 + ... a_n*b_n

; Variables
vecA ds.b 5
vecB ds.b 5
result ds.w 1
counter ds.b 1

; Code
ORG $4000
ldx #vecA
ldy #vecB
movb #5, counter
movw #0, result ; We move word because multiplying two bit numbers results in word (???)
loop: ldaa 1,x+
ldab 1,y+
mul
addd result ; Goes into register D
std result ; Put the result stored in D back into result.
dec counter

Class Notes 2012/03/02

Rewrite find-min to pass parameters via the stack ORG $0800
array ds.b 5
min ds.b 1
ORG $4000
lds #$1000
ldx #array
pshx
ldab #5
pshb
bsr find_min
pula
staa min
leas 2,SP ;clean up the stack... find_min:
;Finds the min value
; Registers modified:
Variables modified:
Input parameters:
; addr of array: SP + 2
; lenth of array: SP + 3
;Output parameters:
; min value:
ldx 3,SP ;x -> addr of array
ldab 2,SP ;B = length of array
loop:
; compare + loop;
; what we did in previous example...
; see find_min sub from Wednesday.
dbne b,loop
staa 2,SP
rts ; | |
; --------
; | |
; --------
; |return| <--SP
; --------
; |addr. |
; --------
; |length| <--SP + 2
; --------
; |addres| <--SP + 3
; --------
; |of arr|
; --------
; | | $1000
; --------
; | |
; --------
Review of HW 7:
lmax = min(7,2l)
lmin = max(0,2l-7) B(2): lmax = min(7,4) = 4 B(4) = %0001 0000
lmin = max(0,-3) = 0 B(0) = %0000 0001
B(6): lmax = min(7,12) = 7 B(7) = %1000 0000
lmin = …

Class Notes 2012/02/17

; ASCII to packed BCD
; 1 3 5 8 7 6
; $31 $33 $35 $38 $37 $36
;
; |$31| <= ASCII
; |$33|
; |$35|
; |$38|
; |$36|
; |$13| <= PBCD
; |$58|
; |$76|
; | |
; | | ;Code:
ASCII dc.b '125876'
PBCD ds.b 3
count ds.b 1 ldx #ASCII
ldy #PBCD
movb #3,count ; initializes the loop counter
loop:
ldaa 1,x+ ; gets 1st char
lsla ; shift left
lsla ; shift left
lsla ; shift left
lsla ; shift left
ldab 1,x+ ;get next character
andb #$0F ;AND it with %0000 1111, which leaves us with the least signif bit of next character
aba ;add B to A
staa 1,y+ ;store in PBCD
dec count ;decrement loop counter
bne loop ;branch if != 0 ;================================================================
;HW #5
;The array "sample" contains 8 8-bit signed binary numbers (integers) as shown below. Write a program which computes the sum of positive numbers and the sum of negative number, and stores them in psum and nsum, respectively.
;It also computes the su…