Programming guidance

umoharana

Member
I am a new bee. I am working on my personal project using PICAXE 20X2. This is the first time I am ever exposed any kind of coding of microcontroller. After reading the manual I felt it is easy for me to program picaxe. Hence I am here.

My initial hick up was to make my computer connect to the PICAXE chip. I got over that with help from the forum.

My next step is to write the code for the project.

In my project I will be using "pause" command very offten as an timer.
This pause time is variable. My project will be product and packaged in box. Computer will not be connected. I should be able to increment or decrement this pause value through a PB connected to PICAXE as a input.
Can one some suggest how can I do this ?

How do I write a code if I will have to refer a "pause" value from a registor.
How can I write to register through a PB in increments or decrements ?
Is there a single command to reset values of all registors in the beginning of the program i.e initialisation.

Thanks in advance. I would be needing help more as I go on.

U.Moharana
 

manuka

Senior Member
Greetings! Please specify just what this project is for. Work ? School ? It may be also relevant to know exactly what is in the box, how the PICAXE circuitry itself is to be powered, and the likely interval(s).

PICAXEs normally draw ~5mA when awake, although when snoozing this can drop to microAmp levels. If the "shelf time" is too lengthy the battery may go flat of course! This is no idle alert, as if powered by say a couple of 1000mAh AA cells, the ~5mA circuitry drain will give you an always on life of ~just a week...

Does your PB mean push button? How is the user informed of it's action? PICAXE reading of a switch or sensor state is usually done with the READADC command via a connection at the midpoint of a voltage divider setup-check the the manuals for details. Stan.
 
Last edited:

westaust55

Moderator
If you use a pushbutton switch you will need two to control both increment and deferment of the variable for phase delay duration.
An alternative method could be a potentiometer which needs only one (ADC type) type input.

With switches you can consider using interrupts to detect when a switch has been pressed and adjust the delay variable.
With the ADC input you could scan once on each pass of the main program to loop to find the current pot setting corresponding to the desired delay.

As already suggested, more information about the project will result in more detailed information being provided.
 

hippy

Ex-Staff (retired)
How do I write a code if I will have to refer a "pause" value from a registor.
That's as simple as using "PAUSE <variable>", for example -

Do
w0 = 1000
Pause w0
Toggle C.0
Loop

Run that and the C.0 line will toggle every second, change the "w0=1000" to make the output toggle at different rates.
 

umoharana

Member
Programming Guidance

Thanks for the quick reply to the posting.

I understand that I need to give a brief description of the project. I am basically a photo-enthusiast. The project is about my experiment on high speed photography. I have already made a unit using discrete components and 555 timers for the same purpose. But the system is not very accurate and results are not repetitive. My timing settings are in miliseconds and micro seconds. Hence I have stepped onto developing the system through PICAXE, which I believe would be very accurate. At the moment I am using 20X2. If this is not accurate enough I intend to use 28X2 with external crystal resonators.

My project is very simple. I have already wired / assembled the hardware and need to do necessary coding. The unit has 4 inputs and 4 out puts.
The inputs are a combination of Push buttons, both stay put and momentary.
Out puts are all relay out puts (contacts), which will energige a solenoid valve, trigger the cameras and flashes.

When the unit is powered on, it initialises and waits for the start button to be pressed and the program is once executed type.

Before the start button is pressed, the timer values are set. The results are in terms of photographs. If snaps are not acceptable then timer values are adjusted by combination of Push buttons. Once the system is tuned the timer values are again adjusted in 1/2 ms steps to capture different moments.

After the start button is pressed all the out puts gets energiged after a time delay and remain energiged for predetermined time.

The sequence shall have two modes. A single mode and multi mode. The sequence shall follow the appropriate sequenece based on selection.

My intial thought on the design concept is in the attachment.

I can not use a Potentiometer for setting the timer values and as I will not be able to control values in steps of 1/2 ms.

Power consumption is not an issue. I can run the unit either on battery or on mains with regulated supply. This unit is not on continuous use.

Please see the attachment for more clarity. Please pardon me for my hand writing and the spelling errors that may be there. Posting in a hurry.

I welcome all suggestions and guidances.

Thanks in advance.
 

Attachments

manuka

Senior Member
Thanks-the Forum brains trust will no doubt appreciate the details, especially since high speed photography can be a very specialised & costly field.

Mmm- did I read that right? You surely don't intend photos to be taken at milli & microsecond intervals?! Even rapid fire digital cameras are generally only good for a burst of ~10 shots in a second, & the camera electronics naturally need time to stash these away in memory too.

Is it however an adjustable pre shutter firing delay that you're after? I've seen such techniques used on the likes of Mythbusters when photographing bullet impacts etc,and PICAXES should be up to consistent ms level "hesitations". Tell us more about the subject you are photographing!
 
Last edited:

BillyGreen1973

Senior Member
This should get you started.
Inputs are on the first 4 pins on port C, outputs are on the first 4 pins on port B.
Have a play in the simulator.

C.0 is the 'START' button
C.1 is the 'MODE' switch
C.2 is the 'UP' button
C.3 is the 'DOWN' button

The delay_ms at startup is set to 50ms
Delay_ms increment/decrement is 10, with button repeat every 0.5 seconds
The output will trigger after waiting the set amount of mS (Delay_ms)
The outputs will be high for the set amount of mS(Delay_ms)

If 'MODE' is high and 'START' is held down it will trigger outputs every 'delay_ms'
If 'MODE' is low, outputs only trigger once.

Code:
#picaxe 20x2

symbol Delay_ms = w0

symbol strt=pinc.0
symbol mode=pinc.1
symbol up=pinc.2
symbol dwn=pinc.3

symbol Out1=b.0
symbol Out2=b.1
symbol Out3=b.2
symbol Out4=b.3


init:
Dirsb=255	;set port B as outputs
dirsc=0		;set port C as inputs
outpinsb=0	;ensure port B is all low

delay_ms=50


Main:
if strt=1 then takepic		;check for 'START' button

if up=1 then				;check for 'UP' button
	delay_ms=delay_ms+10 max 2000
	pause 500
endif

if strt=1 then takepic		;check for 'START' button

if dwn=1 then				;check for 'DOWN' button
	delay_ms=delay_ms-10 min 0
	pause 500
endif

if strt=1 then takepic		;check for 'START' button

goto main					;repeat checking loop

takepic:

pause delay_ms		;waits before triggering outputs
let outpinsb=15		;triggers all 4 outputs
pause delay_ms		;waits the set amount of time
let outpinsb=0		;clears outputs
hold:
if strt=1 and mode=0 then hold		;stay here until 'start' button released
if strt=1 and mode=1 then takepic	;check for mode and start button state.
goto main
 
Last edited:

umoharana

Member
I am overwhelmed by the response and the advices that are coming in.

Initially I was little hesitant about opening out fully on my adventure. Now no more. This is the beginning of my experiment on water drop photography. I have already made the complete set up with complete with

-Drop disposal unit with Solenoid valve (one drop / two drops). This can adjust drop size and drop interval.
-Drop sensor. This sensing device senses a falling drop. I have used LDR.
-Timing device. i have two set ups. One triggers the camera and other triggers the flash.
I can use one device for both camera and flash mounted on camera.

I use Canon 550D and canon 430EX flash.

My initial experiments have been good with 20% rejection rate. My repetability is not good. I have used 555 sequential timers where I can adjust timings upto 0.02 seconds (theoritically).
Results are not bad.

I have 3 postings in picasa. In my first posting I have shown photographs of the set up which is much improvised now. This week end I plan to post my new set up.

Other two postings are taken with imrpovised versions. More complex shots are the water drop colision. I give below the PICASA links for you to have a look and comment.

I am passionately involved in this to bring in accuracy in the equipment so that I can concentrate on artistic aspect of this.

I have few more ideas other than this water drop photography. Once I get familiar with coding my experiment will go on to make more complex compositions.

Below are three links to my postings in PICASA on the water drop photography. These photos are still in its infancy. Please feel free to comment.

https://picasaweb.google.com/lh/sredir?uname=umoharana&target=ALBUM&id=5554486644706544417&authkey=Gv1sRgCKn8zLyY8diA1wE&feat=email


https://picasaweb.google.com/lh/sredir?uname=umoharana&target=ALBUM&id=5566875206975750737&authkey=Gv1sRgCJ2Pw-ymypqvxgE&invite=CPaKheQP&feat=email

https://picasaweb.google.com/lh/sredir?uname=umoharana&target=ALBUM&id=5563532463715126369&authkey=Gv1sRgCJ2M5JiBvK3BsgE&invite=COeTmqEM&feat=email

Thanks
 

premelec

Senior Member
Your pictures look great! LDRs are usually fairly slow and perhaps a silicon device like a photo transistor would help stabilize results. Also I have at times modified small camera strobe / flashes by simply using a much smaller discharge capacitor which gives a shorter flash [- and less light.]. Keep up the great photos!

You mention a relay contact - usually relays bounce some and don't work with great timing precision - perhaps a silicon controlled rectifier with direct logic level control could be used...
 
Last edited:

pete20r2

Senior Member
Depends if he's completing the circuit or triggering, I he's got a relay to the flash, thats alot of amps, I don't know if silicon anything will handle that.
But your right, Mechanical relays aren't precision devices.

If he's triggering, then why not use FET's or old fashion transistors.
 

umoharana

Member
For my discrete circuit I have used miniature Relays to interface with my SOV / camera as well as the flash. I use relay contact for the triggering.
This time I intend to use some solid state relays. May be some opto couplers.

Can some one advise me if there is any number key pad which can be interfaced with PICAXE as serial in put ? I can directly key in the timing values instead of using PBs to increment or decrement the values.
If some thing like this is available, please let me know where / how can I buy it ?

Thanks
 

premelec

Senior Member
Hi - I was suggesting the SCR for firing the trigger capacitor into the flash igniter coil... the flash tube staying in parallel with it's energy capacitor...

You'll find a number of references to using common keypads to enter values through resistors being switched into an ADC input - the programming to accept a series of numbers is a bit more complicated but the code may be here too [search on keypad]. The main possible error is when two keys are pushed at once but there are ways to get around that and there was a recent post on that too. If you are using an LCD to read the key inputs you can confirm that everything is going OK as you enter the numbers from the keypad.

Anyhow search this forum for many keypad input references - both multi column / row coding and ADC single terminal input... it's been done many times...

I just took a look at a telephone 3x4 keypad I interfaced with an ADC input - takes 6 resistors - I tested the actual ADC values read with the low accuracy resistors and then used those values to indicate what key had been pressed in the program... since the ADC pin is ratiometric variations of the power supply don't affect the reading...
 
Last edited:

umoharana

Member
Now a days flashes are intelligent flashes. One can adjust the power / flash intensity in different steps to get shorter duration of flash. No need to do anything externally.

I have used this in my set up to get sharper pictures, using shorter duration flash (1/20000 sec).

Since I am new to coding and the picaxe amnuals are not very clear in explaining how to use the commands, I would like to buy a book.
I see that there are two books available for picaxe one is

PICAXE Projects for evil genius and other one is Customising and programming the PICAXE micro controllers.

Can any one suggest, which one to one buy for better understanding of the coding and programming.

Thanks
 

umoharana

Member
PICAXE interface with MOC3020

I have assembled a circuit for my water drop photography and in process of testing the assembly and coding.
The assembly is similar to the circuit attached here and the reference was given to me through one of my earlier postings.

MOC 3020 is connected exactly as per the diagram. Lets us say (20X2) Pin B.7 is connected to pin 1 of the MOC3020.

I write a small test program.

main: high b.7
pause 9000
low b.7
pause 500
go to main

I check the continuity of the terminals 4 & 6 of MOC3020. When pin 1 (moc3020) is held high, I expect that the continuity between pins 4 & 6 should be close. When pin 1 is low it should be open. When pin 1 is high, I get open and close toggling at pins 4 & 6 instead of being steady close. Why should it toggle.

Why is it so ? Is any thing wrong with this.

I have not tested it actually connecting to either camera or a flash ?? I am going to test it soon.

My second question- Can I use MOC3020 to energige a 24VDC Solenoid valve directly ??

Thanks.
 

Attachments

premelec

Senior Member
On the second question - the MOC3020 is a triac output - a triac turned on stays on until the current through it goes lower than its holding current [about .1ma in this case] - so it's not a good choice to switch DC - with AC the current goes to zero with the cycles...

My brain isn't up to the rest of the question just now [after midnight...]

I think you need to look at other optoisolators which are made for DC switching - these are both phototransistor types and 'photo resistor' types [FETs switched by photonic excitation]. In any case your heavier current type units like relays should be actuated by a driver transistor and have a spike killing reverse diode across the relay coil. I'm not entirely clear on exactly what the isolator is 'doing' - define what it needs to do electrically and you can then find the part that will do that [in regard to switching times, voltages, currents etc]. I hope this information is useful to your project...
 
Last edited:

umoharana

Member
Syntax error

I am unable to find out what is the error in the syntax my coding.

I wanted to pin B.5 as one of the input and depending on the status of the pin the program should proceed.

I am attaching the BAS file.

Main:
if drop=1 and mode=1 then takepic ;check for 'drop' buttonif strt=0 and mode=0 then settime
goto main

Syntax error in the first line.
 

Attachments

eclectic

Moderator
At the start
and flash LED
I've marked them with ****

Code:
#picaxe 20x2

symbol delay_ms = w0
symbol strt= pinc.4
symbol mode= pinc.5
symbol tenms= pinc.3
symbol onems= pinc.2
symbol incdec= pinc.0

symbol sov= b.0
symbol cameraled= b.2
symbol camera= b.3
symbol flashled= b.4
symbol drop= pinb.5  ;************
symbol outled= b.6
symbol Out4= b.7


init:
dirsc=0		;set port C as inputs

delay_ms=150


Main:
if strt=1 and mode=1 then Dropsense		;check for 'START' button
if strt=0 and mode=0 then settime
goto main

Dropsense:
if drop=1 then takepic
goto main

settime: 
if tenms=1 and incdec=1 then			;check for '10ms and increase ' button
	delay_ms=delay_ms+10 max 9000
	low outled
	pause 100
	high outled
elseif tenms=1 and incdec=0 then
	delay_ms=delay_ms-10 min 150
	low outled
	pause 100
	high outled
elseif onems=1 and incdec=1 then			;check for '1ms and increase ' button
	delay_ms=delay_ms+1 max 9000
	low outled
	pause 100
	high outled
elseif onems=1 and incdec=0 then
	delay_ms=delay_ms-1 min 150
	low outled
	pause 100
	high outled
	pause 500
end if
goto main					;repeat checking loop

takepic:
pause 100
high sov
pause 25
low sov
high camera
low cameraled
pause delay_ms		;waits before triggering outputs
high flashLED ; ******************
low flashled
pause 200
low flashLED ;******************
high flashled
low camera
high cameraled
high outled
goto main
It passes Syntax.
You must check if it works. :)

E (and OE)
 
Last edited:
Top