Quantcast
Channel: Wardy's Projects
Viewing all 70 articles
Browse latest View live

Propeller -- fast(ish) serial data output from PASM

$
0
0
Yikes, It's been a while since I last posted.  GTA5 got in the way, then I got very bored of GTA5 and then I played Skyrim all the way through again to get my head right.  GTA5 has almost zero re-play appeal.

Anyway...

For no good reason I wanted to see how fast I could signal asynchronous serial data from a single Cog on a Propeller chip.  Like one does.



CON
_clkmode = XTAL1 | PLL16x
_clkfreq = 5_000_000

PUB Main
coginit(0, @ENTRY_POINT, 0)

DAT
org 0
ENTRY_POINT
or outa, TX 'idle high
or dira, TX 'output

mov byte_to_send, #$41
CALL #SERIAL_SEND_BYTE
mov byte_to_send, #$42
CALL #SERIAL_SEND_BYTE
mov byte_to_send, #$43
CALL #SERIAL_SEND_BYTE
mov byte_to_send, #$44
CALL #SERIAL_SEND_BYTE
mov byte_to_send, #$45
CALL #SERIAL_SEND_BYTE
mov byte_to_send, #$46
CALL #SERIAL_SEND_BYTE

waitpeq $, #0 'hang forever




SERIAL_SEND_BYTE mov ser_bitcount, #10 '8 data bits + start bit + stop bit == 10 bits total to send
mov ser_bitbuf, byte_to_send
or ser_bitbuf, #%1_00000000 '(binary) append the stop bit (we're sending this data LSB first don't forget!)
shl ser_bitbuf, #1 'prepend the start bit (shl shifts in a zero bit on the LSB)

mov ser_time, cnt
add ser_time, #30 '30 clock cycles == approx 2_666_667 baud at 80_000_000MHz !
:ser_loop rcr ser_bitbuf, #1 WC
muxc outa, TX
waitcnt ser_time, #30 '30 clock cycles == approx 2_666_667 baud at 80_000_000MHz !
djnz ser_bitcount, #:ser_loop

SERIAL_SEND_BYTE_ret ret


TX long |< 4

ser_time res 1
ser_bitcount res 1
ser_bitbuf res 1
byte_to_send res 1

fit


As long as you have a 5MHz external crystal on the Prop then you should have something pretty close to 2666667 Baud serial output on pin P4 (crystal accuracy does matter at these speeds!).  If not then you'll want to change the "#30" constants to alter the baud rate (keep both values the same and you'll be fine) to compensate for your chosen clock speed.

Studious observers might realise that I'm aiming for minimal code-space usage.  This code is pretty compact but I think I can do better.

In fact I think I can reach much faster Baud rates.  This code is limited by the waitcnt instruction, which is a little cumbersome when one is trying to wring out every last instruction cycle from a Cog.

By using one or both of a Cog's Counter features (CNTA and CNTB), it might be possible to get something close to 18 MBit of UART speed!  This will be at the expense of code size though.

It is interesting to note that Mr Nyquist's observations determine that TX and RX do not necessarily share the same theoretical maximum baud rate.  TXing is stateless (effectively) but RXing is stateful because we need to be able to notice edge transitions and compare them to the bit rate we are expecting.  Even if I can hammer out TX rates of 18MHz, I'll probably be limited to RX rates of about a quarter of that, maybe less.

Science!

Adafruit Neopixel Ring - example assembly source code for Atmel ATTiny85

$
0
0
http://www.adafruit.com/products/1463

These new NeoPixel rings from adafruit are really very good.  A little strange to operate perhaps (they are like a shift register but they shift by re-transmitting downstream.  Or to put it another way you would send the pixels as if they were drawn out on a TV screen (which is not the way a shift register works if you think about it).

Initially, I wrote some PASM code for a Parallax Propeller (P8X32A) chip to make some interesting colour patterns appear on the ring.  This was quite easy with the aid of a Saleae Logic probe.

But the problem with the Propeller is that it's a very expensive chip and is COMPLETE overkill for making some fancy patterns on a bunch of LEDs.  No, instead I wanted to use a smaller chip to run the LEDs from.

Enter the ATTiny85 [PDF].

Long story short, I've written an very simple ATTiny85 demo assembly code program for showing a pattern on the NeoPixel Ring.  It shows a stationary pattern of 5 reds, 5 greens, and 5 blues, all of increasing brightness, and a single white LED showing an equal mix of the three colours.

Here's a pic of the code in action...

Please forgive the brightness of the LEDs in the picture.  In reality they are in fact displayed at a deliberately low intensity, because the LEDs themselves are very bright indeed when forced to maximum brightness.

The code shown below was written for the ATTiny85 and was compiled using Atmel Studio (version 6.1.2562) and I used a AVRISP MkII programmer device to install the software into the chip using the 6-pin programming connector.

VITAL INFO: You'll need to get the fuses right for this, I've highlighted the important bits...

SOURCE CODE Here's the (public domain) code: ring.asm

Load up Atmel Studio and start a new Assembly language project and select the ATTiny85 as your target chip.  Then replace the default assembly program with the code I have given here.

Hit F7 and it should hopefully compile without any errors.  Then open the programming menu and configure the Fuse options as you see above.  Then once you've set the fuses properly click the "Program" button to send the new fuse config to the chip.  Next click the "Memories" option from the list on the left side of the dialog and then program your chip with the "*.hex" file that was created.  You might have to use the "..." button next to the filename dropdown box in order to find the hex file.

All being well you should be able to hit the "Program" button on the Memories tab and the chip attached to your AVRISP MKII programmmer will now contain the firmware to generate the NeoPixel ring test pattern.

Connecting the ATTiny85 to the NeoPixel Ring:
  • ATTiny Pin 8 goes to 5Volts
  • ATTiny Pin 4 goes to GND
  • ATTiny Pin 5 (PB0) goes to the "Data IN" pin on the NeoPixel ring.  Also power the ring from 5V and the same GND rail.



If you have any problems, please let me know and I'll try to fix my hastily written instructions ASAP. :)


I hope this helps some of you wanting a fast and simple intro to using ATtiny85s to drive the Neopixels without having to rely on some awful heap of crummy arduino imitation libraries to get the job done.

IMPORTANT NOTE:

Please note that the WS2812 datasheet is WRONG!!! Please use the Adafruit timings table instead, my code uses the adafruit timings and they do work well...
Load this page and scroll down to the "Writing Your Own Library" section and notice the differences in the timings table.  This is important!



Good luck and happy hacking. :)






Afterthoughts:
You might find that other fuse settings work for you, the important thing to know is that the code I have provided is designed to work with an internally generated 16MHz system clock.  If you want to you can always just use an external 16MHz clock and choose your own fuses as you wish.  The code itself just deals with shovelling bits around.  The only time-sensitive part of the assembly code given here is the sub-routine labelled "send8bits". In fact you might want to simply convert the "send8bits" function into an Interrupt Service Routine and let it run every 60Hz or so. That would let the rest of your code run without any particular timing limitations - at a leisurely pace if you will :)










Purpleheart Ornamental Clock

$
0
0
Recently I have seen several projects around the interweb featuring LEDs shining through very thin timber.
I found this intriguing enough to invent a way to make my life difficult in a pointless and unprofitable manner.

I wanted to use my new Adafruit Neopixel Ring to build an ornamental clock, using this interesting woodworking technique.  Plus I figured that my milling machine might make this a feasible prospect.

Milling, in my very limited self-taught experience, is best done using a material that is of a consistent density.  Wood, (again in my very limited self-taught experience) isn't consistent in it's density.  Softwood especially.  So I turned to the densest wood I could get my hands on and assumed that it would simply behave like a very soft version of aluminium.  Here's the aggravatingly cursory build log...

Take one lump of Brazilian Purpleheart, and attack it for several hours with a selection of saws.  This stuff is seriously dense.  Cutting it to approximate size was a major ordeal, I had to use a long standard wood saw with regular applications of machine oil (worked very well) on the blade to stop it jamming in the wood. Took ages to get a roughly cubic chunk 2" on a side out of the heavy disc of timber.

Then it was a matter of using the milling machine to square off the rough lump of wood to make all the sides parallel and square to each-other.  This was surprisingly easy, as the wood does allow milling, and yields a shiny and smooth finish when facing off a large area.  A roughing cut followed by a higher RPM run with a slower feed rate does give a great finish.  It will still need hand-sanding and making good to achieve a final sheen though.

Now for the hard bit.  The plan was to mill out a deep pocket in the rear face of the clock into which would be placed the LED ring so that it shines through the front of the clockface.  A daunting prospect because the block of wood I was using was an inch thick and the pocket had to be roughly 15/16" deep.

Long story short, it worked...

Below: Preliminary test of the Neopixels shining through the dense wood grain!  It works.

Below: Purpleheart block with milled-out pocket for electronics.  Shown here with a dead Arduino (the best kind) for scale...

It took ages to mill out this pocket.  Partly because I have no woodworking experience and partly because I haven't had my milling machine long.  Actually it was a lot of fun to do and was great practice for using the X, Y and Z axis motions on the milling machine.  The added danger that calamity would befall me at the first careless turn of a handle simply added to the fun.

The final depth finishing cut on the interior of the block took the front face thickness down to 2.2mm.  I didn't dare cut any thinner than that lest the hardwood fractured and split.  At this thickness, it is more like a veneer!

At time of writing, the front wall thickness is still way too thick to allow the LEDs to be seen clearly in anything above total darkness.  If they are to be effective, I need to carefully sand down the exterior surface to reduce the thickness and allow more light from the LEDs to shine through.At the same time this will hopefully give a smooth and attractive surface finish to the exterior.

That is a task for another day, however.  For now I'm happy that I didn't completely destroy this rather nice piece of one of the world's most super-dense hardwoods.  The milling machine did me proud, a 10mm end mill did the entire job with ease and showed no signs of wear after what must have been several hundred metres of cutting.

PS. for those interested, this type of timber really does turn purple after it's cut (as promised in the wiki page).  I assume it's an oxidation reaction with the freshly exposed surface.  I reckon it takes about 4-5 days to go noticably purple, so don't expect results immediately.  In all other respects it looks like a striated mahogany texture, but I'm certainly no expert.

Watch this space for further updates on this project.  The next thing to do is the firmware for the ATTiny85 microcontroller I plan to use to drive the colour patterns on the LEDs.







Fail

$
0
0
Purpleheart clock enclosure has been destroyed.  ****.  However it does appear to be possible to mill this material down to around than 1mm thin without it fracturing.

Nevermind, onward and upward.  I'll try again.  Good job I have a backup workpiece that was cut out at the same time as the first!

What doesn't kill us... simply disintegrates in a milling machine.

Xmas decoration

$
0
0
"Winter drawers on", as they say.  Xmas is almost upon us.

In the light of my recent carpentry failure, I turned my attention to improving the electronics for my NeoPixel project.  Nothing fancy here, just an ATTiny85 microcontroller with some home brewed NeoPixel driver code on it, running from an ST L7805 5V regulator and taking power from a 7.5V 1.5A wall wart supply.

Here's a badly made, artefact riddled, crappy video...



Multiplexing high frequency digital signals using a Parallax Propeller

$
0
0
While contemplating the Counter features of the Propeller chip, an interesting idea occurred to me.  Since each "Cog" has it's own CTRA and CTRB counters, and given that they run at the system clock (after PLL) speed AND run "in the background" without requiring any particular interaction with running code....

It should be possible to feed in a high(ish) frequency digital signal into an input pin and arrange the CTRA/CTRB features such that the signal is redirected out of an output pin with very little latency and without needing to execute any instructions at all (apart from a small number to set up the features to begin with).

Furthermore, one input pin could supply both CTRA and CTRB simultaneously while two outputs are driven (one for each CTRx).

Even more furthermore, I theorise (but have not yet implemented) that all 16 CTRx features in a Propeller could feed from a single input pin and supply 16 output signals simultaneously!!!

The output signal would be inverted and one master clock cycle behind the input signal.  If multiple output signals are generated, then they would all be exactly in phase with eachother (but still inverted and trailing slightly behind the input signal).

"This doesn't sound very useful!" I hear you cry.  Well it could be used for the following purposes:

  1. Re-routing UART data to alternative destinations, or multiple destinations.  You'd simply need to re-invert the inverted outputs to get your signal the right side up but this is cheap to do.
  2. Clock distribution without having to use expensive additional components.
  3. Simply inverting a digital signal.
  4. All of the above at up to 80MHz (or more if you like overclocking your Propeller)!
Even if you do have 16 outputs running at a time, you'll still have 12 IO pins (16 minus the pin used for programming the chip and I2C to the EEPROM) free to do other stuff with and you're still not actually running a single instruction of code yet.  The only code involved is run once and it only involves setting a couple of registers, but after that your code can forget all about what its counters are up to and get on with other things.

Finished XMas tree decoration code

$
0
0
A few weeks back I finished the ATTiny85 code for driving a 16 NeoPixel Ring and all over the Xmas break it shone like a majestic beacon of festive cheer atop the Xmas tree.  It looks lovely.


There is no schematic for this project, mainly because it's trivial and anyone can work it out themselves with a bit of thought and secondly I couldn't be arsed drawing one.  PB0 on the Microcontroller goes to the data in pin on the first led in the chain.  Both the micro and the LEDs run from a regulated 5V rail.

I will hint that you'll need something at least as good as a LM317 to provide the 5V rail for the LEDs and the microcontroller.  The LEDs chew up a fair bit of current if you drive them at full brightness.  I recommend running them rather dimly because they do get hot and are migraine-inducingly bright at maximum intensity anyway.  For an Xmas tree you'll appreciate the colours more in the dark anyway.

I'm going to adapt this code to drive the 1 metre (30 pixel) strips soon, so stay tuned :)


New Project: Wind Tunnel

$
0
0
To my eternal shame I do not possess my own personal aerodynamics test laboratory. Remiss of me I know. But instead of frittering away several million quid on buying one I have decided to build one for cheap.

Here's a concept drawing...

It will be about 900mm long, 300 high and 300 wide.  It will be constructed from perspex and pine beams.
The fan and speed controller have already been completed (that was today's job, see below).

I will be using an idea I saw on a tv advertisement (one aimed at encouraging people into a career in high school teaching) in which a teacher had constructed a wind tunnel for his classroom.  He had used drinking straws and other simple and cheap parts to affectively make a fully functional model.

I will also be using some car washing sponges to baffle the incoming and outgoing air in order to decouple the rotating fan blades from the linear air flow.  I have found a beefy 12V, 1Amp case fan from a scrap computer.  I am controlling it using a simple, low-part-count circuit which uses a microcontroller to read a rotary potentiometer and drive a power MOSFET using PWM to regulate the speed of the fan.  This works very well and gives good, granular control of the motor speed.

I hope to make this wind tunnel interesting in one respect.  I will be able to up-end the entire thing and do vertical (in opposition to gravity) drag tests for evaluating paper parachute designs!  This might prove difficult but it should be fun finding out.

Here's a couple of pics of the speed controller circuit... (the source code for the ATTiny85 microcontroller can be found here).


The fan connects to the 4 pin header.  The unit requires a 12V PSU such as a wall wart or a laptop power brick.  I can upgrade this design to add a second fan if I decide that a single fan isn't up to the job.

The ATTiny85 is a fantastic chip for small simple projects like this.  I could have done this with a 555 timer of course but I like having the flexibility of the ATTiny85 which gives the potential to add automation features such as soft-starting the fans or setting thresholds on the max/min speeds allowed.

I'll be building the rest of this project this week and I'll put more pics and videos up here soon.

Stay tuned.

Wind Tunnel Project: Welding drinking straws

$
0
0
For the wind tunnel I need to bunch together hundreds of 2" sections of drinking straws to form the flow guides that will hopefully force the air flow to become approximately laminar.  I thought about using spray adhesive but I figured that using glue would be extremely messy and would probably cause more turbulence than it would have eliminated.

Then I tried using my soldering iron to weld the straws together and it works very well...

Look closely at the ends where the straws contact each other.  At those points I quickly touched the hot iron on the plastic of both straws and they instantly fused together.

This is really handy because I can simply pack hundreds of straws into a cardboard jig (a cereal box will work perfectly) and just use the iron to weld all the straws into a single piece!  I have only tried this with a few straws but I think this will work fine for a large mass of straws.  The welds hold strongly although they do tend to ruin the smoothness of the plastic.  I will only do the welds on one end of the straw block, the other end will have to be held in place by another means in order to have a good surface for the air flow to exit the straw bundle.

Try this for yourself and see just how strong drinking straws become when welded together.  I am sure this would be an excellent construction technique for model aircraft makers.  The bundle of 8 straws you see in the picture can hold 8 kilos of longitudinal compressive force without deforming!  And since you're not adding the weight of adhesives, it's incredibly light.  

The bundle above weighs about a gram or so but can support 8000 grams.  Pretty amazing.



Propeller Hacking: WAITPEQ timeout

$
0
0
Random thought of the day:

If you're using either the WAITPE (or WAITPNE) instructions on the Parallax Propeller (P8X32A) chip then you can add a high resolution configurable timeout to it in the following way...

Set up your WAITPEQ instruction like normal but also configure your mask and state values to include an additional IO pin (call it PIN X).  Then configure either CTRA or CTRB to use "NCO single-ended" mode on PIN X with a duration that makes sense for your project.

Since CTRA (or CTRB) are running in the background autonomously then they will be able to cause a pin transition even the cog is still blocked by a WAITPEQ (or WAITPNE) instruction.  Thus you can set up your chip so that it never spends more than a certain amount of time in a WAITxxx state.

I'll throw together a quick code sample shortly to demonstrate this.

Lighting rig for Photographing Paintings

$
0
0
My old man's a dustman an artist.  He's rather good, and I suggested that we record his paintings for posterity in digital format.

This poses a problem - how does one go about providing favourable lighting for photographing a painting?

I have not tried to photograph paintings before so this was rather a new challenge.  I felt it important to give good, neutral white light as far as possible and to distribute that light evenly around the painting.

A few months ago I bought some colour cycling LED xmas lights - five metres worth!  The LED strip came complete with an IR remote control with a colour selection feature that lets you pick from 16 colours or so.

I built a rectangular framework out of MakerBeam parts and cable-tied the LED strip to the frame so that they all face the same direction with a fan out pattern to illuminate the canvas.

Finally I rigged up the framework to attach to my tripod's leg using a scope clamp.  Long story short here are some pictures...




lighting rig for photographing paintings

Home-brew Milling Machine Tacho

$
0
0
For my Clarke CMD10 milling machine I wanted to add a tachometer so that I could better judge the appropriate cutting speeds for various materials, rather than doing the whole thing by ear (literally).

The CMD10 has many failings.  It's sloppy, the ways are rough, the tool head nods like an amused donkey.
The list goes on.  But one of it's great features is it's speed control.  A fairly decent quality potentiometer governs the spindle speed from stall speed (60RPM or so) up to a stated 2000 (mine tops out at 1975).  Within that range you can pick any speed you like to a fine resolution.  This really does feel nice to use since the machinist can simply use their ears to sense the changes in spindle speed.  Quite a pleasant way to use the machine.  But I like accuracy, so I wanted a tacho to tell me the precise speed of the tool's rotation in real-time.

Why buy a tacho when you can build one?  I thought it would be a cool project and there happens to be a convenient spot on top of the machine for a tacho to live.  I fired up my pen and paper and wrote some code to do the requisite calculations.  Then threw a board together and did a bit more code to drive a 4 digit LED display.  Actually this is a fair amount of coding to do but it's a lot of fun to do some serious coding in PASM.

To bring this blog up to date for once (!!!), today I managed to motivate myself to get this build into a state where the RPM sensing and display code is fully operational and made a quick video of it...

https://flic.kr/p/mUsYE2

Next I plan to find a way to add X and Y axis position readings to the display.  Watch this space.

Thanks for reading, comments welcome. :)

Adding LM741 model to LTSpice

New Hardware Project - "2048"

$
0
0
Many annoying things have occurred at once.  My internet went a bit crap for a few weeks.  My laptop decided that it would go on strike - permanently.  Some other stuff that I won't talk about... sigh.

Anyway, we're back on track here at WPHQ and I have a neat new project to be getting on with.

I am going to do a hardware version of "2048", which is a horrifically addictive and fatuous game that has taken up far too much of my free time already.  So by way of rationalising away my tendency to spend hours playing it, I am going to design a electronic version that will fit on a keyring.

It will be open source obviously, since the original game is MIT licensed.

As of this moment I'm just embarking on the schematic design and the tedious activity of sourcing parts and drawing footprints.  The fun part will be writing the firmware that will run the game logic.  I reckon the brains of the game will be an ATTiny85 microcontroller, which I already have a fair amount of experience with and fondness for.

Instead of a numeric game board I will use colours instead.  Red will indicate the number 2, yellow will mean a middling value such as 32 and green will be a higher number like 2048.  For users with difficulty distinguishing between certain hues I will try to provide alternative colour schemes or perhaps animated patterns instead.

It's a very simple project and shouldn't take long to implement.  I plan to make it available as a kit with full design files and parts lists and source code.

2048 PCB layout begins

$
0
0
The schematic is pretty much done now, here's an early screenshot of the rough article...


As you can see, there are a few 3D packages missing (the 4 tactile switches and the 16 neopixels).  No matter.

Version 1 will simply run from a standard USB cable to obtain it's 5V power.  Maybe later versions will have a battery.

The above board is currently 54x31mm in size.

An interesting feature of this game is that turning it through 90 degrees makes absolutely no change to the game play, thus making this suitable for right or left-handed players.

2048 game -- ergonomic rethink

$
0
0
A friend of mine pointed out that the large electrolytic capacitors on the 2048 game PCB design would interfere with the ergonomics when used by left-handed players.  After some thought I figured I could solve that problem by using tantalum caps instead which are smaller and can be moved to a more convenient location.  They are shown as C1 and C2 on this image...


This has saved a bit of board space and makes the entire device a bit smaller and less weirdly-shaped.


2048 game -- Layout so far

$
0
0
Had a fun few hours playing with the routing of the game board.  Top layer has all important signals and also contains the ground plane.  Bottomside will be power plane and connections for the USB connector.


The trickiest part of this so far has been juggling traces in order to allow the ground plane to flow around the board to reach all components that need it without using vias.

Tomorrow's job is to get the power plane done.  That will need vias, but hopefully this will be fairly easy.

2048 -- Nearly there!

$
0
0
Finished the routing for the most part.  Still need to ensure my DRC is compatible with the OSH Park preferred settings.  All that is left is to add some embellishments to the rear silkscreen.  I'll add the Open Source Hardware logo before I send off the Gerber files to Laen.  Also I'll round off the corners, for ergonomics' sake :)


2048 -- Sketchup Pro nails it

$
0
0
It's great when things just work unexpectedly.

Just now I threw together a rounded corner version of the board outline I want to use for the 2048 game in Sketchup Pro.  That went without a hitch.

Imported it into Diptrace.  Also without a hitch.  Hmm.

Surely the copper pours will screw up and not understand what I'm trying to do.  Turns out it's all fine.  I'm seriously impressed with Diptrace. :)

Took about 120 seconds to re-make the board outline with 3mm filleted corners from a DXF generated by Sketchup and brought into Diptrace.  Splendid.


"2049" game PCB goes out for manufacture!

$
0
0
https://oshpark.com/

The 2049 game (as I've now decided to call it) is the 3rd PCB job that I've sent to OSHPark.

6 boards for less than £16 with free international shipping.  In the past the boards have been in my hands within 5 weeks of submitting the designs.  That is *fast* turnaround.  At work I'm used to 8-12 week turnaround times for commercial boards.  5 weeks without having to pay for accelerated service is spectacular.

The second best thing about OSH Park in my opinion the awesome user interface on their website.  Upload your zip file full of Gerbers and drillfiles and the website processes it while you wait and then shows you their own interpretations of your Gerber files.  You can review them and then decide whether or not to continue or go back and fix any problems with your design.  Absolutely brilliant system.

Here's a couple of screenshots of the finished board as sent to OSHPark just now...





Viewing all 70 articles
Browse latest View live