JVR Design

Expandmenu Shrunk


  • Linux Board – Part 1

    Its alive!!!

    So after getting really gatvol of trying to find info on this archaic CPU, I just did random google searches for “RM9200 boot” and I found a page by a chap named Darrell Harmon. Looking at the page, its been a while since he has been there, but, he did modify u-boot to run as the initial loader on an AT91RM9200. After some more searching I found his source code on another page.

    I started by building in command line, this took a good bit of time, and was clunky,  also, the code did not work. It built fine, and I got it to upload to the CPU via minicom, but it was unresponsive.  Some digging in the source led me nowhere, and I was getting tired of using gedit and terminal to build, so I installed Eclipse CDT.  Some fiddling with the bashrc script and the PATH variable had me building in eclipse, oh the joy of an IDE.

    So I still had a problem, the code was unresponsive, inside I found a memory test that was deactivated, I rewrote this to make it smarter and more thorough, and ran the build.  It failed. I then started printing my findings to the console, and found that I could access 256k of the 8MB of the SDRAM.  Some scratching (read: 4 days) later I found that the SDRAM chip on my PCB was not compatible with the loader code.  Diving into the datasheets of both the CPU and the RAM revealed some answers, and a quick patch to the code had the memtest working, awesome.

    Now the loader runs in the device SRAM, and can run be used to load code into either SDRAM or a FLASH device.  I wanted to get the loader written to the AT45 serial DataFlash on the board, as this would save some time in the boot sequence. A quick look at the code had me thinking it should work, alas, it did not.

    Among my problems was the fact that to get the device into its initial bootloader, I had to short SDI and SDO together, as this is the only way to get the device to fail its boot sequence and revert to the initial bootloader.  I thought this might be part of the problem, but soon foun it was not, as I’d remove the short before trying to write to the flash.  I then modified the memtest code to run on the flash, and it failed. A substantial amount of probing later, I found that the WP line was held low, not allowing writes to the first page of the device. Modifying this allowed it to pass the memtest, so now its time to get the loader into flash.  This went badly, so I tried to get it running out of SDRAM, and after some digging found that the base .text address was to blame, two mods to that had it running it both SDRAM and written to dataflash.

    So now I could boot the board into known code with the option to reflash and modify as I pleased.  It was time for u-boot.  One of the ports for u-boot is a AT91RM200 based dev board from ATMEL called the AT91RM9200-DK or -EK depending on what version you had. I had never seen one, and the schematics looked lank different from my board. Some hacking would be in order.  After a few hours of reading through the code and changing both setup and config code, it built and ran on the board. Awesome!  The ethernet driver was dead though. After adding tons of debug code and  getting familiar with PHY’s, something that I have never used, it was as simple as lifting the reset line on the PHY as its connected to the proccessor. Bingo, dhcp found itself an IP address.

    So hopefully the next installment will have the board running a Linux kernel, and that will be awesome!

    Here are some logs from the terminal:

     



  • Genset Controller – Part 1

    So a gent walks into the office accompanied by our MD, he needs some help, his generator is not working. Curious, we ask him how we can help.

    He then pulls out a home made PCB with about 20 relays on it.

    The old board got toast when lightning struck his hose, along with its power supply.  He figured the power supply was broken after it started toasting itself and making calm humming sounds, so proceeded to replace it. Apart from the fact that the genset was starting itself randomly, all was fine :)

    The old system was looks like it was designed by a 1980′s electrician/PLC programmer, as everything is done with relay logic and 555′s. Its horrid to look at, and fundamentally flawed, as a lot of tracks where cut, and a budge board used to modify the circuit to work.

    I offered to design him a proper controller, something that is safe, intelligent and repairable, for much less than a commercial product.

    A trip to the far side of town later I had scouted out the install and decoded the wiring, the I/O’s look like this:

    • DPDT Contactor with a 220V actuator
    • 220V Mains Sense Wire
    • 220V Generator Sense Wire
    • 12V Generator Sense Wire
    • 12V Ignition Wire
    • 12V Starter Wire
    • 12V Manual/Auto switch Wire
    • 12V Battery Feed
    • 12V Power Supply

    Testing it revealed a few oddities, the Man/Auto switch gets its feed from the Ign wire, so the Ign must be on to determine what mode the genset is in. A helpfull lead is the 12V Generator sense wire, this starts at 0V, and ramps up to about 10V when the motor is at full tilt, so a good way to see when to release the starter signal.

    So on to design, of course I needed some specs, but as the gent does not know what he wants, I came up with one myself.

    • Small and cheap
    • Info feedback
    • Battery Charge control
    • Brown out detection
    • Generator Failure detection
    • Generator runtime (session/total)
    • Battery Failure detection

    First up is the choosing of the microcontroller to run the system, as it needs to be in my codebase, cheap and available, I looked at the 16F690 first. With 18 usable I/O, it might do, but I need to run a LCD.  I had two in mind, a 128*64 graphic would be awesome, and a standard 16*2 char.  Price unfortunately won this round, as well as availability.  the GLCD is R160 and 8days, and the 16*2 is R30 and immediately available.

    cpweb152320

    Being a one off, I am lazy, and am going to use 8bit mode, this however chows about 11 I/O’s. So I moved one up in my junkbox, the 18F4550 in TQFP package. This allows me 40 I/O’s more than enough to do as I please.  Yes I know there are smaller devices in the 18F range, but I have these on hand, so it will have to do.

    Next up is how to connect the 220V signals to the micro without much fuss, and to enable me to read the voltage. The circuit below allows me to do this.

    The high voltage input is fed through a 0R resistor to a MOV, this creates a fusable link in the current path, it is then divided down via a 1M and a 5k resistor to create a low voltage feed to the transistor.

    220Vac*1.414
    311.08Vp
    311*(5e3/(5e3+1e6))
    1.54726V

    The BC846 has a nominal 500mV Vbe drop at a few mA, but as I will be using a few uA of current, this voltage drops to about 300mV. Thus the voltage fed to the 100nF cap is 1.247V at 220V.

    Now why use all this extra circuitry when I can just divide the voltage and feed it to the micro? Well then I would need a diode anyways, and I’d need to trigger the ADC at the exact high point of the AC sinewave.  The transistor acts as both my diode and buffer, feeding a pulsing voltage to the cap, the cap has a bleeder resistor and will stay charged a a voltage proportional to the AC line voltage as long as its on, enabling me to sample the voltage at any time.

    The 12V inputs where sorted in the same way, but without the transistor/cap combo. The outputs are done by relays, I wanted to use FET’s, but like I said, its a one-off.

    The  Genset Schematic is available for download in PDF format, the PCB is in PADS, so I’ll probably not upload that. But It looks like this, with a 100*60mm footprint

    So that will get sent off to PCBpool and in two weeks I should have the PCB and be able to start the firmware design.

     

     



  • Linux Board – Intro

    Linux,  something I’ve been scared of doing for a long time.  I did not feel comfortable drowning my work pc in the world of command line use.

    Then I had a thought, get a proper bit of virtualizing software, and play in a safe environment. I started by installing VMware, and then dropping Mint onto that, much fail ensued, as it seems Mint is designed to replace windows, so getting packages installed is a ballache.  I then installed vanilla Ubuntu to the VM, and started having some fun.  I read a few online tutorials and eventually got my first bit of C code compiled and running in Linux.  I was actually starting to enjoy the whole terminal thing.

    But the story behind the story, I am getting fed up with writing long ass drivers in native C to use stuff like USB, WiFi and Ethernet.  And I’d like to have everything on one board.  Like a PC, I’d like to write and compile the code for the device, on the device.  So looking at the options I narrowed it down to .NETMF and Linux.

    The fact that linux is smaller, more usable and free won it.  So now it was time to try and find some info.  Being in ZA, dev boards are cost prohibitive, so I had to find one on the cheap.  JVR haxoring comes in good there.  Looking around the house, I found an old Ethernet-to-RS232 converter.  Bingo, that should run linux!  Opened it up, and I was greeted by an AT91RM9200, a SDRAM chip and a Dataflash chip. WIN.

    I pulled a datasheet for the AT91 and traced the debug serial port, soldered a UART->RS232 converter on there and powered it up. I was greeted by a proprietary bootloader/interface. But it works.

    On one of my web trawling expeditions, looking for AT91 info, I found a good site. It shows a good way of getting the AT91 to boot linux via U-Boot.

    To ease my suffering I added another 232 port to the board, with a little PCB containing a MAX202 for level conversion.

     

    I then had to figure out a way to get the AT91 into its internal bootloader, as the dataflash still contains a valid boot image, after some probing, I figured out that shorting SDI and SDO on the dataflash during boot would not allow any data to pass from the dataflash to the CPU, allowing me to enter the ROM bootloader, and getting the string of ‘C”s in realterm.  The bootloader runs at 115200:8:n:1.

    I tried in vain to find a first stage bootloader for the AT91 that is compatible with my board, but nothing was available, so doing it the easy way is not an option, so I will start from cratch with my archaic CPU, by manually writing the bootloader to enable me to transfer u-boot to SDRAM.  That will be coming up in the next few posts.

    JVR

     



  • Hello world!

    Right, WordPress, after trying Frontpage, Joomla and Pixie, lets see if I like this.

    I’ll start updating the site in a while, got some stuff to sort through first though.