Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : freq gen set pin
Author | Message | ||||
sparkey Senior Member Joined: 15/06/2011 Location: AustraliaPosts: 819 |
ok if any body can help me with this :iwant to make a digital output pin switch from high to low : :also i would like to be able to control the time it is high and low ..states : i would also like to be able to do this in real time but if thats just a hell of a lot of programme the latter will be fine i can just go into the program and set the variable manually....thanks to all whom reply technicians do it with least resistance |
||||
BobDevries Senior Member Joined: 08/06/2011 Location: AustraliaPosts: 266 |
try this: 10 setpin 10,8: rem set pin 10 for digital output 20 do 30 pin(10)= 1:rem set pin 10 to logic high 30 pause 500: rem pause for 500 mSec 40 pin(10) = 0: rem set pin 10 to logic low 50 pause 500 60 loop 70 end In a real life situation you can use the TIMER to see how much time has elapsed, and then you can do other code while waiting for it to get to the value you need. Remember, the TIMER counts UP in mSec. You can set it to 0, and then check periodically to see if it has the value you need. Hope that helps, Regards, Bob Devries Dalby, QLD, Australia |
||||
BobDevries Senior Member Joined: 08/06/2011 Location: AustraliaPosts: 266 |
By the way.... NEVER use the TIMER function to get a specific value if you're executing other code while waiting for it. Chances are that you'll miss your target value. 10 SETPIN 10,8 20 TIMER = 0: PIN(10) = 1 30 DO WHILE TIMER < 500 40 GOSUB 100 50 LOOP 60 TIMER = 0: PIN(10) = 0 70 DO WHILE TIMER < 500 80 GOSUB 120 90 LOOP 60 END 100 REM subroutine to do something while you're waiting 110 RETURN 120 REM another subroutine 130 RETURN Regards, Bob Devries Dalby, QLD, Australia |
||||
Gizmo Admin Group Joined: 05/06/2004 Location: AustraliaPosts: 5078 |
Ideally you would use some sort of PWM output, where you set the on time, off time and it will run in the background until you make a change to it. At this time the Maximite doens't support a PWM output, so we need to do it with software. I havn't tried it yet but you might be able to use the SETTICK command. Its a interrupt, meaning it will interrupt your normal program at a certain time. I havn't tested this, its probably broken. The two timer routines at 1000 and 2000 should flip flop between eachother. 5 SETPIN 10,8 'Set as output 10 SETTICK 100,1000 'Start timer in 100ms 20 ' Normal program, do stuff 30 PRINT RND() 40 GOTO 30 1000 'On Time, 10ms 1010 SETTICK 10,2000 1020 PIN(10)=1 1030 IRETURN 2000 'Off Time, 100ms 2010 SETTICK 100,1000 2020 PIN(10)=0 2030 IRETURN Glenn The best time to plant a tree was twenty years ago, the second best time is right now. JAQ |
||||
BobDevries Senior Member Joined: 08/06/2011 Location: AustraliaPosts: 266 |
Hey Glenn, excellent example. I'm learning from this. I had used the SETTICK command before, I just didn't think of it in this instance. And yes, it works fine. Regards, Bob Devries Dalby, QLD, Australia |
||||
sparkey Senior Member Joined: 15/06/2011 Location: AustraliaPosts: 819 |
20 ' Normal program, do stuff 30 PRINT RND() 40 GOTO 30 are these three lines nesscary it loks to me like a ramdom n0 gen loop and thows a heap of numbers down the screen ....thanks .... technicians do it with least resistance |
||||
Print this page |