Another project completed

General "chat", not necessarily MTX related
Post Reply
Martin A
Posts: 799
Joined: 09 Nov 2013 21:03

Another project completed

Post by Martin A »

Nothing to do with the MTX. (well almost nothing see below)

Question 1: What do you do when the screen/trip computer on your exercise bike dies ?

The answer, build a new one from scratch of course!

Question 2: Do you do the sensible thing and use a 20 or 28 pin microcontroller and SPI display

The answer, of course not, why do things the easy way!
bike comp.jpg
bike comp.jpg (378.22 KiB) Viewed 5125 times
Because I originally wanted the possibility of running from the onboard 3v battery pack I've used a modern WDC 6502 and HC logic, All of which can run on anything from 2 to 5v. I don't have a 3v capable Z80 or PIO. The W65C02 runs at 4.096mhz with a W65c21S PIA, 8k of ram and 128k flash chip. The current software is pretty "basic" so is using just the "zero page" ram and the stack. Rom use is about 6k of a theoretical maximum 55k, most of which is the boot ram and lookup tables for the trip counter.

The LCD turned out to be a bit of a problem, it's 5V only, so for now, everything else is running at that voltage, and the power comes from a wall wart. The screen is 128 x 64 pixels so using the 6 x 8 font from the MTX (tentative MTX link there as promised) I can get 8 rows of 20 characters. Theoretically 21 rows are possible, but the way the screen in laid out as 2 panes of 64 x 64 makes it far simpler to stick to 10 characters in each half, and not try to have a character in the middle split between the 2 halves. Instead, the outer 4 pixels on each row are ignored to maintain the character spacing.

With the screen inplace, it boots to:
starting.jpg
starting.jpg (401.69 KiB) Viewed 5125 times
And currently testing software shows just distance and time, one day it will get a current speed indicator, and maybe average speed too. Current speed I'm sure I can do with more lookup tables. Average speed means doing division, not something I've done before on the 6502 so it means lots of new code.
running.jpg
running.jpg (396.88 KiB) Viewed 5125 times
Technical details.
The CPU runs at slightly unusual 4.096mhz so that I can use a 12 stage counter to divide the clock by 4096 and produce a 1ms tick for the trip timer. The trip timer runs on the NMI interrupt to make sure it's never held up. The pedal sensor triggers the IRQ interrupt for the distance calculation, again running on the interrupt means that it gets priority over the display software.

The screen is too slow to be driven directly by the CPU, and so it's controlled via the PIA. It's a similar sort of thing to the way the CFX controls the IDE interface through the 8255 PPI.

The original controller used 4 buttons for various functions, 3 of those are connected to the PIA the 4th is the reset button. All 3 of the PIA inputs and the pedal sensor are passed through a 74HC14 Schmitt trigger inverter to avoid glitches.

The miles counter is pretty straightforward, like the original I use 256 turns to the mile. But that means 159 turns for a kilometre. 159 is a nasty number, so I used a 2 x 159 entry lookup table to convert that to a 2 digit decimal. Miles are done the same way with a 2 x 256 table simply because it's easy and there's space. And yes, I know having a 3 digit counter for the miles is over doing things a bit, but it's there just in case I decide to train for the Tour!

PS the screen's actually upside down, it was only after I fitted it I realised the "bottom" is the connector side. Since it's all bitmap the print routine and character definitions are "tweaked" to put things the right way around.
Bill B
Posts: 593
Joined: 26 Jan 2014 16:31

Re: Another project completed

Post by Bill B »

Very good. I wish I could manage to be half as productive.

One of the projects on my "long list" is to hook up an RPi to an exercise cycle and then interface it to Google Street View so that it is possible to do a virtual tour of London, Lake District, New York or anywhere. But then the chance of completing even 1% of my "long list" projects is slight.
Martin A
Posts: 799
Joined: 09 Nov 2013 21:03

Re: Another project completed

Post by Martin A »

The bike computer has had a couple of upgrades, the backlight is now enabled and the software now includes a speedo.

I managed to avoid doing any math by using tables and pre-rendered images of the speedo.
Bike upgrade.jpg
Bike upgrade.jpg (57.27 KiB) Viewed 5095 times
The power LED resistor got upped too, it was uncomfortably bright in poor light.
Post Reply