Tuesday, 26 February 2013

Measuring inductances using an arduino


I just read this excellent article about measuring inductances:

http://reibot.org/2011/07/19/measuring-inductance/

The technique consists in measuring the resonance frequency of a LC circuit. Since this frequency is:

f = 1.0/(2.0*M_PI*sqrt(L*C))

By measuring f with the arduino and knowing C you can easily get L.

I modified the code so its much more precise, the original code is using 'pulse' to read half an oscillation. My code instead measures one whole oscillation by using an AVR's hw feature called Input Compare, this feaure starts and stops a timer that runs at 16Mhz.

Enjoy!


//measuring inductance using the higher precision input compare  
//based on http://reibot.org/2011/07/19/measuring-inductance/  
//capture Flag  
volatile uint8_t Flag;
void InitTimer1(void)
{
    cli();
    //Set Initial Timer value  
    TCCR1A = 0;
    TCCR1B = 0;
    // Input Capture Noise Canceller  
    TCCR1B |= (1 << ICNC1);
    //First capture on rising edge  
    TCCR1B |= (1 << ICES1);
    //Start timer without prescaller  
    TCCR1B &= ~ ((1 << CS12) | (1 << CS11) | (1 << CS10));
    TCCR1B |= (1 << CS10);
    //Enable input capture and overflow interrupts  
    TIMSK1 = 0;
    TIMSK1 |= (1 << ICIE1) | (1 << TOIE1);
    Flag = 0;
    sei();
}
volatile uint16_t Capt;
volatile uint16_t T1Ovs2;
//capture ISR  
ISR(TIMER1_CAPT_vect)
{
    if (Flag == 0)
    {
        //reset overflows  
        TCNT1 = 0;
        T1Ovs2 = 0;
    }
    else if (Flag == 1)
    {
        Capt = ICR1;
        //disable capture and overflow interrupts
        TIMSK1 &= ~ ((1 << ICIE1) | (1 << TOIE1));
        //clear pending interrupts  
        TIFR1 = (1 << ICF1) | (1 << TOV1);
    }
    //increment Flag  
    Flag++;
}
//Overflow ISR  
ISR(TIMER1_OVF_vect)
{
    T1Ovs2++; //increment overflow counter  
}
//13 is the input to the circuit (connects to 150ohm resistor)
//8 is the comparator/op-amp output.   
//reibot.org for guide  
double pulse, freq, inductance;
//insert capacitance here. Currently using 2uF  
double capacitance = 2E-6;
void setup()
{
    Serial.begin(115200);
    pinMode(8, INPUT);
    digitalWrite(8, LOW);
    pinMode(13, OUTPUT);
    Serial.println("Why hello!");
    delay(200);
}
void loop()
{
    digitalWrite(13, HIGH);
    delay(10); //give some time to charge inductor.   
    digitalWrite(13, LOW);
    delayMicroseconds(15); //make sure resonance is measured  
    InitTimer1();
    delay(100); // wait for ICR to read once cycle  
    pulse = (T1Ovs2 * 65536 + Capt) / 16.0;
    if (pulse > 0.1)
    {
        freq = 1.E6 / pulse;
        inductance = 1. / (capacitance * freq * freq * 4. * 3.14159 * 3.14159);
        inductance *= 1E6;
        Serial.print("High for uS:");
        Serial.print(pulse);
        Serial.print("\tfrequency Hz:");
        Serial.print(freq);
        Serial.print("\tinductance uH:");
        Serial.println(inductance);
        delay(20);
    }
}

Sunday, 3 February 2013

SMD if there is a will there is a way

I couldn't wait for my breakout boards to arrive! I hope this encourages others to do some smd soldering... I used some rosin soldering flux from radio shack and a regular solder.

SMD breakout board

Wednesday, 16 January 2013

Virtual MSX disk drive


When I was a kid I had an MSX, a SVI-728 to be more precise, it's just a Z80 based computer with 64Kb of RAM. Mine used cassette tapes to load games and the loading times were eternal not to mentioned all the loading errors that required restarting the load from the beginning.

Other friends of mine had an MSX with a disk drive but I got still stuck with the tapes :-(

So... Revenge! I decided to build my own disk unit :-)

MSX's with a disk drive come with a disk BIOS that handles all the disk operations, from the lowest level (i.e.: read sector 23) to extending BASIC with new commands to list the available files in the disk, formating, deleting and creating files, and so on.

My first step was to get a disk BIOS from a MSX with a disk unit and patch the sector reading/writing routine so instead of talking to a disk unit, it would talk to another device, an Arduino.

Unfortunately I can't fit an 720Kb disk in an Arduino but since it has a USB connection it can ask my PC to get that sector form an certain disk image in my PC's hard's disk and send it thought the USB cable.

For that I need some gluing hardware between the MSX and the Arduino, here is the pic of the setup

Breadboard with arduino-msx gluing logic

And here are the schematics of the interface:


Schematics

The trick of the trade

It all works thanks to the Z80's /WAIT pin, when an IN or an OUT instruction happens for an port below 31 the logic gates put this pin to a low sate making the Z80 wait, the Arduino notices that and can fetch the data from the computer and put it onto the 74245 buffer, then the Arduino will raise the /WAIT pin to make the Z80 resume the execution so the OUT instruction gets the data from the buffer.

The software bit on the MSX side...

My computer didn't have a disk BIOS so I had to get one, fortunately Arjen Zeilemaker had disassembled some and put the asm code in sourceforge. All I had to do was to write the DSKIO function to talk with my arduino, the code was so simple that I just used notepad and worked on the second run. I took a game cartridge and replaced the game's ROM with an 16Kb EEPROM I got from EBAY. As for writing the EEPROM I used a reader/writer I built once as a quick hack, I used for that a ATMEGA128 since it has enough pins to driver teh 28 pins you need to set in order to write or read an EEPROM.

Simple flash memory reader on the top, game cartridge on the bottom

The two white cables sticking out of the Atmega128 are the serial port, I wont tell what are the black and red ones :-)

..and on the PC side

I just used Python to read the commands coming from them MSX, the script will take the 512 bytes sector and will send it to the arduino and 1Mbit per second. The Arduino will send byte by byte to the Z80 at a similar speed.


Here is the video, sorry for the shaky hand :-) On the left you have the python script, on the right VLC media player.



Source code! :)


Ok here are the sources, sorry I didn't document the code so much, please let me know if you have any questions.
https://docs.google.com/file/d/0B4IJZPdCtzO0OGJvcnB3U0xnY1U/edit?usp=sharing

Thursday, 6 October 2011

DIY Linear actuator out of scanner parts and a drawer slider

To build this linear actuator I stripped off from a scanner the motor + gears along with the timing belt and the pulley. I bought in Brico a cheap drawer slider and screwed it all into a piece of wood.

First the video showing off what all this is about




Below you can find a pic of one end of the actuator:

IMAG0336


As you can see, I attached the stepper to the piece of wood by just using a wire, and it works great!
Also note that zigzag piece of metal that links the timing belt with the drawer rail. In the picture below you can see it in more detail

IMAG0337


The timing belt is sandwiched between two pieces of metal.

And finally below you can see the pulley at the other end, this was a tricky part, keep reading more the details!

IMAG0338


This pulley had an axis that was riveted to the chassis of the scanner, I pulled it off with my pliers and welded it into a screw using solder, I had to heat both parts for a long time before in order to get the solder to bind both parts, the picture below shows the results:

IMAG0344


And voila, its working better than I expected! Keep tuned for more and thanks for reading!

BTW greetings goes to the guys in timelab for inspiring me!

Saturday, 17 September 2011

A Pre Amp for an electric guitar

I bought an electric guitar and needed an amp, I thought is was kind of silly to buy one since I could use my computer speakers. You cannot connect the guitar to the computer amp directly since the signal coming from the guitar is too weak, you need a preamp.

I had a bunch of 741 op amps around and decided to build a preamp myself. I used a inverter amp configuration (quite a simple one) and it worked great. By cranking up the gain by a lot I get a nice heavymetal distortion.




Here is the schematic along with a link to see it running in a free java circuit simulator.





The only problem is that the preamp seems to amplify too an FM radiostation and I can hear some nice music while I play guitar....

At the beginning I thought my guitar was haunted by The Beatles and played on its own, when I hard a kind of a voice I suspected it could be receiving some sort of radio signal.. 

 You don't believe me? Check out this video! 






Gameboy Cart Using an AVR

Built a Game Boy flash cart using an AVR. Took a cartridge I bought for a few euros and replaced the ROM chip with a 32Kb RAM I took from a printer. The pinout of most RAM, ROM and EEPROM chips are almost the same, I was quite glad about this :-)

The next step was to find a processor that had many free pins to drive the 15 for the address bus and 8 for the data bus, for that then I used and AVR128.



If you look at the cartridge 'pins', you'll see a cable soldered to one of them, that is the HALT line of the Z80, controlling this pin I can freeze the Z80, this way the data and addresses buses are free and my AVR can write and read data from my RAM.



This is how the whole setup looks like once connected, the big chip is the AVR .

I can write programs in the RAM in two ways:

1) Connecting the AVR to my computer through a serial port and use a little loader to upload apps.
2) Write the app I want to upload in the AVR's flash and have it write it to the RAM when the Game Boy is turned on.

So, bottomline :-) It worked for small apps < 16Kb but it didn't work for bigger apps, so I think this post will have a second part someday, stay tuned!

Tuesday, 12 October 2010

How to get support for the Arduino oscilloscope (and Parallax),

We now have a forum, please ask your questions there!

http://groups.google.com/group/xoscillo

Thanks!