Getting an analogue input to control timing periods between turning on LED's.

Blazemaguire

Senior Member
Hi guys,


I have a student who is producing a PICAXE18X based GCSE coursework project that is essentially a novelty lighting system (think christmass tree lights that you can change the lighting sequence and ALSO the speed of the flashing / sequence.

We have a 10k potentiometer connected as an analogue input (for selecting the speed of flashing), and 3 PTM switches to the other inputs to act as 'sequence selectors' e.g Flashing / alternating /nightrider style etc. And just 8 high powered LED's taking up all the outputs.

We are using PIC Logicator ver 2 to do the programming, as BASIC code is beyond my students capabilities. -

We are having trouble trying to get the analogue input to determine the 'WAIT' period between output changes.

For those familiar with logicator:

So far we have tried writing the value of the analogue input into variable 'A' (which writes in a arbitary value between 0 and 255 depending on the position of the potentiometer) using the EXPRESSION command. - Then using the WAIT command, between turning on and off OUTPUTS you can select to use the value of variable 'A' instead of typing in a time period - hence the speed of each lighting sequence would be proportional to the position of the potentiometer. - now when you simulate this in logicator, it works to a degree, and when you download it to the chip and plug into the PCB it works to a degree (i.e you can see that the POT is definatly having an effect on the speed of pulsing) however it does not have anywhere enough adjustability.

We would like the speed of pulsing to vary from about 2 seconds between pulses to almost faster than the eye can see between the two extremes of movement of the potentiometer.

I am stuck as to how to achieve this, I cannot get a number higher than 255 to be stored in the variable 'A' using logicator, even if I use adition or multiplication of the number. - I think the WAIT command is using the value 255 in A to mean 255 miliseconds, where we would obviously need 2000 to get the maximum 2 seconds delay that we need.

Can I do this with components easily? or would proper BASIC code allow for what we want to achieve? - If so could someone suggest a suitable piece of code that I could look at ( I myself know enough about basic to understand whats going on, and could maybe program the chip without logicator if necessary).

Thanks for reading this essay!

Rob
 
Last edited:

leftyretro

New Member
Hi guys,


I have a student who is producing a PICAXE18X based GCSE coursework project that is essentially a novelty lighting system (think christmass tree lights that you can change the lighting sequence and ALSO the speed of the flashing / sequence.

We have a 10k potentiometer connected as an analogue input (for selecting the speed of flashing), and 3 PTM switches to the other inputs to act as 'sequence selectors' e.g Flashing / alternating /nightrider style etc. And just 8 high powered LED's taking up all the outputs.

We are using PIC Logicator ver 2 to do the programming, as BASIC code is beyond my students capabilities. -

We are having trouble trying to get the analogue input to determine the 'WAIT' period between output changes.

For those familiar with logicator:

So far we have tried writing the value of the analogue input into variable 'A' (which writes in a arbitary value between 0 and 255 depending on the position of the potentiometer) using the EXPRESSION command. - Then using the WAIT command, between turning on and off OUTPUTS you can select to use the value of variable 'A' instead of typing in a time period - hence the speed of each lighting sequence would be proportional to the position of the potentiometer. - now when you simulate this in logicator, it works to a degree, and when you download it to the chip and plug into the PCB it works to a degree (i.e you can see that the POT is definatly having an effect on the speed of pulsing) however it does not have anywhere enough adjustability.

We would like the speed of pulsing to vary from about 2 seconds between pulses to almost faster than the eye can see between the two extremes of movement of the potentiometer.

I am stuck as to how to achieve this, I cannot get a number higher than 255 to be stored in the variable 'A' using logicator, even if I use adition or multiplication of the number. - I think the WAIT command is using the value 255 in A to mean 255 miliseconds, where we would obviously need 2000 to get the maximum 2 seconds delay that we need.

Can I do this with components easily? or would proper BASIC code allow for what we want to achieve? - If so could someone suggest a suitable piece of code that I could look at ( I myself know enough about basic to understand whats going on, and could maybe program the chip without logicator if necessary).

Thanks for reading this essay!

Rob
I'm not great at math but I think you will have to scale the 8 bit A/D commands 0-255 range to a say 0-2000 millsec range needed for the delay argument. So if you read the A/D input, multiply it by 8, and use that result for the delay value you should find that the most of the pots range will work, at least it's worth a quick try.

Lefty
 

eclectic

Moderator
Wait and Pause ?

Blaze/Rob.
Please have a look at Picaxe Manual 2

p.173 WAIT is in whole seconds

p. 106 PAUSE is in milliseconds

Can Logicator replicate these commands/instructions?

e.
 
Last edited:

testerrrs

New Member
Code:
symbol adcpin = 0
symbol adcvalue = b0
symbol pauselen = w1

main:
readadc adcpin, adcvalue 
pauselen = adcvalue * 8
let pins = %11111111
pause pauselen
let pins = %00000000
pause pauselen
goto main
How about that?

Jon
 
Last edited:

Blazemaguire

Senior Member
Thanks for your replys guys,


Will try the code out tomorrow when i'm back at school and let you know what happens.


In regards Logicator, there is only a WAIT command, and no PAUSE command. - I'll post up the code generated from my simple program.... give me five minutes.

Thanks

Rob
 

Blazemaguire

Senior Member
And Lefty thanks for the idea,

I have tried adding / multiplying the value stored in variable A to get the delay up, but the program will only allow 255 as the biggest number to be stored in a variable.

Is this true of programming using BASIC (forgive the ignorance, as I taught myself PIC's using Logicator only). Or do you think its some stupid glitch that logicator has? (I have spotted many other glitches with the program, so it wouldnt suprise me!)

Rob
 

Blazemaguire

Senior Member
As Promised, Here is the code for the program that works as simulated in Logicator.


Cheers.



BASIC converted from Logicator flowsheet:
'Flowsheet1
'Converted on 23/1/2008 at 20:18:20


main:
label_8:
readadc 0,b8 'read A0 to b8
let b0 = b8 'Expression command
gosub prc_FLASH_TO_TIME 'Do Procedure
goto label_8

prc_FLASH_TO_TIME:
let pins = 255 ' %11111111
pause b0 'Wait command
let pins = 0 ' %00000000
return 'End



'Notes
'Variables A-H are shown as B0 to B7 in BASIC
 

testerrrs

New Member
0-255 limit is a limitation of the byte variable. As you can see in the code I posted above, I have used a word variable which allows 0 - 2^16.

So the ADC is read in with 8-bit resolution and scaled up by 8 in a word variable so it doesn't overflow.

Should work fine :)

Jon
 

eclectic

Moderator
On, but not Off long enough?

Rob.

Try these modifications to your program, in the simulator.

prc_FLASH_TO_TIME:
let pins = 255 ' %11111111
pause b0 'Wait command
let pins = 0 ' %00000000
pause b0 ' lights off ************
return 'End

then

prc_FLASH_TO_TIME:
let pins = 255 ' %11111111
pause b0 'Wait command
pause b0 ' Add another ***
let pins = 0 ' %00000000
pause b0
pause b0 ' ** and continue until it looks OK
return 'End

e.
 
Last edited:

james1

New Member
Try this:

Code:
Main:
symbol adc_value = b1

Read_adc:
readadc <pin>, b1     'read acd as b1
gosub flash_sequence
goto read_adc

Flash_sequence:
let pins = %11111111
pause adc_value
let pins = %00000000
pause adc_value
return
 

Blazemaguire

Senior Member
Thanks for those codes gents (or ladies...I shouldnt presume should I!)

I would try them now (at home) but logicator only lets you convert from flow-chart to BASIC, not vice-versa (unless you copy and past the code in and download to a real life chip- unfortunatly, I only have the software here).

Still, i'll let you know the outcome.


Many Thanks again,

Rob
 

eclectic

Moderator
Just to check

Rob, may I just add.

You don't need any hardware to test a basic program.
Just copy and paste from the forum, then run the Simulator.
e.
 
Top