help needed to calibrate a potentiometer and a few other things

Hi to everyone.
I am relatively new to programming, but I am pleased I found picaxe. It seems alot easier to understand than arduino and seems to be (in my opinion) supported better with good documentation.
The problem I have is that I would like to know how to calibrate 2 potentiometers so that they can be used to proportionately control the period and duty cycle of a pwm output.
I have read the manuals but I could not really find the answer.

Another question, Can someone tell me if it is possible to make analog outputs with picaxe?

Last question could someone please take the time to explain in layman's terms the difference between hexadecimal and ordinary language.
I have the programming picaxe book and it seems to switch between the 2 types (more if you include binary etc.) but I find it is not too clear for a novice and when I see things like %02, I have no idea how to interpret it, or how to translate it into normal code.
I would prefer to stick to just basic language if at all possible

Many thanks

Steve
 

Paix

Senior Member
Code:
100       ; 100 decimal

$64       ; 64 hex
0x64      ; 64 hex note two methods or representing it.

%01100100 ; 01100100 binary
binary 0 1, base 2
decimal 0 1 2 3 4 5 6 7 8 9, base 10
hexadecimal 0 1 2 3 4 5 6 7 8 9 A B C D E F, base 16
so the value of A 10, B 11, C 12, D 13, E 14 and F 15.

So $0A is 10 and $1A is 25 (15 + 10)

Does that make you any the wiser?

Whilst sticking with decimal may be convenient for a lot of things,
binary will show you the pattern which is very helpful and hex goes a long way
to being a good halfway house with less typing. Where bits matter, keep typing . . . binary is best :)

I'll leave someone else to explain the main course of your question. It doesn't look difficult, but obviously has a few gotchas for those that rush in.
 
Code:
100       ; 100 decimal

$64       ; 64 hex
0x64      ; 64 hex note two methods or representing it.

%01100100 ; 01100100 binary
binary 0 1, base 2
decimal 0 1 2 3 4 5 6 7 8 9, base 10
hexadecimal 0 1 2 3 4 5 6 7 8 9 A B C D E F, base 16
so the value of A 10, B 11, C 12, D 13, E 14 and F 15.

So $0A is 10 and $1A is 25 (15 + 10)

Does that make you any the wiser?

Whilst sticking with decimal may be convenient for a lot of things,
binary will show you the pattern which is very helpful and hex goes a long way
to being a good halfway house with less typing. Where bits matter, keep typing . . . binary is best :)

I'll leave someone else to explain the main course of your question. It doesn't look difficult, but obviously has a few gotchas for those that rush in.
Thanks Paix.
I can see that there may be benifits from using binary. But your description of hexadecimal left me not much the wiser.
Are the values A10 B11 C12 .... etc. Veriables? If so I got that. and would $2A = 40? and in what kind of scenareos would you need to use these?
I really would like to be able to get my head round this as it seems to be quite important.

Thanks again

steve
 

Goeytex

Senior Member
"The problem I have is that I would like to know how to calibrate 2 potentiometers so that they can be used to proportionately control the period and duty cycle of a pwm output..."
It is a matter of math. However it is not trivial. The duty cycle is dependent upon the PWM frequency and the PWM frequency range is dependent upon the processor clock speed.

In order to do the math routines we need to know what PWM frequency range is required ???

And a bit of a warning here. The duty cycle can be changed very smoothly with "PWMDUTY". However changing the frequency requires issuing the PWMOUT command, which resets the PWM timer every time it is called. This will cause a short glitch in the PWM signal. So when a pot is used to sweep the frequency the frequency will be glitchy until the pot stops moving.

What is the required frequency range and what is the actual application ?
 

binary1248

Senior Member
The reason people use Hexadecimal is for convince. It is easier to convey and remember something like FA97(hex) rather than the 16 bit binary 1111101010010111. Hexadecimal breaks the binary sequence into easy to remember 4 bit bytes defined by 0 thru F. As an example is I always remember the hex value for some of the common ASCII characters such as ASCII 0 is 30 hex, and ASCII A is 41.
The important thing is understanding the bits in binary, you will learn Hex later, not so important.
.
.
EDIT: If you want I will help you understand binary format, and later Hex format. Please PM me your email so we dont clutter up this thread, or I will help you by using this thread if thats more comfortable for you.
Paul
 
Last edited:

westaust55

Moderator
The PICAXE M2 parts include a single 5-bit (32 level) DAC for analog output.
Another means is to use PWM with a a resistor and capacitor to smooth oh the pulses into an average voltage level.

There are also external DAC chips available that can include 2, 4 or more DAC channels in a single chip with typically 64, 128 or 256 output voltage levels. I posts a thread with details and code examples for several DAC chips in the last if you care to do a forum search (too difficult with iPhone on the move).
 
It is a matter of math. However it is not trivial. The duty cycle is dependent upon the PWM frequency and the PWM frequency range is dependent upon the processor clock speed.

In order to do the math routines we need to know what PWM frequency range is required ???

And a bit of a warning here. The duty cycle can be changed very smoothly with "PWMDUTY". However changing the frequency requires issuing the PWMOUT command, which resets the PWM timer every time it is called. This will cause a short glitch in the PWM signal. So when a pot is used to sweep the frequency the frequency will be glitchy until the pot stops moving.

What is the required frequency range and what is the actual application ?
Goeytex

Oh that sounds quite complicated:eek:
I wanted to build a test bed to test common rail diesel injectors.
I need one pwm signal that controls the rail pressure using an input from a pressure sensor in the rail. (this i believe should be around 180Hz)
And i need a second pwm signal to adjust/simulate different injection pulses on the injectors. Thats what needs adjusting with the 2 pots. (this can vary significantly from around 5Hz for pre/post injection upto 50/60 Hz for main injection. (20Hz is common))

I am not trying to simulate an engine. I just want to build a test bed for injectors so it does not need to be so precise.


Another thing i wanted to build was a cruise control for my van.
That uses potentiometers on the accelerator pedal to interpret the pedal position.
That is why I wanted to know if it is possible to output analog signals from picaxe. That way I could hack in to the pedal signal wires and use an input from the speed sensor to control a varying analog output into the accelerator pedal pots. (not forgetting safety cut out using the brake/clutch pedal switches)

Westaus55

Thanks for the info
 

MPep

Senior Member
Just a thought but do you need to use PWM?
Whilst I realise that it is the most 'apparently' good solution, I suggest using 1 pot for setting the interval (variable pause), and the other for setting the pulse width (pulse out).
 

BeanieBots

Moderator
Another thing i wanted to build was a cruise control for my van.
No, DON'T.
Get that idea a long way out of your mind. You would be making a death trap.
After talking to your insurance company and getting their approval of your design together with a certificate from an independant engineering firm and only then, you might re-consider that option.

As for the actual question about PWM control, I would go along with MPep's comments.
The confusion might be the use of the term "PWM". What he suggests is actually still PWM but when PWM is mentioned here most people immediately think of the in-built PWMout command.
 

Goeytex

Senior Member
I need one pwm signal that controls the rail pressure using an input from a pressure sensor in the rail. (this i believe should be around 180Hz)
This can be done using the Picaxe PWM / PWMDUTY commands, where the frequency is fixed and the signal from the pressure sensor controls the duty cycle. Or the Sensor can simply provide a visual indication of the Pressure and the Pot can be used to adjust the pressure.

Please clarify if you need the sensor to provide a feedback signal to control the pressure for Proportional Control and the Pot controls the setpoint ( complex and complicated) or if the sensor simply provides a readout and the pressure is controlled manually with a pot. We also need to know what sensor you are using, it's interface. Does it supply an analog or digital output? A Datasheet would be helpful.

And i need a second pwm signal to adjust/simulate different injection pulses on the injectors. Thats what needs adjusting with the 2 pots. (this can vary significantly from around 5Hz for pre/post injection upto 50/60 Hz for main injection. (20Hz is common))
The Picaxe PWMOUT does not support frequencies below 50Hz, so it will need to be bit-banged. Probably the simplest and most straight forward way is with using pulsout pauseus, and readadc or readadc10 within a control loop.

Will you be using a standard or peak & hold injector driver ? Which one ?
 
I was getting my ms and Hz mixed up.
I should have said 5ms pre post injection and around 20ms main injection. so that should be around the limit of 50Hz. That should be good enough for testing.
I think I might not yet understand the full concept of PWM, I was under the impression that you set the frequency and adjust the pulse width to vary the on period within that frequency.

Goeytex

The pressure sensor is to provide a feed back signal to proportionaly control the pressure to a fixed pressure that is set via a pot or multi position switch with different fixed values. which is connected to the fuel metering valve on the pumlp. This is used to set the pressure in the rail.

The 2 pots that I talk about control the Piezo electric or solenoid actuated injectors that are supplied fuel from the rail under the pre set pressure, and only adjust the speed and opening times of the injectors. If the pressure sensor in the rail detects that the pressure has dropped it reduces or increases the duty cycle of the fuel metering valve to maintain the pressure in the rail.
The 2 pwm signals work together but are independant of one another.

As for the rail sensor I have no idea what I would use, at this stage it is only an idea.
Probably an analog 2 wire sensor as they seem to be the common fitment on all vehicles that I have seen.

I have no idea what you mean by standard or peak hold injector driver. I am still very much a novice when it comet to electronics.
I was thinking of using power MOSFETs, to switch the injectors, but if that is not a good idea I would like to learn why not.
I am a plant machinery technician, and while I get quite involved with electrics and electronics, it only goes so far.
That is why I want to learn about picaxe and programming, because all to often I have come accross problems where I need understand that little bit deeper.
It seems today that everything is built to be thrown away and replaced when it goes wrong, even though It might be something cheap & small within that could be replaced to get it fixed at a fraction of the cost.
If it can be fixed it costs a fortune because special diagnostic equipment is required, which brings me back to the injector test bed.
I have a car that is worth maybe €2000, it is in really good condition, but the market value is just €2000. The injectors needed replacing and to do that cost €1200 in parts alone.
So for me its a no brainer, learn a bit more so you can fix it yourself.

BeanieBots

I dont see why it should be a death trap? as long as it cuts out as soon as the brake or clutch pedal is pressed, it cant be activated by any other means than by my input and the acceleration is set so it is not too harsh it should be fine.

I appreciate all your help

Steve
 

hippy

Ex-Staff (retired)
I dont see why it should be a death trap? as long as it cuts out as soon as the brake or clutch pedal is pressed, it cant be activated by any other means than by my input and the acceleration is set so it is not too harsh it should be fine.
"as long as..."; that assumes everything works as expected, that there isn't any mistake made in the coding or any adverse event which causes things to behave in an unexpected way.

"it should be fine"; is not acceptable for any safety critical application. "Will be fine" is what needs aiming for and has to provably so.

If you cannot see how it can go wrong that suggests you should not be attempting such a project. If you can see how it could go wrong you should be inclined not to try it.

The same applies if you are thinking of using home-made electronics to control your injectors.
 

BeanieBots

Moderator
... I am still very much a novice when it comet to electronics....

BeanieBots
I dont see why it should be a death trap? as long as it cuts out as soon as the brake or clutch pedal is pressed, it cant be activated by any other means than by my input and the acceleration is set so it is not too harsh it should be fine.
I appreciate all your help
Steve
The reason it would be a death trap is because you would be putting a micro between your foot and the speed control. I'm not saying it can't be done, (that's how most aircraft work these days) but can YOU do it and do it in a totally safe manner.
Here's a very simple scenario. You're at a junction about to turn left with your indicator on. You select first gear and let out the clutch. Just as it fully engages the indicator lamp turns off just as it has many times before. Only this time, the alternator surge (which of course you know all about) is enough to break through the 5v regulator even though you used one good enough for 50v (which is no where near enough by the way). This results in the PICAXE hanging just when the PWM out was high. Net result FULL throttle in first gear going round a left hand corner. Long before you can hit the breaks or clutch you will be in a full tilt doughnut on a busy junction......

There are many-many more examples of what can/could go wrong which is why PIC micros (not just PICAXE) are deamed unsuitable for "safety critical" systems (which cruise control is). Even if you could demonstrate that your hardware was fully fail-safe AND YOUR code was perfect, you cannot do the same for the firmware inside the PICAXE because you do not have (and will not get) access to it. Hence, you could never get your design certified.
Without certification, your insurance will be void.

It might sound like I'm going on like an old nanny but there is much more to electronics within a car than meets the eye. Doing something like an interior light dimmer is one thing, but something that could effect a car in the way a cruise control could is something else.
A car electrical system is described as 12v but there are things you might not be aware of.
Spark plugs generate noise that can put 5kV spikes on lines. (comparable to an ESD discharge)
Turning off the headlights can cause alternator surge as high as 150v for 10's of mS.

If your system can fail in any manner that you or your insurance company can possibly think of and still be 100% safe, then go for it.
 

rossko57

Senior Member
[cruise control] as long as it cuts out as soon as the brake or clutch pedal is pressed,
Tilt already, what happens if you need to stomp on accel to get out of trouble .... easily remedied of course, but an illustration of the possible oversights.

With the injectors, what you are seeking to make is often called a "flow bench", Google for the term to get ideas. Its a good plan to use standard off the vehicle parts, you know they're suitable and durable, like the rail sensor you have in mind already.

An alternative to a complicated variable drive pressure pump is to find a fluid reservoir with generous air space; pressurise to your desired target (which I think can be quite high for diesels).

I would go along with the others, use the Picaxe to generate a variable delay (label that pot "RPM") and pulse duration (label that pot "Load"). And definitely add in a facility to do a fixed numebr of pulses - 1, 50 , 100 - so that you can measure the liquid flow for each injector, probably the most useful feature of a flowbench.

Look into how vehicle ECUs drive injectors - you will get lots of info about peak-n-hold or saturated drive techniques for coil driven injectors from piston-head forums. I'm not so sure about how piezo drive works, but you can probably arrange alternate drive circuits driven from the same pulses easily enough for flexibility.
 
Ok maybe ill ditch the idea of the cruise control.
My apologies to all, I thought my level of english was good enough, but maybe the intonation of some of the things I said were possibly taken the wrong way, or I am misunderstanding maybe what some have replied.
I used to do alot of field trials for a Japanese manufacturer so I am aware of the safety requirements that have to be met. We even had to anticipate how the machine could be misused or "fiddled with" by the end user, and we had to make this as virtually impossible as is possible, or the machine would never make it to market and we could have faced huge fines or prosecution from the powers that be within the European union.
I had considered the possible effects and scenarios mentioned and had ideas for some fail safe devices but did not think it necessary to go into such detail.

My intention was to use available plant machinery parts that I have access to, mounted to an electric motor.
Plant machinery is 24v but its all the same really.

I think it would be hard and dangerous to pressurize a fuel reservoir, as the max pressure in common rail applications can be as high as 2000bar

I like the idea of the variable delay etc, ill look into that further.

my thanks to all who have helped me, especially with regards to understanding Hexadecimal.
 

Paix

Senior Member
@Steve. your level of English is very good. Unfortunately modifying the active parts of vehicles is an area where safety of the individual and others is paramount and any such modification would be unlikely to keep you legally insured.

The consequences of encouraging such activity don't really bear thinking about.

Maybe your diesel motor should have been driving a conveyor belt . . . :)
 
Top