gnupic: 555 code dumper testing (was DIY USB programmer?)


Previous by date: 11 Jan 2005 20:37:26 +0000 Re: DIY USB programmer ?, David Willmore
Next by date: 11 Jan 2005 20:37:26 +0000 Re: DIY USB programmer ?, David Willmore
Previous in thread:
Next in thread: 11 Jan 2005 20:37:26 +0000 Re: 555 code dumper testing (was DIY USB programmer?), Byron A Jeff

Subject: 555 code dumper testing (was DIY USB programmer?)
From: Byron A Jeff ####@####.####
Date: 11 Jan 2005 20:37:26 +0000
Message-Id: <20050111203722.GA7190@cleon.cc.gatech.edu>

On Wed, Jan 05, 2005 at 09:19:15AM -0500, Byron A Jeff wrote:
> On Tue, Jan 04, 2005 at 06:39:41PM +0100, Manuel Bessler wrote:
> > Hi all,
> > 
> > I'm looking for a simple DIY design for a USB-based PIC programmer.

[SNIPPAGE]

Last week I was discussing a dumb bootstrap code dumper. Here's a recap of
the primary and followup posts

> So the only thing that you can guarantee is the TX signal. Fortunately there
> are some guarantees there. Because of the async interface you know that 
> you'll get really precise timing at any particular bit rate. So you'll have
> exact timings relative to the falling edge of the start bit.
> 
> So the simplest TX only programmer will require an external one shot to 
> clock in the data bit at some time relative to the falling edge of the start
> bit. 
> 
> This is when you trot in the venerable 555 timer. The problem with it is
> that it needs to be non-retriggerable. A 5 minute Google search came up
> with the interesting idea of using an NPN transistor as the gate. Let me
> see if I can describe it:
> 
> 1. Wire up the 555 in traditional one shot mode. There are a trillion 
> examples of this so I won't describe any further.
> 
> 2. Add a NPN transistor to the trigger input of the 555. Wire the collector
> to the trigger input (with a pullup resistor), the emitter to the 555 output,
> and the base (with a suitable series resistor) as the new trigger input.
> 
> Here's how it works. The 555 trigger is active low and the 555 output is
> active high. The transistor acts as an inverter so the base is now an
> active high trigger. So if we start from the idle state where the trigger
> input to the base is low and the output is low, the transistor is off and
> the 555 trigger is pulled up by the pullup resistor.
> 
> Now you trigger the circuit by raising the base. The transistor turns on
> pulling the 555 trigger low, this triggers the 555, which raises the output
> high. So far so good.
> 
> But remember that the emitter of the transistor is connected to the output
> of the 555. So when the output goes high it brings the emitter high too. 
> Since there is no longer a voltage differential between the emitter and the
> base, the transistor turns off and the pullup pulls the trigger high again.
> And as long as the output of the 555 is high, that trigger cannot be pulled
> low. So you in theory can wiggle the base input as much as you like and it
> won't affect the timing of the 555.
> 

[SNIP]

> So if it all works there may be a winner here:
> 
> 1. Use the 555 one shot output as the program clock for the PIC. There is no
> need to invert the signal as the bit is latched on the falling edge of the
> clock.
> 
> 2. Since the new trigger is active high and with RS-232 the leading edge of
> the start bit is a transition from 1 (-12V) to 0 (12V) (i.e. a rising edge)
> you don't need to invert the TX signal, just condition it with a series
> resistor and a 4.7V or 5.1V zener. The output of that junction goes to the
> PIC program data PIC too in addition to the base of the trigger. Even better
> in the idle state both the clock and data pins to the PIC are low, so you can
> simply wire a switch from 13V to MCLR with a pulldown resistor to activate
> programming mode.
> 
> 3. Now you tune the 555 delay to about 1/2 a character transmit time. This
> should be doable without any fancy equipment if you test with flip flop
> like the 74HCT74. Simply tie the transistor base to the D input of the FF
> and tie the output of the 555 to the clock (you may need to invert
> the signal). Then tune the delay resistor until when you send a 0x00 down
> the serial port you get one bit and when you send 0xff down the port you
> get the other bit.
> 
> And that's it: a trivial serial PIC bootloader programmer that only uses the
> TX line and a handful of cheap plentiful components. And it should work with
> any USB to serial converter.

I followed up with a correction in my thought process.

> Now to the new stuff.
> 
> In my original 555 design  made a goof. While the circuit which uses a
> transistor to make the 555 non retriggerable should work, it doesn't
> satify our needs. A brief review:
> 
> 1. We use TX only for both clock and data to the PIC.
> 2. The TX line is tied directly to the PIC program data line.
> 3. The TX line is also tied to a non retriggered 555 which is triggered
>    by the start bit edge. On the falling edge of the 555 output the PIC
>    data is clocked in because the output of the 555 is tied to the PIC
>    program clock line.
> 
> Here's what I missed. Even with the non retrigger circuit, the 555 is game
> to be triggered again after its timeout. So if the TX line is set for the
> PIC to clock in a high bit, just as soon as the 555 times out, it'll 
> retrigger. OOPS!!!
> 
> The solution isn't too difficult but unfortunately complicates the board
> a bit. The solution is a second 555 one shot with a longer duration. Or of
> course you can use a 556 and get two times. Here's how it works:
> 
> 1. Everything for the clock 555 is almost the same as before. Same delay,
> same input, and same output. The only difference is that the transistor
> emitter is tied to the output of the second 555, which I'll call the char
> timeout delay.
> 
> 2. The char timeout 555 is configured to give a delay that is almost the
> width of the character being transmitted. Its purpose is to prevent any
> retriggering for the entire time the character is being sent. Presuming the
> typical N-8-1 transmission which is 10 bit cells, this time is configured to
> time out after 8 cells, while the clock 555 is configured to clock after 4-5
> cells. BTW both 555s are triggered by the same transistor circuit so that
> they trigger together. However since the char timeout 555 is holding up the
> retrigger and it's longer than the clock 555, then the clock 555 will time
> out and give a falling edge for the PIC clock, clocking in the data.
> 
> In this new configuration, TX can wiggle during the entire character, and
> the data is latched in on the falling edge of the clock 555, which will
> remain no retriggered until the next character.
> 
> How of course we've simply transferred the issue as the longer 555 can be
> accidentally be retriggered by TX when it times out. So we simply use some
> software to solve the issue. By issuing the characters 0x07 and oxff we
> can effectively shorten the cell width from 10 bit cells (N-8-1) to 7
> bit cells (N-5-4). So TX can be guaranteed to be idle when the character
> delay 555 times out after 8 bit cells.
> 
> Calibration should be easy. For each of the 555s tie the output back to the
> RX of the PC. Then send a the 0xff character which will guarantee to idle TX
> by the time either 555 times out. Then read back the character sent.  For the
> clock 555 tune the resistor until you get back characters 0xf8 or 0xf0
> consistently which is 3-4 bit cells delay. Tune the character delay 555 so
> that you're getting back either 0x80 or 0xc0 which is 7-8 bit cell delays.
> 
> Once that's done the hardware should be ready to roll. When you send a 0x07
> down the pipe the clock 555 will clock in a 1 into the PIC after 3-4 bit
> cells and TX will return to idle after 6 cells, well before the 7-8 timeout
> of the character delay 555. On the other hand sending a 0xff will cause a
> 0 to be clocked in for the data and of course it'll idle right after the
> start bit.
> 
> So it adds one for 555 monostable to the circuit.
> 
> I went to the Radio Shack today and found all the parts. I'm planning on
> using a 4800 BPS clock rate with the clock 555 at about 1ms and the character
> delay at a bit over 2ms. 
> 

I also had a thought on verification...

> I thought a minute or three today about doing dumb verification. The basic
> idea would be to set up a second one shot, triggered by the clock's one
> shot.  The verify one shot is configured so that it gives different delays
> based on the value of the PIC program data pin. The output of this one shot
> is then connected to the receive pin of the USB/serial cable. The basic idea
> is that for every trigger of the clock one shot, the data one shot goes off
> transmitting back the value of the bit. If you set one delay for 2 or 3 bit
> times and the other for 5-7 bit times, then you can simply read back the
> characters coming back over the serial port to get the value of the data 
> pin.Since you can command the pic to read back its program memory, you can 
> verify it.
> 

I rethought this. More below.

[more snippage]

> Hope this helps. It's interesting enough that I think I may take an hour
> today to breadboard and do some tests.
> I'll post results of my testing when I get it done.

OK I've done some testing and I have some positive preliminary results. I
don't yet have a schematic (I may try to draw one in the next day or two)
but the written descriptions of the circuit are above. I've also corrected
an error or two in thinking.

I wired up the two monostables as described above using a 556. The short
clock 555 (known as short 555 from now on) uses a 1 uF tantalum cap and 940
ohms of resistance from 2 470 ohm resistors. The longer character 555 (long
555) has the same 1 uF cap and about 1470 ohms of resistance (this one has a
pot on it for tuning). As specified above I tested by trying the 555 outputs
to the RX input. I also modified my copy of linwload which has a simple
terminal program in it to send out the non-printable character for the zero
bit when @ it hit and the non printable character for 1 when ! is hit. More
on those values later.

Note on the monostables: the filter cap for the control voltage input is
a must. The circuit didn't work until I put them in.

The TX filter and trigger were wired as specified above with a 470 ohm
series resistor, a 5.1V zener and a 2N2222. The collector of the 2N2222
serves as the trigger input to both 555s. Also as specified above the output
of the long 555 is connected to the emitter of the transistor.

The non retrigger circuit works like a champ. The long 555 is tuned
until RX gets a 0x80, while the short 555 is tuned until a 0xf0 comes
out.

One mistake I made was forgetting that UARTS send characters LSB first. So
when I was sending 0x07 as I specified above, it was actually retriggering
the timers. So for a zero bit, a 0xc0 is sent so that the TX line is high
when the short 555 times out, and a 0xff so that TX is high only for the
start bit.

To test I hooked up the whole thing to a 74HCT573 (from Trivial fame) to
test the latch, which is falling edge triggered. I hooked up the conditioned
TX line (at the point of the zener and the resistor) to a data input and the
output of the short 555 to the latch enable.

Worked like a champ. When I hit @ a 0 bit was latched, and when I hit ! a
1 bit was latched.

At this point I have all the hardware required to dump, and it only takes
a TX line set to 4800 BPS sending 2 characters.

Now on to verification. Note that we have 2 one shots now, each triggered
at the beginning of a character, which one timing out in the middle of the
character cell (0xf0) and the second near the end (0x80). We can use these
two to define a frame for verification.

First off we only want to read bits when TX has been triggered. Secondly we
have to define a proper start and stop bit. Finally we need to have a section
that shows the value of the PIC data bit.

Taking care of the first issue is simple. Only allow RX to be non idle when
the long 555 is active. So when that 555 is inactive (output low)
we want RX to be idle (which is also a low voltage). This is easily done 
using a pullup resistor on RXand a diode (anode to RX, cathode to long 555 
output). When the long 555 activates the cathode rises to the anode and the
diode stops conducting letting the pullup pull RX to +5 
(and emitting a zero).

But the second and third legs are what I'm still thinking on. I think that
the short 555 can be used to force a proper start bit. It can be done
by using another steering diode to the short 555 output with the anode to
the 555 output and the cathode to RX. So in the short 555 idle state both
anode and cathode are a 0V and non conducting (the long 555 diode will be
conducting). When the two 555 trigger and both of their outputs go high
then the long 555 diode will stop conducting and the short 555 diode will
conduct if and only if something else is trying to pull the line low.
Since both 555 have 200ma of drive, they can easily override any other
current limited signal.

So only two diodes and a pullup resistor so far. The third leg is impressing
the PIC data bit onto RX. I think that the TX data input needs to be 
isolated from the RX circuit. So I think that throwing a transistor inverter
between the TX data and the PIC data line is appropriate. That transistor
can tug the PIC data line low and the pullup (or the short 555) can pull it
high. Finally the PIC data line itself can drive RX, but needs to be 
overridden by the two 555 outputs. So it'll need a series resistor into
the RX junction.

So in short RX will by pulled high by a pullup resistor and will have 4
potential sources or sinks:

1) The diode steered long 555 which can pull it idle (low).
2) The diode steered short 555 which can pull it active (high).
3) The transistor driven TX input which can pull it idle.
4) and the PIC pin itself which can pull it high or low when driving it.

So here's the timing. When idle the long 555 keeps RX idle. When TX
sends a character it triggers both the long and short 555. The long 555
drops out for its active duration while the short 555 activates RX forcing
a start bit. When the short 555 times out we make sure that TX isn't
forcing the issue by idling TX, which ensures that the transistor to RX
is off. Finally the PIC pin can drive the line the way that it wants for
the 2 or so cells between the short 555 timing out and the long 555 timing
out. When the long 555 times out RX goes idle ending that transmission.

The only problem I see is when you are clocking bits into the PIC that the
short 555 is going to hold the data line high until it times out. I'm not
sure that we can guarantee the setup since when latching a 0 bit, both the
data line and the clock line will be transistioning at the same time. It
looks dicey. I don't really like the right solution, which is add a 3rd
ultrashort 555 one shot to the mid to make sure that the start bit is
held properly.

But I'll worry about that later. I'm going to see about hacking on pikdev
to give me a driver to program some parts next.

BAJ

Previous by date: 11 Jan 2005 20:37:26 +0000 Re: DIY USB programmer ?, David Willmore
Next by date: 11 Jan 2005 20:37:26 +0000 Re: DIY USB programmer ?, David Willmore
Previous in thread:
Next in thread: 11 Jan 2005 20:37:26 +0000 Re: 555 code dumper testing (was DIY USB programmer?), Byron A Jeff


Powered by ezmlm-browse 0.20.