A long week of mouse hacking and projects

I’ve been a little busy on the workbench lately. I’ve been working late at the-day-job so I’ve been neglecting my workbench notebook and my blog for most of this week. I’ve got a ton of “fun” stuff planned for this weekend; no way I’ll get it all done.

I won’t make you read through the whole post if I pulled you in with mouse hacking 😉

I am a poor gamer.. give me a cheat code and I’ll use it. I have no shame in gaming. Adam Fabio recently got me slightly addicted to ClickingBad … I refuse to link it, don’t search for it.. it’s a god-awful time suck. I clicked a freakn’ mouse for 90 minutes straight… Well screw that. I pulled out one of those el-cheapo USB mice you get with a refurb computer… the $5 throw-away kind. I popped it open and as luck would have it little microswitchs on a single sided PCB. Well 2-1/2 minutes later I had soldered wires to the switch contacts, dumped them on the normal open contacts of a small relay,  hooked it up the relay coil to my MOSFET driver (yes, way overkill, it was laying there already), and threw it under a PIC. I used a rate of 70 ms off 40 ms on.. I probably could have sped that up but it was at that warp speed, I was happy. Did it take away from the game? Nah, I had that much more to buy! I was shocked the relay held out for a few days of being hammered (“Batches hand-cooked: 1.01Q” , that’s not a quadrillion clicks, but it was a lot regardless). I pulled my cheat-clicker off after a while because the super-fast click of the relay was getting pretty damn annoying. I had little bug in the system: a little phantom drift issue with the el-cheapo mouse so turned down pointer sensitivity to as slow as possible; That allowed for a couple hour stretch of non-stop cheating.

Mouse Click Hack

Continuing on with actual electronics projects: I have five active projects I’m working on, a few I’ve recently benched waiting on a big purchase, trying to get other stuff out of the way or for other reasons.

1. Video Synth … Lawrence has inspired me to help him build a Video Synth. I’ve gotten a fair amount of reading done. Looks like I’m going to need a spectrum analyzer for some filters I want to build (awww darn! heh). I’ve gotten some boards finished which I needed for other projects but just happened to work for this one as well.

 

Sweep Generator -- Opps I forgot something
Sweep Generator — Opps I forgot something

… version 2.0 of these boards in at the fab. I’ll probably sell some of these for people needed a quick sweep generator for their VCOs, etc.

 

2. Workshop Time Standard  — Just started this because I got most of the parts in. This will be powered by my MikroElectronika PIC clicker and GPS2 click…. Stay Tuned.

3. WWVB for non-US persons… Edward contacted me about using my WWVB project but to actually broadcast the correct time. Well, fair enough. This has gotten me to buy all the stuff I think I need to create a PIC NTP client, GPS NMEA input .. and then the easy part. Broadcast it on 60KHz… I’ll have some kind of notice you should do this in a lead box under the ocean. I certainly wouldn’t sell this to someone within the US. I don’t think the FCC has any rule that allows a person to broadcast any tiny amount of power on 60KHz, certainly not intentionally. I didn’t find anything I thought I’d be safe under Part 15. I’d love to be proven wrong on this.. really.

4. My electric scooter. I just got a welder … now for some more material. Most of the electronics are done-enough until testing.

5. My ESR meter… waiting on parts of course.. come on Customs.. let me have my fun-stuff.

… all this work has left me bench a disaster zone.

 

The Great Mess of April 2014
The Great Mess of April 2014

 

.. I’ll finally leave you with this fun photo:

Ohm's law
Ohm’s law

Project: MOSFET Driver v1 (Product?)

Today I received the first of a couple batches of PCBs from OSH Park. This set is a simple MOSFET w/ driver. The MOSFET can be logic level driven and all my testing was done at 5VDC however the driver had a wide voltage range so running this at 9V or 12V should present no issues (16V max! VGS). I do have a few minor adjustments I want to add (silk screen additions and adjustments). I built this board as an electric scooter motor drive and I tested it with the motor I was interested in using and thankfully all testing worked out well including loading my power supply at max load for over an hour straight 🙂 This board can be used for an assortment of load control applications.

MOSFET Driver v1

The build was easy enough, next board I think I’ll just skip the chipquik and stick to straight soldering iron… and I think I also “figured out” the trick to solder the heat sink without making too much of a mess.

MOSFET Driver v1

I tested the load for 60 minutes at 66% duty cycle and 1.5KHz PWM with total load at 140watts (45Volts 3.1 Amps)..  the heat sink temperature on the MOSFET raised from ambient (78 deg F) to 90.7 deg F (32.3 deg C) steady for an hour.  The MOSFET is rated for 55V (max) at 30 amps but the board isn’t designed to handle that load. I used 50mil power traces which is roughly 3 amp handling according to the google machine; 5A if you don’t mind a 40 deg C rise (though there is a fan) so I’ll call this a 140W MOSFET board (47×3). I personally feel I could squeeze more current out of this in short bursts but I would need to do more testing.. and I can’t promise anything along those lines. The PWM signal was generated and directly fed from a PIC 18F16K22 microcontroller running @ 5V. You’re NOT going to be able to drive this at 3.3V.

 

Fresh off the soldering iron!
Fresh off the soldering iron!
Driving an electric scooter motor. Note the diode for flyback near the bottom of the photo just hanging out. The flyback is a must in this application.
Driving an electric scooter motor. Note the diode for flyback near the bottom of the photo just hanging out. The flyback diode is a must in this application.
MOSFET PWM signal vs VDSS
MOSFET PWM signal vs VDSS

 

I will likely stick a 75VDSS MOSFET in the next revision…

.. I’m considering selling these on Tindie. If you’re interested in getting on of these “BETA” boards at cost let me know before they’re gone.

PIC 18F26K22 PWM+A/D with MOSFET, the start of an eScooter?

I’m considering building an electric scooter; considering it probably putting it lightly.. I have almost everything I need for it.  Interested? Why type so much when you can just watch my proof of concept!

If you’re following along and want to use the same hardware (warning totally untested… ):
Controller found on the TAUTC Tindie Store
Search on eBay for “24VDC scooter motor” ..
..and pick up a MOSFET that’ll pull off a couple 20 amps and saturates at or below 5VDC.
…what am I talking about? Try google or read this.

To the important stuff, the code:


/* 
 * File:   main.c
 * Author: Charles M Douvier
 * Contact at: http://iradan.com
 *
 * Created on March 27, 2014, 4:12 PM
 *
 * Target Device:
 * 18F26K22 on TAUTIC Dev Board
 *
 * Project:
 * Electric Scooter
 *.. a real hack job, comment, delete garbage, etc.
 *
 * Version:
 * 0.1
 *
 */
#ifndef _XTAL_FREQ
#define _XTAL_FREQ 4000000 //4Mhz FRC internal osc
#define __delay_us(x) _delay((unsigned long)((x)*(_XTAL_FREQ/4000000.0)))
#define __delay_ms(x) _delay((unsigned long)((x)*(_XTAL_FREQ/4000.0)))
#endif

#include 
#include 
#include 
#include 

//config bits
#pragma config FOSC=INTIO67, WDTEN=OFF, PWRTEN=OFF, CP0=OFF, CP1=OFF, BOREN=ON
#pragma config STVREN=ON, LVP=OFF, HFOFST=OFF, IESO=OFF, FCMEN=OFF

//WRT=OFF, FOSC=INTOSC, MCLRE=ON

#define _XTAL_FREQ 4000000 //defined for delay

//clean up on isle 2.. 

    int     an9_value;          //value for a/d
    char    buf[10];            //buff for iota
    long int    fvar;           //long for format math
    long int    tens;           //left of decm
    long int    decm;           //decimal places
    int     tempi;              //to add leadign zeros..
    int     vtxdata;             //volts int for TX
    int     itxdata;

    volatile unsigned int uart_data;    // use 'volatile' qualifer as this is changed in ISR
/*
 * 
 */
void interrupt ISR() {

    if (PIR1bits.RCIF)          // see if interrupt caused by incoming data
    {
        uart_data = RCREG;     // read the incoming data
        PIR1bits.RCIF = 0;      // clear interrupt flag
    }

}

void init_io(void) {
    TRISAbits.TRISA0 = 0; // output
    TRISAbits.TRISA1 = 0; // output
    TRISAbits.TRISA2 = 0; // output
    TRISAbits.TRISA3 = 0; // output
    TRISAbits.TRISA4 = 0; // output
    TRISAbits.TRISA5 = 0; // output
    TRISAbits.TRISA6 = 0; // output
    TRISAbits.TRISA7 = 0; // output

    ANSELA = 0x00; // all port A pins are digital I/O

    TRISBbits.TRISB3 = 1; // AN9
    TRISBbits.TRISB4 = 0; // RB4 = nc
    TRISBbits.TRISB5 = 1; // RB5 = nc
    TRISBbits.TRISB6 = 0; // RB6 = nc
    TRISBbits.TRISB7 = 0; // RB7 = nc

    ANSELB = 0b00001000;     //RB3, AN9

    TRISCbits.TRISC0 = 0; // output
    TRISCbits.TRISC1 = 0; // output
    TRISCbits.TRISC2 = 0; // output
    TRISCbits.TRISC3 = 0; // output
    TRISCbits.TRISC4 = 0; // output
    TRISCbits.TRISC5 = 0; // output
    TRISCbits.TRISC6 = 1; // input
    TRISCbits.TRISC7 = 1; // input
    ANSELC = 0x00; // all port C pins are digital I/O
}

void pwm_init(){

//         PSTR1CONbits.STR1A
//hackhackhackhack... TODO

//    CCPR1L = 0x120;
    CCPR1Lbits.CCPR1L = 0xFE;
    PR2 = 0xFE;
    CCPTMRS0bits.C1TSEL = 0;     //CCP TMR2 Selection
    CCP1CONbits.P1M = 0x00;
    CCP1CONbits.DC1B = 0x00;
    PWM1CONbits.P1RSEN = 0;
    T2CONbits.T2CKPS = 1;  //1:2 Prescale
    T2CONbits.TMR2ON = 1;  //timer 2 go

    CCP1CON = 0x0C;       //PWM (CCP)1 ON

}

void uart_xmit(unsigned int mydata_byte) {

    while(!TXSTA1bits.TRMT);    // make sure buffer full bit is high before transmitting
    TXREG = mydata_byte;       // transmit data
}

void serial_init(void)
{
    //9600 8N1
    // calculate values of SPBRGL and SPBRGH based on the desired baud rate
    //
    // For 8 bit Async mode with BRGH=0: Desired Baud rate = Fosc/64([SPBRGH:SPBRGL]+1)
    // For 8 bit Async mode with BRGH=1: Desired Baud rate = Fosc/16([SPBRGH:SPBRGL]+1)

    TXSTA1bits.BRGH=1;       // select low speed Baud Rate (see baud rate calcs below)
    TXSTA1bits.TX9=0;        // select 8 data bits
    TXSTA1bits.TXEN = 1;     // enable transmit

    RCSTA1bits.SPEN=1;       // serial port is enabled
    RCSTA1bits.RX9=0;        // select 8 data bits
    RCSTA1bits.CREN=1;       // receive enabled

    SPBRG1=25;  // here is calculated value of SPBRGH and SPBRGL
    SPBRGH1=0;

    PIR1bits.RCIF=0;        // make sure receive interrupt flag is clear
    PIE1bits.RCIE=1;        // enable UART Receive interrupt
    INTCONbits.PEIE = 1;    // Enable peripheral interrupt
    INTCONbits.GIE = 1;     // enable global interrupt

         __delay_ms(50);        // give time for voltage levels on board to settle

    uart_xmit('R');         // transmit some data "restart" notification
}

int main(void) {

    init_io();
    serial_init();
    LATCbits.LATC2 = 0;
    pwm_init();

    // set up oscillator control register, using internal OSC at 4MHz.
    OSCCONbits.IRCF = 0x05; //set OSCCON IRCF bits to select OSC frequency 4MHz
    OSCCONbits.SCS = 0x02; //set the SCS bits to select internal oscillator block

    ADCON0 = 0b00100101;                            //select AN9 and enable
    ADCON1 = 0b00000000;                  //speed Vref=AVdd, VssRef=AVss
    ADCON2 = 0b00111011;                //ledft justified, 20RAD, FRC
    __delay_us(5);

//loop

    while (1) {

        PORTAbits.RA0 = 1; //blinky i'm alive.
        __delay_ms(140);
        PORTAbits.RA0 = 0;
        __delay_ms(140);

            GO = 1;
    while (GO) continue;              //wait for conversion
    an9_value = ADRESH;               //AN9 value

        fvar = an9_value; //this is hacked off another project but works
        fvar = fvar * 10749;        //calibration
        fvar = fvar / 256;
        tens = fvar / 100;
        //tens = tens % 10;
        decm = fvar % 100;
        vtxdata = fvar / 43; //because I'm lazy... I'll change this later.
        uart_xmit(vtxdata);
        CCPR1Lbits.CCPR1L = vtxdata;

    }
    return (EXIT_SUCCESS);
}

Programmable Load Circuit Update

My unfortunate failure Friday lead me to banish the project to the “maybe-I’ll-work-on-this-later” pile. I decided to give it another look this morning. I figured I did it to myself when I decided to trust a random schematic found online instead of engineering my own, right? So I designed my own circuit, not that it’s rocket science… It worked fine. I will reconfigure the operational amplifier to be a voltage doubler; right now I am using a potentiometer to drive the MOSFETs but I’ve started to work on a program on a PIC mcu and the 0-5V out of the DAC isn’t going to do the trick…  I have a real nice book on Op Amps but this app note, AN-31, gives you plenty of examples if you every get bored one weekend and want to experiment with Op Amps. Also W2AEW (google it) has a great Youtube video on it that even the skilled will enjoy. If you’re working with interfacing microcontrollers you should buffer your outputs. A voltage follower Op Amp works well with DACs but keep in mind you’ll want to pick your Op Amp wisely.. think rail-to-rail or plan on using additional power.

Note to self: Build a quick “MOSFET” tester… I found many my recycled MOSFETs pulled off the odd piece of HAM swap meet scores were not totally functional.

So I tested my circuit up to 30 watts, mostly because I didn’t have a dummy load that could handle anything more. I’ll design up a circuit or photograph a hand drawn one once I’m done. I don’t know how much I’ll get done this week, I have jury duty, bleh!

On a side note: See the plastic cases on my bench with the white labels in the photo? I don’t think I’ve mentioned it but those are my parts storage. They are meant for 4×6″ photo storage bought from craft stores. I have eight cases of 20 of those storage boxes… and I’ve just filled all of them. I’ll have to buy another case in a while when I separate more parts.. the parts cases cost about $40 for the larger case that contains the 20 smaller cases. They are by far the best parts storage I’ve ever had. I still have a couple other types of storage for projects, wire, big parts like transformers, etc.. but for all the regular stuff these are a dream come true.

The meat and potatoes of the load work fine... note to self: stop trusting online circuits.
The meat and potatoes of the load work fine… note to self: stop trusting online circuits.