|
Post by tcworld on Jul 13, 2010 11:28:48 GMT
Hello. You say on your site that the motor decoder has no functions. May i enquire as to what the output marked LED does? Also, you have pins 4 and 5 of the PIC connected together. Is this necessary, or would it be possible to split the pins up, and they adjust the PIC code to make this a function output. One final thing. I am wondering if it is possible to use less components in the circuit (trying to make it as small as possible) such as below - in theory all you need to do is provide the op-amp with a 2.5v reference voltage on the + pins... Or are you using the track to generate a PWM?
|
|
|
Post by Paul Harman on Jul 13, 2010 12:20:41 GMT
Several questions here. I will answer them.
1. The output for the LED is a function output but it does not work reliably, if you want to play with the software you might be able to fix it.
2. Pin 4 is only an input, so will not be much good as a function output! You may be able to realocate it as an input if you can think of something to do with it.
3. The voltage reference circuit cannot be dispensed with because it is used to maintain the comparator inputs within the supply rails to ensure good decoding of the data. If you want to use the circuit that you have shown, you can free up pins 6 and 7 as function outputs and use pin 4 for the input from the track via a suitable current limit and clamp instead. You will need to modify the code of course to use pin 4 as the input instead of the comparator output. The comparator is used to provide excellent decoding of data even when the track signal is way out of the NMRA spec as will occur from time to time. This decoder should decode virtually all packets that are addressed to it when the comparator is used.
The op-amp reference just needs to be somewhere between the processor supply rails hence the use of a diode to give 0.6V which you may find more convenient than R2! The capacitor ensures that it is low impedance.
|
|
|
Post by tcworld on Jul 13, 2010 12:54:51 GMT
That nicely explains it, thanks. Can R3 and R4 be 10k resistors or do they have to be 2k2 in the original diagram? I ask to see whether or not i can use a 10k resistor pack to save space.
|
|
|
Post by tcworld on Jul 13, 2010 14:07:06 GMT
Having just gone throught the PIC datasheet i understand what you meant, I hadn't realised the PIC had a built in comparitor.
|
|
|
Post by Paul Harman on Jul 13, 2010 14:52:36 GMT
R3 and R4 can be smaller, but not larger. They are used as part of a potential divider to keep the voltage at the input to the PIC within it's supply rails. If using a high voltage on the track (above 20V) or using a lower regulator voltage (you can go down to below 2.5V for better performance if you can find a suitable regulator) you might like to reduce them to 1K.
|
|
|
Post by tcworld on Jul 13, 2010 16:00:47 GMT
Well, after much tinkering, I have built your original circuit and it is working - it didn't at first, not sure why. I'm planning on getting a tiny PCB made (ordering something else, so will add one to the corner of the other board), the issue was just space. I have however managed to cram the whole of your circuit (minus the Zener diode - my track runs at 15v so i doubt it is necessary) into a 9mm by 16mm PCB - will let you know how it goes. I can get resistor Arrays that will fit as fours, or as pairs. They values for pairs are 47k, 10k, 4k7, and 1k. at the moment it is 10k:2k as the as the reference, as a ratio of 5:1, would 47k:10k work, as it is the same ratio?
As for the LED function, it is interesting. When i turn it on, it flashes at about 1.5Hz, its a little odd.
|
|
|
Post by tcworld on Jul 13, 2010 16:46:59 GMT
Worked out why it wasn't working before, I have to set my NCE Cab to 28 steps, it just wont respond to the 126 speed step mode? I have to give cudos, other than that it is working well - attached it temporarily to a locos motor by a long wire to drive it around a bit. It programs (tried OPS so far) brilliantly -- I have my test loco going at 0.61 Scale MPH, and that is an N-Scale loco.
|
|
|
Post by tcworld on Jul 13, 2010 23:10:39 GMT
I have worked out why the LED flashes every couple of seconds, the NCE command station has function refreshing on. I take it then the function doesn't remember that it was on the next cycle the code goes through. I had a thought on a possible fix, using the GP3 (pin 4) input. If one were to connect the LED function GP5 to GP3, then write into the code a piece that says, if GP3 is on, set GP5 to on, then in theory, when the controller turns the lighting function on, the new piece of code would keep it on. If this "if" were to be placed in the code just after the DCC packet is read, then when the controller tells the function to turn off, then the new code section would read it as off, and bobs your uncle - in theory at least.
I'm not sure if this would work as i don't know how your code is organised.
|
|
|
Post by Paul Harman on Jul 13, 2010 23:34:06 GMT
Well, after much tinkering, I have built your original circuit and it is working - it didn't at first, not sure why. I'm planning on getting a tiny PCB made (ordering something else, so will add one to the corner of the other board), the issue was just space. I have however managed to cram the whole of your circuit (minus the Zener diode - my track runs at 15v so i doubt it is necessary) into a 9mm by 16mm PCB - will let you know how it goes. I can get resistor Arrays that will fit as fours, or as pairs. They values for pairs are 47k, 10k, 4k7, and 1k. at the moment it is 10k:2k as the as the reference, as a ratio of 5:1, would 47k:10k work, as it is the same ratio? As for the LED function, it is interesting. When i turn it on, it flashes at about 1.5Hz, its a little odd. I would be inclined to use the 10K/1K or 4K7/1K combination to keep the impedance low rather than the higher values, but it may be OK if your environment is not too hostile as far as RF and magnetic fields. Going for a higher ratio will increase the effect of any offset inbalance in the comparator and mismatch in the resistors, but I suspect that will not be measurable. If dropping the zener you should lose the 47R resistor as well since it does not serve any real purpose without the zener present. The resistor is required to avoid cooking the zener, I have seen the zeners go short circuit on commercial decoders with no resistor fitted. The zener circuit is there to help protect against back emf spikes following a short on the track, Relco track cleaners on DC layouts and the Hornby select (60V peak output!) It will be nice to see the PCB.
|
|
|
Post by tcworld on Jul 13, 2010 23:39:46 GMT
I hope I don't fry the decoder, but to fit it in my n-scale loco, there just isn't quite room on the board. I will go for the 4k7 to 1k ratio then.
|
|
|
Post by Paul Harman on Jul 13, 2010 23:41:34 GMT
Worked out why it wasn't working before, I have to set my NCE Cab to 28 steps, it just wont respond to the 126 speed step mode? I have to give cudos, other than that it is working well - attached it temporarily to a locos motor by a long wire to drive it around a bit. It programs (tried OPS so far) brilliantly -- I have my test loco going at 0.61 Scale MPH, and that is an N-Scale loco. There is no support for 126 step mode in this firmware, Heiko Schroeter did not include it - the 126-step instructions are just ignored. If you are keen you should be able to extract it from the function decoder firmware where it just converts the 126-step instruction into a 28-step instruction.
|
|
|
Post by Paul Harman on Jul 13, 2010 23:49:01 GMT
I have worked out why the LED flashes every couple of seconds, the NCE command station has function refreshing on. I take it then the function doesn't remember that it was on the next cycle the code goes through. I had a thought on a possible fix, using the GP3 (pin 4) input. If one were to connect the LED function GP5 to GP3, then write into the code a piece that says, if GP3 is on, set GP5 to on, then in theory, when the controller turns the lighting function on, the new piece of code would keep it on. If this "if" were to be placed in the code just after the DCC packet is read, then when the controller tells the function to turn off, then the new code section would read it as off, and bobs your uncle - in theory at least. I'm not sure if this would work as i don't know how your code is organised. I had a little look but could not see what was going on. Unfortunately the timing is a bit tight, the motor outputs are on the same IO port as the function pin, and IO operations have to write all three output pins at once. Not sure what happens in 14 or 27-step mode. In this mode the function will be written whenever a speed command is sent. It might be worth trying. It should be possible to use one of the motor drive output pins to drive directional lighting between 0V or the blue wire if you don't want to turn it off.
|
|
|
Post by tcworld on Jul 13, 2010 23:58:31 GMT
The way my PCB is layed out, it would actually be very easy to hook directional lighting from the op-amp inputs. Are the op amp inputs (GP2 and GP4) set to high or low when the motor is stopped? Edit: In changing that, I have made room for the zener diode, and the 47R resistor on the PCB. I'm getting three copies of my other PCB made, so will have 3 decoder PCBs. They wont be ready for 3 weeks or so, as I'm going on holiday for a fortnight so am delaying ordering until I get back so I am there to recieve them, but I will certainly let you know how it works out.
|
|
|
Post by Paul Harman on Jul 14, 2010 0:23:03 GMT
The way my PCB is layed out, it would actually be very easy to hook directional lighting from the op-amp inputs. Are the op amp inputs (GP2 and GP4) set to high or low when the motor is stopped? Oh and i have just about made rrom for the zener diode, but not the 47r resistor yet. You will have to measure, but I think it varies depending on whether you are stopped forward or stopped reverse.
|
|
|
Post by tcworld on Jul 14, 2010 0:35:18 GMT
Never mind, that doesn't work, if there is an LED connected to one of the op amp inputs when it is a PWM, it causes the loco to launch off at very quickly. I will try 14 step mode, and see if that cures the Fn outptu problem.
Edit: Nope, it only half fixes it. For odd speed steps the function is on, for even ones the function is off, regardless of how the function is set on the controller.
|
|
|
Post by Paul Harman on Jul 14, 2010 8:09:28 GMT
You must match the speed steps on the controller with CV29. CV29=0 should be OK for 14/27 steps on the controller, CV29=2 for 28 steps on the controller.
|
|
|
Post by tcworld on Jul 14, 2010 12:44:50 GMT
That would make sense. I can't seem to set my ProCAB to 14 step mode, so will have to use CV29 as 2.
|
|
|
Post by tcworld on Jul 15, 2010 14:48:11 GMT
I have been thinking about the function problem, and have come up with a *possible* solution, which would not only fix the problem, but allow the decoder to have 2 functions. Basically, it uses GP3 and GP5 to communicate with a PIC10F200. I will try and experiment with in a fortnight when i return from being on holiday. I can post some untested asm code in the mean time if you wish to have a look.
|
|
|
Post by Paul Harman on Jul 15, 2010 16:15:40 GMT
If you can afford six extra legs, the 16F630 or 16F676 should be a better bet. That will give you six extra function pins, and you will not need much extra code.
|
|
|
Post by tcworld on Jul 15, 2010 16:32:02 GMT
I can afford the six extra legs as two seperate entities, but not as one chip. A 14pin SOIC is actually larger in total that an 8pin Narrow SOIC and a SOT23 amusingly. As it happens, there isn't a great deal of extra code if it works, as I'm not going to try and create a proprietary communication bus, the code on the second pic should be only 30 lines - plus all the configuration settings, and the existing one will get about the same extra.
Granted this way will only yeild a total of 2 functions, but that is all i need. If this works though if should be elementary to use the same method to host as many functions as DCC allows.
|
|
|
Post by s57baj on Dec 30, 2011 22:53:13 GMT
Hi to all, I wonder if anyone has changed the Function part of code so the LED is available at F1? I've built the simplified version of the schematics (still preserving the comparator dual input with only 33k resitor on each side, resistor divider for L272 input 2x2k2 5V-0V, Schottky rectifier, no overvoltage protection) and have no luck by lighting the LED up. The motor worked well right from scratch. I am using a Roco Lokmaus 2 and Roco 10764 booster and changing the values under CV just messes the SW or settings so it becomes unuseful (new programming of 629 is required). For example: if I change the CV1 from 3 (default) to 4, the motor starts to spin at much higher RPM. Changing the acceleration CV3 to 15 (default = 1) causes motor not to spin at all. I read that some misbehaviour might happen due to different settings in Command Station and decoder - this is my first 14 step velocity controller but the design is so excellent that I had to test it, although simplified (I know my voltages on test track) Best regards and all the hapiness in 2012! Andrej So, if anyone has updated the code, please let me know!
|
|
|
Post by torsteins on Nov 16, 2012 2:30:43 GMT
If dropping the zener you should lose the 47R resistor as well since it does not serve any real purpose without the zener present. [...] I'm not so sure about that. R15 together with C1+C2 will act as a filter that will attenuate spikes into the 78L05. However, bear in mind that even with the zener, there is no protection of the L272, with an absolute maximum supply voltage rating of only 28V. (R15, C1+C2 and D3 might perhaps dampen resonances?) Thus I wonder if the zener (or better: a Tranzorb/Transil of similar clamping voltage) should be placed directly after the diode bridge. A related issue: In the component list, the value of R15 is 4R7, i.e. 4.7 ohm. From this discussion and the picture of the decoder, I understand that the actual value should be 10 times higher.
|
|
|
Post by Paul Harman on Nov 16, 2012 12:24:26 GMT
You are correct, R15 should be 47R. Originally it was going to be 4R7 and some kits have the 4R7 in them.
The L272 cannot be protected by a series resistor so a more advanced protection device would have to be provided. There should be sufficient current flowing through the L272 to minimise most over-voltage problems. The Zener was really provided to keep the 78L05 voltage to within spec in the function decoder since it is a more sensitive device than the L272 and the function decoder offers a very low load when all the outputs are off.
Putting a Zener directly after the bridge will result in failure of the Zener to short circuit when high power spikes are present. Some manufactures do this and their decoders fail - the resistor is a key component when the Zener is present to protect the Zener against the effects of excessive current.
|
|
|
Post by torsteins on Nov 16, 2012 16:36:09 GMT
That's why I think a transient voltage supression diode (Tranzorb/Transil) would be a better option. They behave roughly like zeners, but can take much higher transient power. (If you apply high power for a longer period, like the reversing pulse from an old Märklin transformer, you'll fry them anyway.) Common peak powers are 1.5 kW (e.g. the 1.5KE and SM15T series), 600W (e.g. the SM6T, SMBJ and P6KE series) and 400W (e.g. the SMAJ series). Among the manufacturers are Vishay, ST and Fairchild. They don't cost much, either. More here: en.wikipedia.org/wiki/Transient-voltage-suppression_diodeencyclopedia.thefreedictionary.com/Tranzorb
|
|
|
Post by Paul Harman on Nov 18, 2012 10:53:51 GMT
They are interesting, but still a bit expensive I think. It would probably be a good idea to put a bipolar one across the red and black wires, it would guarantee the decoder to be Relco proof.
I would probably use one on a commercial product, but I think that the price is too high for DIY, it would be the second most expensive component in the decoder!
|
|
|
Post by torsteins on Nov 18, 2012 15:59:00 GMT
I wonder if you've only checked the prices of the 1500W types, or that your distributor is overcharging for these devices. From a popular distributor here in Scandinavia (elfa.se), one can get devices from the SM6T, SMBJ and SMAJ series for around USD 0.70 each, including 25% VAT (sales tax). That's around one third of the price for the PIC12F629 (although some of the more recent PICs are a little cheaper), and one fifth of the L727M. A cheap insurance, IMHO.
When selecting such a diode, one should check the standoff and clamping voltages in the datasheet. Some of the series name the devices after their standoff voltage (where the current is only a few microamps), other after their "zener voltage" (typically at 1 mA).
|
|