# Can Some one verify this?

I am currently working with a CH-925 coin validator, that is not a pivotal part of my question though, however it is the simplest way to state the problem.

Asian reverse-engineers in all of their intelligence and genius did not program in a break between the pulse trains for 2 different coins, so if you have the pulse value of a penny set to 1, nickle set to 5, quarter set to 3....

a person puts in a penny back to back with a nickle and they would be able to have 50 cents worth of credit, a loss of 43 cents for the vender...the probelm is pretty well documented with this hardware.

For example, in this video, As the author says, he had difficulties differenciate between coins and he relies on a timeout of 200ms to convert counted pulses to actual coins. That works pretty well if you leave time between coin insertions, but otherwise, you'll run into two issues:

• Issue #1: the program can be fooled by quickly inserting a 50p followed by a 10p, because the train of 4 pulses for 50p will take at least half a second (4 * (20+100)ms) and the 2 pulses for the 10p will be queued next to it, forming a 6-pulse train that will be seen as £2 => seller loses
• Issue #2: the program can also get stuck by quickly inserting two 50p coins for example, because the train will be 8 pulses long and that case is not handled by the code and those coins will get igored => customer loses

Let's take a look at another very popular example :http://timewitharduino.blogspot.be/2014/01/isr-based-sketch-for-adafruit-coin.html :
It also relies on a "time-out" of 200ms on the COIN line to count the pulses and determine which coin was inserted, and suffers similar issues:

• Issue #1: quickly inserting a \$1 ("loonie") followed by a \$0.25 ("quarter") will result in a train of 15 pulses which will display (and credit) \$2 => seller loses
• Issue #2 is "somewhat" handled by a specific "Unknown coin" case. For example, quickly inserting two \$1 coins will cause 20 pulses and make the code fall in the "Unknown coin" case. However, as there is no way to return coins, unless this alerts the store manager, they will be "lost". And even if the store manager gets an alert and looks at the logs, he won't be able to tell which coins were inserted to make 20 pulses: Was it 2*\$1 or 4*\$0.25 or another combination ?

i believe i have come up with a way to solve this but, i would like to know if it could apply to any pulse train of definable pulses( a pulse train, consisting of mixed values, of known pulse sets [example: 7 pulses,11,pulses,3 pulses])

using prime numbers:

``````if the values of the denominations are set to the prime numbers;3,11,17,19,23,29 there is no crossing point within the
human achievable insert speed. What i mean by this is there is no way you would be able to accurately (based
on the speed of recognition) inser coins, that would generate a pulse train that could be confused with any thing but
the actual values that are contained in the pulse train.

1c 	5c 	10c 	25c 	1\$ 	1\$ gold
3 	11 	17  	19 	23 	29
___________________________________________________
1	3	11	17	19	23	29
2	6	22	34	38	46	58
3	9	33	51	57	69	87
4	12	44	68	76	92	116
5	15	55	85	95	115	145
6	18	66	102	114	138	174
7	21	77	119	133	161	203
8	24	88	136	152	184	232
9	27	99	153	171	207	261
10	30	110	170	190	230	290
``````

im not honestly really sure i can explain this very well.

all of the numbers in the table meet these rules:
is evenly divisible by itself...
is not divisible evenly by another number
sum can be divided by 2 numbers and equal their parts. (Goldbach's conjecture[Goldbach’s conjecture — Every even integer greater than 2 can be represented as the sum of two primes numbers.]) used for 2 coins worth of pulses back to back...

my theory on how to figure out a random pulse train would be

i am still working on how i would check against a random insertion of coins that generate a random pulse train with no break but i think the arduino is fast enough to detect the small hesitation.

however there is only one problem with this and that is the amount of time it takes to generate the rewuired number of pulses. the machine generates the pulses and then cues the other coin pulses immediately behind the first set of pulses, so there would be no hesitation.

suggestions for how i would go about a random pulse parse would be helpful as well, i would also like to know if you see any problems with this number scheme?

tbillion:
however there is only one problem with this and that is the amount of time it takes to generate the rewuired number of pulses. the machine generates the pulses and then cues the other coin pulses immediately behind the first set of pulses, so there would be no hesitation.

Queues the other coin pulses, you mean? Why is this a problem?

Sounds like a good reason not to use a CH-925 coin validator.

...R

100% agree … but i think the old adage is “the customer is always right” and since the customer is my nephew, and he already got his dad to buy the parts without consulting me first, i suppose now its the uncles job to “just make it work” i mean i can make it work, but i was trying to come up with a way to :

Not have a delay, because they are blocking code and i try to stay brick wall free {blockage}
not have to worry about how fast my nephew puts in the coins and still have accurate accounting
since my nephew really cant read id prefer not to have to tell him to wait, plus children are immeasurably impatient…

@aarg

its an issue because you cant differentiate between the coins it just keeps firing pulses(infinite coins = infinite pulse train)… 50 pennies could look like a dollar… etc. depending on what you set the pulse values to, and so i was considering prime numbers, because they are easy to pull from large numbers, and they well are only divisible by themselves and 1…

i have been working on hacking the serial output of the device, its some sort of diagnostic terminal and i cant find any information about it any where, probably because its pseudo proprietary, i have managed to get data sets out of the device over serial, but i havent found a way to reliably interpret the information, i am trying to come up with the plan B for my Christmas deadline… if i cant get the serial to work, then i am going to have to fall back to some intermittently working junky wait routine probably kill that 200ms just drawing the BMP to the display with the red stop sign logo… haha

tbillion:
100% agree .. but i think the old adage is "the customer is always right" and since the customer is my nephew, and he already got his dad to buy the parts without consulting me first, i suppose now its the uncles job to "just make it work"

I feel for you

its an issue because you cant differentiate between the coins it just keeps firing pulses(infinite coins = infinite pulse train)...

Presumably there is a practical limit to how many coins will be inserted so that there will be a large gap (in human and in Arduino terms) between one group of coins and the next - even if someone is trying to trick the system.

Maybe a solution is to count all the pulses between two gaps and only when the second gap is detected make an attempt to see what combination of coin-pulses will give you the number of pulses that have been counted.

I wonder if you ascribe power-of-two values to the coin-pulses can you figure out the individual coins from the total. If so it would be simpler than using prime numbers.

...R

if you assign every coin type a prime number then with factorization of pulses count you get exact count and value of coins. but it the count is wrong (missed or false pulses), then I do not know if the error could be detect/corrected.

edit: striked - not true, my error

in this big family and being the only person who is decent with electronics, i am sort of regarded as a wizard of sorts, its pretty hard to keep up with every one all at the same time. now my 14 siblings are all working on having their own families so the uncle title keeps growing, in a world with increasing technology, it is fascinating to them to build it themselves. doesn't stop me every moment from wanting to stab my brother in law for coming up with this stupid piggy bank..

Presumably there is a practical limit to how many coins will be inserted so that there will be a large gap (in human and in Arduino terms) between one group of coins and the next - even if someone is trying to trick the system.

absolutely, and due to the closed nature of the device, im not sure exactly how big its que is for stored pulses, that represent coins, the most technical information i have found on this device is here the information he pulled from the serial port of the ch925 with his scope i have been able to verify with the serial terminal on the arduino, only real difference is i have USD he has GBP. the point of me mentioning that page is because he has some pretty good scope images captured, they show the problem very clearly, i can also verify that the problem does occur, i have used example code to verify if two coins are placed in the machine within the time it takes for the device to generate the pulses for the previous coin, all the pulses come out on top of each other, my scope isnt as fancy, but it works (when it feels like it )

Maybe a solution is to count all the pulses between two gaps and only when the second gap is detected make an attempt to see what combination of coin-pulses will give you the number of pulses that have been counted.

this was actually the direction i was going, with this post especially. the critical problem i see with this which is why i had gone with prime numbers is because it is a way to make a number that is otherwise just a number unique, and when you are dealing with a lot of the exact same data parsing it becomes a matter of how you can make 0's and 1's unique. what would your best suggestion be for going about seeing how many coins fit in a pulse train, im not quite sure arduino would be good at brute forcing .. lol

I wonder if you ascribe power-of-two values to the coin-pulses can you figure out the individual coins from the total. If so it would be simpler than using prime numbers.

much simpler, except the maximum number of pulses per coin is 50, and 50 pulses takes 150ms to receive on "fast" mode. that was something i was going to mention above when i was talking about the pulse que. the issue isnt really the small value coins its that someone could insert a second coin within the 150ms space, for example if 50 pulses per coin is the gold dollar, a casual insertion of the coins would have you either with a full buffer in the device, depending on the variable size that controls the pulse loop. or you could have a several second pulse train, the situation rapidly gets out of control when you consider each of my great grand parents give each of us a roll of gold dollars for christmas (20 * 150ms = 3 seconds a roll, 6 grand parents 18 seconds) that not to mention if my nephew puts his 6 rolls in at one time plus any other change he has. if we even manage to ignore that single instance the average pocket full of change has at least 15 coins of varied value. that could accumulate just as well.

Juraj:
if you assign every coin type a prime number then with factorization of pulses count you get exact count and value of coins. but it the count is wrong (missed or false pulses), then I do not know if the error could be detect/corrected.

surprisingly, the pulses are stupid reliable. I have made some pretty iffy connections and had the scope pegged into it and see very little spike or error, ive also never seen a "false trigger" it only triggers if it is "sure" the coin is good. and the wires between the arduino and the coin mech currently are ground shielded, which was part of another recommendation that i got from another forum when we were originally talking about 3 foot of wire. the wire now is maybe 30mm, and thats the permanent install.

can you miss a pulse with an arduino if it is on an interrupt? i know you can if it is just in a routine, but all the examples ive seen using this hardware all function on interrupt.

totally off topic for a second, if they would just standardize these things like the bill acceptor i have which uses both pulse, and the "mars serial link"(9600-8N1) this conversation wouldn't even be a topic. took me about 15 minutes to write the code for the APEX 5400 bill acceptor i have. i got 6 of them on a steal for \$150, normally they are between \$75 and \$200 each. the guy couldn't get them to work so i got the whole box, turns out he was reading the wrong schematic.

taking a quick look at the little kids version of "factorization of prime numbers" it might be a challenge to break it down correctly, one wrong move and it could be just as bad as the other original methods. and i think to factor it you would still have to wait for the entire pulse train. Until robin pointed that out i really wasn't thinking about the length of how long the train could be. it gets further complicated by the fact that each prime number is not an actual representation of the actual coin value. 3 = 1c.

nope prime factorization wont work, because the number created is either prime or it will break it down to the smallest prime number which is 2 and 2 doesnt represent a coin value ...

pulse train: 3+11+23+17+11+11+17+19+19
composite number 131(pulses)
131 is prime...

or a worse example is the prime factorization of 261 which comes out to be 3^2*29, on the chart 261 is a number that i have figured initially as 9 gold dollars, but with prime factorization it comes out to be \$1.02 ... lol thats a big loss.

my error. for decoding with factorization the number must be encoded as a multiplication of primes, not sum

tbillion:
im not sure exactly how big its que is for stored pulses, that represent coins,

When I mentioned "a practical limit to how many coins will be inserted" I was not thinking about the machine's limits but, rather, about the user's limits.

I suspect, even if it would not bother the machine, that it is unlikely that a user will try to feed in 1000 coins. What about 100? Or 50? Or maybe not as many as 10.

Do you have the option of returning all the coins to the user if you get tired of counting pulses - i.e. if the number of pulses exceeds some limit that you can set? (Better still just return the excess coins and give no value for the earlier ones so the user quickly learns not to mess with the system )

That brought to mind whether you have the option to enforce a gap between coins - perhaps by limiting any one count before a gap to the value of the largest coin.

...R

ok i think i can solve all of those things with an additional piece of hardware. i just woke up and read your post and it dawned on me, coin star. thos machines are meant to take massive user input and if i was to implement a tray to catch all the coins with a rotating wheel inside it , (which i happen to already have printed [3d printer owner here]) i could just have a slot, with an optical break detector, when my nephew puts in a coin it starts a time out timer, once he has inserted all the coins, and presses “go” on the touch screen or the time out value is reached the wheel at a predetermined interval pushes the coins into the acceptor.

i think this meets all of the criteria:

1. establish a gap between the coins to allow pulse differentiation / control rate of insertion
2. independence from user input speed
3. controlled return of all things that are not a coin/have no value
4 to some extent optimize "what the pulse train looks like: giving it a uniformity.

the stepper motor could make sure that a coin is fed in every 145 ms, this would be enough time between the coins to basically say the maximum amount of time that the pulse train should be will be 140ms (7 pulses, @ 20ms ea) + a guaranteed 5ms gap. attach a feeder tube to the coin input and a return out put to the return chute and walla!!!

can anyone see an issue with that?

(Better still just return the excess coins and give no value for the earlier ones so the user quickly learns not to mess with the system )

haha, i love your way of thinking, and trust me, friends of the family are already gearing up to try and fool it. its quite upsetting at times, work so hard to make something nice and people immediately set out to break it .

tbillion:
its quite upsetting at times, work so hard to make something nice and people immediately set out to break it .

I have had a few experiences where I created something for my own use that works perfectly for me and the first time a friend tried it he did something perfectly sensible that I had not allowed for and it failed. There was no sense that my friend was trying to find fault - he was just doing what he thought was correct.

I think I would draw the line at building something if I knew the work was not going to be appreciated, and especially if it people were deliberately going to try to make it fail.

Part of the problem is that because you produce stuff people think it takes no effort.

...R

Maybe I don't understand but it seems tome that if the pulses are settable and the implication from your post above is that is true, you simply have to attach some proportional value to the number of pulses.

``````nickel  = 1
dime   = 2
quarter = 5
dollar = 20
``````

Or is it that the pulses cannot be set?

BulldogLowell:
you simply have to attach some proportional value to the number of pulses.

Now that seems clever.

I reckon that is how the system is intended to be used. Asian engineers were not so stupid after all.

...R

Robin2:
Asian engineers were not so stupid after all.

Particularly when it come to counting money... as we all are.

Maybe I don’t understand but it seems tome that if the pulses are settable and the implication from your post above is that is true, you simply have to attach some proportional value to the number of pulses.

the pulses can be set, and i love the way your answer works, until we talk about pennies… then it doesn’t work any more. in the confines of the output of the coin acceptor, there is no proportional values for a penny that work, because you would need 100 pulses for a dollar. which is unable to be had. and would take at the fastest 3 seconds to send. if there was a proportional answer that would include pennies and not additional hardware i would be all over that. Or, better yet if the government got rid of pennies, which with the inflation problem pennies really are useless, they cost more to make than their worth.

little kids are always swath with pennies, so really before anything else i would actually say pennies are more important than the dollar coins. it is a “penny bank” after all

have had a few experiences where I created something for my own use that works perfectly for me and the first time a friend tried it he did something perfectly sensible that I had not allowed for and it failed. There was no sense that my friend was trying to find fault - he was just doing what he thought was correct.

I think I would draw the line at building something if I knew the work was not going to be appreciated, and especially if it people were deliberately going to try to make it fail.

Part of the problem is that because you produce stuff people think it takes no effort.

i like when people point out flaws and change my thinking process to improve the design, but there are a few people that i unfortunately have to deal with that are purely malicious people. i think people have lost all value in the art of creation it gives a feel of, since they couldn’t or wouldn’t do it that in essence what you do means nothing. every once and a while i get a good customer, who does value creativity, but they are few and far in between. most people just want something they can use for 10 minutes and then be done with it .

i never said they were stupid, perhaps we should rephrase to “not forward thinking” because a device that could be fooled with cash manipulation isn’t a very forward thinking device. every malicious person on the face of the planet trys to manipulate money.

tbillion:
because you would need 100 pulses for a dollar. which is unable to be had. and would take at the fastest 3 seconds to send.

little kids are always swath with pennies,

Maybe it's all coming together nicely. Put a big sign that says 50c max coin. If some fool puts in a dollar then you win.

...R

3, 11, and 17 would not work. 2 pennies and one nickel would be the same as 1 dime. 3+3+11=17.

3, 11, and 17 would not work. 2 pennies and one nickel would be the same as 1 dime. 3+3+11=17.

good catch and reasonably 3 coins could be inserted within 150ms, so i would have to change out prbably the 3 for a higher prime number. higher prime numbers i noticed have a harder time replicating themselves in other sums of prime numbers.

Maybe it's all coming together nicely. Put a big sign that says 50c max coin. If some fool puts in a dollar then you win.