Accelerometer and PWM PULSIN command - Event Data Logger

Michael V

Senior Member
Hi Forum,
I'm still developing my event data logger which you have given me heaps of help with http://www.picaxeforum.co.uk/showthread.php?t=7745. This unit (now with 100nf capacitors) is going on a large mining excavator (600 tonne)

The idea is is to measure the pressure differential on the hydraulic filters when the boom passes a predermined point, or angle. That is the "event" in this case. Initially i was going to use an inductive proximity sensor, but after reading up on accelerometers as tilt sensors i found they were about the same price, and could be installed more easily (just with adhesive) on these difficult to access machines. The data sheet says the pulse width modification (duty cycle) output is "easily interfaced with a microcontroller". A walk in the park for the Picaxe i thought.

I found the PULSIN command in the manual, looked up the threads on pulsin. A one liner reads the value into a word variable. I could fine tune the limits without making a hardware change on the machine. I could put in a nice solid box with a 5V voltage regulator. I was sold.

I purchased a Sparkfun accelerometer board http://www.sparkfun.com/commerce/product_info.php?products_id=400 the ADXL202JE. which in Australia you can get overnight express post in capital cities from http://www.oceancontrols.com.au/Sensors/sfe/accelerometers_sensors.htm. These are a tiny little thing. Data sheets at both those sites.

I wired it up to the PWM output, and put in the following code, hoping to see the the value of the word variable as a number between 1 and 65535 displayed:

Code:
'PICAXE-18X - Read Accelerometer PWM and display it on screen terminal

Symbol y_axis = w1
symbol x_axis = w2

main:

pulsin 0,1,w1     ‘ record the length of a pulse on pin 
pulsin 1,1,w2     ‘ record the length of a pulse on pin 
sertxd ("y axis,",y_axis,"x axis,",x_axis,13,10)

Pause 200
goto main
Instead of getting a number for the variable i just get strange characters. I know the thing is working, because when i hold it still, the characters don't change, when i rotate it they change to other strange characters, and if i rotate through one axis, only one set of characters change.

There must be something basic i am not doing , and i don't think its the Hex thing i was caught out on before. i tried state as both 1 and 0, same result. The pulsin command is simple, and the accelerometer board is designed for microcontrollers.

What am i doing wrong?
 

hippy

Technical Support
Staff member
You forgot the # symbols to make the numbers appear as numbers ...

- sertxd ( "y axis,", #y_axis, "x axis,", #x_axis, 13, 10 )
 

Michael V

Senior Member
That worked

I knew it had to be something simple.

This works:
Code:
'PICAXE-18X - Read Accelerometer PWM and display it on screen terminal

Symbol y_axis = w1
symbol x_axis = w2

main:

pulsin 0,1,w1 ‘ record the length of a pulse on pin 
pulsin 1,1,w2 ‘ record the length of a pulse on pin 
sertxd ("y axis, ",#y_axis," x axis,",#x_axis,13,10)

Pause 200
goto main
It gives values around 320 when horizontal to 420 when vertical, and around 200 when upside down. I guess that is 320 x 10 us = 3.2 milliseconds. WHatever it is i can work with it, we will just boom out to the level we want and that will be the limit point.

Another question, Can i use PWM over a distance? Do i lose accuracy over a 10m cable length? The tilt sensor will be out getting dirty while the Picaxe will be nice and safe in the operator cabin.

Or, should i put a 08M in with the sensor and transmit the info in some other form? I'm a bit confused as to when Rs232, RS485, and I2C (for the display) can be used over distances, and with a lot of metal around.
 

hippy

Technical Support
Staff member
It's a digital signal so the problems ( with any serial data which is what PWM is at heart ) are, loss of voltage due to cable resistance, slewing/sloping of edges which makes pulses change their width, noise superimposed on the signal, ringing so you don't get nice clean on-off transitions. Probably other things which don't come to mind. Dirt and grime are probably the least of your problems if you fit it in a decent enviromentally protected box. Vibration and sudden movement and stops may cause more problems.

Shielded cable, twisted pair, balanced lines (RS485) and some careful tweaking of the transmitter and receiver can all help to reduce problems. DMX serial at 250kbps through 1km of coiled bog-standard mains cable with an arc welder waving over it using RS485 was corruption free under testing I did so it should be possible to sove most problems.

The advantage of putting the PICAXE up with the sensor is when the sensor sends out lots of data but only a little information needs passing on. The PICAXE can use a low baud rate to send data serially which will usually be a lot more immune to all the nasty effects mentioned without fancy electronics.

It's probably one of those things which is ideally prototyped and tested to see how well it works in practice before getting too carried away with designing a perfectly immune system. It's also possible to do software filtering so you can throw away unexpected ( corrupted ) readings.

Ideally put a scope on the signal lines and look what's happening. That also helps when trying to solve interference problems, far better than simply guessing what might or might not work, where solving one issue may worsen another. You get instant feedback as you try putting caps and resistors across lines.
 

Michael V

Senior Member
Ripples

Thanks Hippy,
In the case of the accelerometer it is really only going to be used as a trigger point mid way through a few seconds of steady flow, so its not so critical, i am just curious. It is more relevant to the pressure transducers.

Last weekend i installed two 20 Bar pressure transducers (i bought cheap on eBay for $60) only to find my pressures were less than 1 bar. I expected much more. Transducer signal is voltage, o-5 V. I used screened micrrophone cable over 4-8m, flexible and robust. I attached the signals to my LabJack USB data logging module, which connects to the laptop. Like an oscilloscope i guess, that is the prototype.

I had to multiply the signal by 40, to get 50% of scale on the graph so i think i know what you mean by noise, and the need for software filtering. Even with the noise the difference is useful, plus or minus 10 percent accuracy would be adequate, since we have no measurement at all now. I will have to amplify (or buy more expensive $300 transducers) to get an acceptable level for the a/d conversion of the picaxe.

Regarding software filtering, i guess that is something i need to know more about. I have had a taste of it in the recent post on the DS18B20. http://www.picaxeforum.co.uk/showthread.php?t=7960&page=2 I will use that logic for the DS18B20, and similar logic for the accelerometer - eg multiple positives before accepting the change of state.

I thought to take a number of readings (eg 5) over one second and average them as a way of smoothing out the ripples, i.e filtering. But i can see that when i start adding numbers up that are mid way in the a/d range, then , i will go over the maximum value for the word or byte variables, and the numbers won't mean anything. Do you have any suggestions on software filtering for a ripply signal??
 
Top