Some Help Please

Symon20

New Member
my project is a light that automatically turns on as light levels drop and has a specific program for if full beam is needed for a breif period,
this is all working fine on simulation, but once i program it into the pic the ouputs from the pic are completely different to that on the simulation
the program goes like this:
Code:
main:

prog: 
	if pinc.2 = 1 then push 	'if pinC.2 gets a pulse high then go to the program Push
					
	readadc c.1, b3			'convert analouge signal from C.1 and send as digital signal to B.3
					
goto main

push:					
	high b1 				'take pin b1 high				 
	b1=255				'let b1 = $255
	wait 1				'wait for one second 
	for b1=255 to 0 step - 2	             'step down two $ levels each time round
	pwmout B.3,255,b1			
	readadc c.1, b2			'check the input at b2
	if b2=b1 then goto main		'if b2 = b1 then go back to the start of the program
	pause 10				'stop for 10 milliseconds
	next					'go back to the line pwmout B.3,255,b1



goto main
any criticism's appreciated

Regards
Symon20
 

hippy

Ex-Staff (retired)
It may help if you could describe the hardware you have; what's connected to C.1 and C.2, how the program is meant to operate, what it achieves, and in what way the program differs from when run in simulation.

Which PICAXE are you using and are you sure the following is correct ...

high b1 'take pin b1 high

That's not actually controlling pin B.1
 

nick12ab

Senior Member
Can you say how it behaves differently?

Regarding your code, for pwmout, the period value is set to 255 but the duty is being set only by a byte variable so the biggest duty cycle you can get is 25% as the period value has to be 1/4 of the duty value for a 100% duty cycle. Change the period value to 63 if you want the light to be able to run at fiull brightness.

Also, that first line after the push label says 'high b1' which makes whatever pin represented by the number in variable b1 high. Do you mean to put 'B.1' instead?

any criticism's appreciated
You're not supposed to use apostrophes on plurals and breif is spelt 'brief'.
 

Symon20

New Member
sorry,
i am using an 18M2 pic,
the input coming into C.1 is a Light sensor (LDR),
C.2 is just a push to make switch,
I have a luxeon as an output, which as the light surrounding the light sensor gets lower the intensity of the Luxeon increases proportionaly,
If however the push to make switch on pin C.2 is pressed then the light intensity goes to full beam and start to dim until it is equal to the input being given by the light sensor.
but the PIC is not giving out the same voltages it gets in from the Light sensor, so the Luxeon is not dimming or brightening.

Also, that first line after the push label says 'high b1' which makes whatever pin represented by the number in variable b1 high. Do you mean to put 'B.1' instead?
i have tried writing the code in as B.1 but the program will not allow it,

regards
symon20
 

nick12ab

Senior Member
i have tried writing the code in as B.1 but the program will not allow it,
What? Since when has 'high B.1' been disallowed by the compiler? Remember that for the high command you use 'B.1' and not 'pinB.1' as they are actually very different!
 

nick12ab

Senior Member
Anyway, is it working now and if not why not?

Note to self: When a new user starts a new thread but the user has some previous posts as indicated by their post count, check them out to see whether they're just re-asking stuff.
 

hippy

Ex-Staff (retired)
for b1=255 to 0 step - 2 'step down two $ levels each time round
pwmout B.3,255,b1
readadc c.1, b2 'check the input at b2
if b2=b1 then goto main 'if b2 = b1 then go back to the start of the program
What happens if b1 steps 255, 253, 251 etc as it will according to the FOR-NEXT and your READADC returns a value of 254 ? Any even number for that matter.

Also what happens if the READADC returns say 10, and b1 has decremented to 251 and then READADC jumps up to 252 ?
 
Top