clasicrocker
New Member
Hi All,
I have a strange problem when I run this code in the simulator it performs just as I would think it should but when I program the chip 08m it does strange things. The code:
Button is on pin4
led is on pin2
Do I have to do something with other pins or can they just float at any state?
What I see happening when the chip is running.
With no button pushed it should just go round and round it doesn't. I see the led start from dim and get brighter about 12 steep and it goes out for about the same time and does that until button is pushed.
When the button is pushed it slowly goes to full bright as I hoped, at that point I wanted it to stay at full but when it gets to the top, it goes out and stays out.
When I let go of button It does odd blinks for a time and goes back to the way I described originally.
ok around 40 cycles of that and it went full bright and cycled to dim. Just not what I expected.
Can anyone see what I am doing wrong.
Gripe *%($@@#
basic commands section 2 page 139 is the pwmout command and it shows that the 08m can use that command. Next page140 gives some example code
pwmduty that is.
Just had to say that feel better now http://www.picaxeforum.co.uk/images/smilies/redface.gif
Thanks for the help in advance
Jim
I have a strange problem when I run this code in the simulator it performs just as I would think it should but when I program the chip 08m it does strange things. The code:
Code:
b0 = 255 'b0 is a variable full bright is 1 out is 255, I think
Main: 'where it all starts
if pin4 = 1 then goto Brighten ' they are pushing the button
if pin4 = 0 then goto Dim ' they arn't pushing the button
Goto Main 'repeat
Brighten:
if b0 = 255 then Letemwait 'I don't want it to start as soon as they touch
Brighten2: 'where to come back to
if b0 = 1 then goto main 'we are the brightest we can get so just go look at the button
b0 = b0 - 1 ' go up in brightness
b2=255-b0/62*5+10 'half hearted attempt to linearise
pwm 2,b0,b2 ' I don't understand this but it works almost
goto main 'go look at touch pads
Dim:
if b0 => 250 then goto alltheway ' we don't want to go to next step it will start over
b0 = b0 + 10 'next step down
b2=255-b0/62*5+10 'half hearted attempt to linearise
pwm 2,b0,b2 'set pwm output on pin2 duty b0 duration b2
goto main 'go back and look at button
alltheway: ' must be 250 so make it go out
b0 = 255 ' 255 sets led off well.....
goto main 'go back and look at button
Letemwait: 'don't let em think there in control
wait 2 ' don't know how long to mak em wait good for start
goto Brighten2 'this is like a return for a gosub cant use them because the stack up
led is on pin2
Do I have to do something with other pins or can they just float at any state?
What I see happening when the chip is running.
With no button pushed it should just go round and round it doesn't. I see the led start from dim and get brighter about 12 steep and it goes out for about the same time and does that until button is pushed.
When the button is pushed it slowly goes to full bright as I hoped, at that point I wanted it to stay at full but when it gets to the top, it goes out and stays out.
When I let go of button It does odd blinks for a time and goes back to the way I described originally.
ok around 40 cycles of that and it went full bright and cycled to dim. Just not what I expected.
Can anyone see what I am doing wrong.
Gripe *%($@@#
basic commands section 2 page 139 is the pwmout command and it shows that the 08m can use that command. Next page140 gives some example code
That took me some time to find that it doesn't work on the 08m.init:
pwmout 2,150,150 ‘ set pwm duty
main:
pwmduty 2,150 ‘ set pwm duty
pause 1000 ‘ pause 1 s
pwmduty 2,50 ‘ set pwm duty
pause 1000 ‘ pause 1 s
goto main ‘ loop back to start
pwmduty that is.
Just had to say that feel better now http://www.picaxeforum.co.uk/images/smilies/redface.gif
Thanks for the help in advance
Jim