I'm using the Logicator to get me started, but all it lets you do is 0-100 duty, no dropdown for a variable. Unless the dropdown gets filled up as you define variables in Logicator, but haven't tested that to see if that's the case...Welcome to the forum.
The syntax is:-
PWM pin,duty,cycles
PWM is the command, pin,duty & cycles can be constants OR variables.
What other input do you need/want?
Two points.I'm using the Logicator to get me started, but all it lets you do is 0-100 duty, no dropdown for a variable. Unless the dropdown gets filled up as you define variables in Logicator, but haven't tested that to see if that's the case...
THANKS!
http://www.rev-ed.co.uk/docs/cat_06.pdfWhat is Logicator? Is that another term for the flowsheet design?
To get started I was looking to read an analog voltage on a pin and output a PWM in relation to it.Two points.
1. Can you provide more background information
about your project / requirements?
2. Seriously consider using BASIC.
Manual 2, page 160.
And the "Wizard" from Programming Editor.
e
PIK-E.To get started I was looking to read an analog voltage on a pin and output a PWM in relation to it.
Thanks!
#picaxe 08M
Main:
readadc 1,b0 ; Reads a value between 0-255
pwmout 2, 62, b0; outputs value
; Varies LED brightness from off(0) to full(255)
pause 100 ; pause for 1/10th sec.
goto Main ; start again
All right, now things are starting to work, any idea why pause doesn't pause? I played around with the values, but no affect on PWM frequency. Is the PWM frequency fixed for the PWMOUT function block? Or does pause only affect the time it takes to update the PWMOUT block?PIK-E.
Logicator, AFAIK, is a superb program for initial education.
For your simple voltage - pwm however,
try something like:
eCode:#picaxe 08M Main: readadc 1,b0 ; Reads a value between 0-255 pwmout 2, 62, b0; outputs value ; Varies LED brightness from off(0) to full(255) pause 100 ; pause for 1/10th sec. goto Main ; start again
Not sure I fully understand the question but you've perhaps misunderstood how PWMOUT works. The second parameter (62) sets the frequency, the third (b0) sets the duty cycle.All right, now things are starting to work, any idea why pause doesn't pause? I played around with the values, but no affect on PWM frequency. Is the PWM frequency fixed for the PWMOUT function block? Or does pause only affect the time it takes to update the PWMOUT block?
THANKS!!
Agreed, as far as the interrupt goes, I was trying to force it to work. Even with it configured as this below, still no override of the main program based on the interrupt input.I'm afraid your code does not make a lot of sense. You cannot use an interrupt routine in the way you are doing - it should be a separate subroutine in its own right, ending with a RETURN and also probably issuing a SETINT to accept further interrupts - you cannot 'fall into' the interrupt as you are doing nor can you GOTO out of the interrupt routine. Also the "POKE" makes no sense; you probably meant "let varA = 0".
It's hard to give an example which would work because it's not clear exactly what you are trying to achieve. What do you want to happen when pin 4 goes high ? Presumably you want to set the duty to zero, but then what ?
You probably don't even need interrupt. You could check what the level of Pin 4 is within your main loop.
I was shooting for (Input) 4 interrupting the main PWMOUT loop, setting PWMOUT to 0 and looping there until the micro was reset. I thought that once I set the varA to 0 that on the next cycle it would be 0, but it wasn't reduced by any amount.The problem is that you enter the interrupt, set varA = 0, return to somewhere in the main loop, and some short time later re-read the ADC into varA and set the PWMOUT from that varA+10, which will no longer be zero.
What exactly are you trying to achieve ? What do you want to happen when pin 4 goes high ? What do you want to happen after that ?
Perhaps you could do two things:I was shooting for (Input) 4 interrupting the main PWMOUT loop, setting PWMOUT to 0 and looping there until the micro was reset. I thought that once I set the varA to 0 that on the next cycle it would be 0, but it wasn't reduced by any amount.
Thanks for your help!
1) Unfortunately all I have is the PicAxe proto-board connected to a larger breadboard with a pot, resistor & LED, and a small scope to take a look at. I wanted to see functionality, hence the breadboard.Perhaps you could do two things:
1. Post a circuit / schematic / HQ photograph of your setup.
2. Use five or six short, linked
bullet point statements,
in straightforward English (not BASIC),
explaining your requirements.
e
Well that's relatively easy if you think of it in terms of 'generate PWM until pin 4 goes high, then stop PWM, and do nothing more. In Basic but I'm sure you'll figure how to turn it into flowchart blocks ...I was shooting for (Input) 4 interrupting the main PWMOUT loop, setting PWMOUT to 0 and looping there until the micro was reset.
It looks like I have something finally working. Guess I have a long way to go in order to 'see' what the micro is expecting vs what I want it to do.Well that's relatively easy if you think of it in terms of 'generate PWM until pin 4 goes high, then stop PWM, and do nothing more. In Basic but I'm sure you'll figure how to turn it into flowchart blocks ...
label_80:
readadc 1,varA
let varA = varA + 10
pwmout 2, 71, b0
pause 100
If pin4 <> 1 goto label_80
pwmout 2, 71, 0
label_81:
goto label_81
But not if you are after the specification given in an earlier post - "I was shooting for (Input) 4 interrupting the main PWMOUT loop, setting PWMOUT to 0 and looping there until the micro was reset."It looks like I have something finally working.
I agree, i guess i jumped to it working as far as i could actually get the PWM to 0 with input 4 input high. That was a first over 20 or more other attempts to make it do that. Its a milestone when it responds vs doing nothing. Sure, I would like to have it hang there till reset. True, I still need to loop until reset, and test how long it takes to get to 0 PWM so there's more for me to do. Logicator doesn't offer as much versatility for doing what I'm after, and my basic programming skills are still nil, I was hoping to use logicator to allow me to draw up in a flow chart manner (similar to labview) and looking at code via Logicator is a great idea since you have a flow and code representation together. I seem to have found its limitation forcing me into basic much sooner than I would like.But not if you are after the specification given in an earlier post - "I was shooting for (Input) 4 interrupting the main PWMOUT loop, setting PWMOUT to 0 and looping there until the micro was reset."
The problem is that you have a "goto label_80" at the end after setting PWM duty to zero. That's not a "looping there until reset", that's going back and setting the PWM duty according to the READADC ( albeit with an aside of PWM duty forced to zero while pin4 is high ).
If there's a disparity in specification and 'working code' it becomes impossible for anyone to really tell what you want or wanted, to know which is right. This is why it's very important to know and define exactly what you want, then to create the code to exactly what you want.
OK fine.I agree, i guess i jumped to it working as far as i could actually get the PWM to 0 with input 4 input high. That was a first over 20 or more other attempts to make it do that. Its a milestone when it responds vs doing nothing. Sure, I would like to have it hang there till reset. True, I still need to loop until reset, and test how long it takes to get to 0 PWM so there's more for me to do. Logicator doesn't offer as much versatility for doing what I'm after, and my basic programming skills are still nil, I was hoping to use logicator to allow me to draw up in a flow chart manner (similar to labview) and looking at code via Logicator is a great idea since you have a flow and code representation together. I seem to have found its limitation forcing me into basic much sooner than I would like.
Pic of PicOK fine.
Then start again in BASIC,
you'll then get more help,
and please post the schematic and photographs.
"boring" or not,
they will help others to help you
rather than chasing a moving target.
e
I'm not sure what your thinking is here but PWM will always be high ( well, always active whenever you have it on ). As Input 4 is independent of PWM you can read it at any time you choose to and I cannot see any reason for having to hold the input with a cap.One thing that came to mind in all this is the ideal time as to when to look at input 4. I figure when the PWM output is high would be ideal. Even if its not possible I could buffer when input 4 goes high with a cap long enough to see it afterwards and shutdown the PWM.
Do
ReadAdc 4, b0
If b0 <> b1 Then
b1 = b0
PwmOut 2, 63, b1
End If
Loop
Do
ReadAdc 4, b0
w1 = b0 * 4
If w1 <> w2 Then
w2 = w1
PwmOut 2, 255, w2
End If
Loop
Do
ReadAdc10 4, w1
If w1 <> w2 Then
w2 = w1
PwmOut 2, 255, w2
End If
Loop
Thanks for the tips, I'll try today inbetween classes (I teach)@Gareth,
just for information,
could you post the circuit for your project?
e
Thanks Hippy, all 3 work wonderfully, but surprisingly the first listing is the best in terms of least flicker at the absolute dregs of illumination. To be honest, that level might as well just be removed by having a minimum chack, or by padding one end of my pot with a 100 ohm resistor so it never gets that low. hardware vs software.A cap on the ADC input might help and perhaps a bit of software filtering. With high brighteness and low PWM duty there can be flicker in lamps anyway and the re-issuing PWMOUT can sometimes add some which I think is what you are seeing.
You can optimise your code a little which may make things clearer and smoother ( or may make it worse ! ) ...
It may also be worthwhile upping the "63" frequency to 255 and trying this ...Code:Do ReadAdc 4, b0 If b0 <> b1 Then b1 = b0 PwmOut 2, 63, b1 End If Loop
Or even ...Code:Do ReadAdc 4, b0 w1 = b0 * 4 If w1 <> w2 Then w2 = w1 PwmOut 2, 255, w2 End If Loop
Code:Do ReadAdc10 4, w1 If w1 <> w2 Then w2 = w1 PwmOut 2, 255, w2 End If Loop