Bernie_of_CPE
New Member
Hi Guys,
My fifth week with Picaxe electronics and my first excursion into a project design. Please pay attention there will be newb questions at the end.
I am starting to meddle with IRIN. I have an 08M2 and have bread boarded the receiver LED circuit (as per the manual) have managed to understand that data is taken in, manipulated and PWM output is generated according to parameters set up in the program code. This is a large chunk of learning change for me.
Now things are getting exciting as I have taken my first off piste adventure and tried to set up the Infra Red remote system to operate basic functions as follows.
I want to soft start and stop a small motor to protect the delicate (aka cheap) gearbox. So I decided after researching through the forum that I needed to understand what a PWM was and how I could bottle it's ether to work for me. The trick seems to be turning rapid on then off blips in power, the longer the blip remains "on" the faster my motor will turn. I set up an 08M2 on my breadboard and coded a quick test using an LED to substitute for the motor to better see the result:
Main:
for b1=0 to 255 'start a counter to make steps from fully off (0) to fully on (255)
pwmout C.2,255,b1 'pushes the PWM signal through pin C.2 looping through the counter b1 times
next 'runs another b1 counter loop and adds 1 to the count
goto main 'what to do when all 255 loop steps are done
So far so good, I can make it get brighter and reversing the counter direction means I can make it dimmer:
for b1=255 to 0
pwmout C.2,255,b1
next
goto main
So now I want to control the speed at which this all happens so I can be sure that I can select the best option for my motor and it's swinging load
The pause command is perfect for this as I can slow each loop for fine control just before the next loop:
for b1=255 to 0
pwmout c.2,255,b1
pause 1000
next
goto main
To decrease the time taken to start and stop the motor I had a play with the values starting from 10 and ending at 150, decreasing the number of steps in this way speeds up the process overall i.e. the total length of time it takes to soft start (or stop) the motor from rest to full speed (or back again).
So now I decide I want to be a smart guy and do this through an infrared remote, I would need to operate the start and stop as separate functions, a bit more coding, first the IRIN part that gets the 08M2 to look at the IR LED receiver signal, if you don't find anything look again, if you do then check it's value and run either poweron or poweroff. I choose 16 as this is the code for the "up" arrow on the remote, guess what key "17" is?
main:
irin [1000,main],C.3,b0 'look for the IR remote signal it will be at C.3 and load it's value to b0
if b0 = 16 then poweron 'if keystroke is up then soft start the motor
if b0 = 17 then poweroff 'if keystroke is down then soft stop the motor
goto main 'Look again for an IR remote signal
Here are the sequences for starting and stopping:
poweron: 'Soft start the motor
for b1=0 to 255
pwmout C.2,255,b1
pause 20
next
goto main
'poweroff: 'Soft stop the motor
'for b1=255 to 0
'pwmout C.2,255,b1
'pause 20
'next
goto main
I ran this in simulation (first time I ever used it) to see what happens. I will be using this to play test all my programs in future it is a very powerful tool. It did take me a bit of head scratching to work out how to input the control code, solution click in the generic box and change the value to whatever key code you need. It is delightful to see the program step advance to the other routines and you can change the value on the fly to see it's effect.
In my blue sky world I want the red power button to operate the motor start and the motor stop sequences. This is how I would expect my TV remote to operate and I like this functionality.
So chaps, I am stuck at this stage having been a master of the universe for an afternoon and much enjoying my successes but I realise I have just cleared the first foothill peak and looked over the top to the next slightly taller one. I don't really have a firm idea how to do this (perhaps looking at C.2 to see if it is outputting and using a toggle command?)
So I am asking for a solution if anyone can be so kind please?
Bernie.
My fifth week with Picaxe electronics and my first excursion into a project design. Please pay attention there will be newb questions at the end.
I am starting to meddle with IRIN. I have an 08M2 and have bread boarded the receiver LED circuit (as per the manual) have managed to understand that data is taken in, manipulated and PWM output is generated according to parameters set up in the program code. This is a large chunk of learning change for me.
Now things are getting exciting as I have taken my first off piste adventure and tried to set up the Infra Red remote system to operate basic functions as follows.
I want to soft start and stop a small motor to protect the delicate (aka cheap) gearbox. So I decided after researching through the forum that I needed to understand what a PWM was and how I could bottle it's ether to work for me. The trick seems to be turning rapid on then off blips in power, the longer the blip remains "on" the faster my motor will turn. I set up an 08M2 on my breadboard and coded a quick test using an LED to substitute for the motor to better see the result:
Main:
for b1=0 to 255 'start a counter to make steps from fully off (0) to fully on (255)
pwmout C.2,255,b1 'pushes the PWM signal through pin C.2 looping through the counter b1 times
next 'runs another b1 counter loop and adds 1 to the count
goto main 'what to do when all 255 loop steps are done
So far so good, I can make it get brighter and reversing the counter direction means I can make it dimmer:
for b1=255 to 0
pwmout C.2,255,b1
next
goto main
So now I want to control the speed at which this all happens so I can be sure that I can select the best option for my motor and it's swinging load
The pause command is perfect for this as I can slow each loop for fine control just before the next loop:
for b1=255 to 0
pwmout c.2,255,b1
pause 1000
next
goto main
To decrease the time taken to start and stop the motor I had a play with the values starting from 10 and ending at 150, decreasing the number of steps in this way speeds up the process overall i.e. the total length of time it takes to soft start (or stop) the motor from rest to full speed (or back again).
So now I decide I want to be a smart guy and do this through an infrared remote, I would need to operate the start and stop as separate functions, a bit more coding, first the IRIN part that gets the 08M2 to look at the IR LED receiver signal, if you don't find anything look again, if you do then check it's value and run either poweron or poweroff. I choose 16 as this is the code for the "up" arrow on the remote, guess what key "17" is?
main:
irin [1000,main],C.3,b0 'look for the IR remote signal it will be at C.3 and load it's value to b0
if b0 = 16 then poweron 'if keystroke is up then soft start the motor
if b0 = 17 then poweroff 'if keystroke is down then soft stop the motor
goto main 'Look again for an IR remote signal
Here are the sequences for starting and stopping:
poweron: 'Soft start the motor
for b1=0 to 255
pwmout C.2,255,b1
pause 20
next
goto main
'poweroff: 'Soft stop the motor
'for b1=255 to 0
'pwmout C.2,255,b1
'pause 20
'next
goto main
I ran this in simulation (first time I ever used it) to see what happens. I will be using this to play test all my programs in future it is a very powerful tool. It did take me a bit of head scratching to work out how to input the control code, solution click in the generic box and change the value to whatever key code you need. It is delightful to see the program step advance to the other routines and you can change the value on the fly to see it's effect.
In my blue sky world I want the red power button to operate the motor start and the motor stop sequences. This is how I would expect my TV remote to operate and I like this functionality.
So chaps, I am stuck at this stage having been a master of the universe for an afternoon and much enjoying my successes but I realise I have just cleared the first foothill peak and looked over the top to the next slightly taller one. I don't really have a firm idea how to do this (perhaps looking at C.2 to see if it is outputting and using a toggle command?)
So I am asking for a solution if anyone can be so kind please?
Bernie.