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 : Oscillating project / PWM / Duino-Mega
Author | Message | ||||
Fiesta90150 Newbie Joined: 09/10/2013 Location: FrancePosts: 5 |
Hi everyone, i have been on the look out for help on a small simple project i would like to do, Its basically a rotating system for aqaurium power heads. IT allows you to flow water in different directions trhougout the day which is ace for a reef tank. Basically I would need to control a servo from my duinomite-mega, but unlike arduinos there isnt a PWM connection on the board. I am as good as a beginner can be with microcotnrollers and programming... I did one project with loads of help from a guy that new more than me and it worked well... It was basically a LED setup where i replicated a thunderstorm. I had three LEDS on the circuit, I had 10 sequences of "Led flashs". that were chosen randomly by the duinomite during a certain time of the day. (this was also for the reef tank). Anyways well i would like the same for my oscillating project... create three or more sequences (in the future) to be able to have a non repeating pattern, instead of the same pattern over and over again. I have a Duinomite-Mega and i did the 4.4 firmware update on it yesterday. I also have a 4.8V micro servo. I have changed the original program that i used before to some extent... It was used before for 3 LEDs so i just changed it to basically one LED, which would now become a servo... 10 SetPin 1,8 20 'initializes time 30 times$="00:01:01" 40 debut 50 GoTo 40 Sub debut() 'transforms variable time into a number between 0 and 86399 heure=Val(Left$(Time$,2))*3600+Val(Mid$(Time$,4,2))*60+Val(R ight$(Time$,2)) 'time slot 1 If heure > 0 And heure < 12000 Then tirage 'time slot 2 If heure > 24000 And heure < 36000 Then tirage Pause(1000) End Sub Sub tirage() 'performs a draw to start a cycle of oscillation 'value multiplied by RND corresponds to the probability of launch 'a oscillation sequence If Int(Rnd*1)=0 Then oscillation End Sub Sub oscillation() 'performs a random sequence to initiate 'generates a value between 0 and 2 'and stores this value in the variable range choix = Int(Rnd*3) If choix = 0 Then seqa If choix = 1 Then seqb If choix = 2 Then seqc End Sub Sub seqa() 'oscillation sequence a Pin(1)=1 Pause(100) Pin(1)=1 Pause(100) Pin(1)=0 Pin(1)=0 Pause(50) pin(1)=1 pin(1)=1 Pause(100) Pin(1)=0 Pin(1)=0 End Sub Sub seqb() 'oscillation sequence b Pin(1)=1 Pause(100) Pin(1)=1 Pause(100) Pin(1)=0 Pin(1)=0 Pause(50) pin(1)=1 pin(1)=1 Pause(100) Pin(1)=0 Pin(1)=0 End Sub Sub seqc() 'Oscillation sequence c Pin(1)=1 Pause(100) Pin(1)=1 Pause(100) Pin(1)=0 Pin(1)=0 Pause(50) pin(1)=1 pin(1)=1 Pause(100) Pin(1)=0 Pin(1)=0 End Sub I translated (it was in french) since i live in france now. huh, so there are two words that i did not translate :debut= beginning and choix= choice. I dont know if i can replace those words in the program without it not working anymore. I hope you get the idea... I know this wont workd for a servomoteur because you don't have the pwm wired to a pin and im not sending any information. I just rewrote the program as if i had a LED. Basically i would need help converting this program into a program for a servo motor... This means that i need to integrate the PWM signals into the program and also where to wore that signal wire from the servo... As said i don't know much about prgoramming and circuits and all and it probably shows in the program above lol. Thanks for any help any questions feel free to ask. |
||||
Fiesta90150 Newbie Joined: 09/10/2013 Location: FrancePosts: 5 |
is this impossible i see that 43 people have read the thread but no answers =( |
||||
panky Guru Joined: 02/10/2012 Location: AustraliaPosts: 1101 |
Nick, Interesting ideas - can you provide a bit more on how you wan to drive the servos and what exactly will they do? The PWM ability of mmb utilises the audio pins so you have pwm ability in the duinomite already. From a software perspective, your program looks ok but you could possibly simplify a bit, particularly in the seqa seqd etc area. Have a look back through some old threads on The Backshed using the search function and PWM for more info on driving servos. Regards Doug ... almost all of the Maximites, the MicromMites, the MM Extremes, the ArmMites, the PicoMite and loving it! |
||||
crez Senior Member Joined: 24/10/2012 Location: AustraliaPosts: 152 |
Fiesta90150, At http://mbed.org/cookbook/Servo I found: The control circuitry of the servo uses a potentiometer (variable resistor) that is used to sense the angular position of the output shaft. The potentiometer is the tall component on the right in the image. The output shaft of a servo normally travels 180-210 degrees. A single control bit is used to specify the angular position of the shaft. The timing of this bit specifies the angular position for the shaft. The potentiometer senses the angle, and if the shaft is not at the correct angle, the internal control circuit turns the motor in the correct direction until the desired angle is sensed. The control signal bit specifies the desired angle. The desired angle is encoded using pulse width modulation (PWM). The width of the active high pulse varies from 1-2 ms. A 1ms pulse is 0 degrees, 1.5ms is 90 degrees and a 2 ms pulse is approximately 180 degrees. New timing pulses are sent to the servo every 20 ms. If this is the kind of servo you have, you could set up an interrupt using the SETTICK command that happens every 20ms. When the interrupt runs, it produces a pulse between 1 and 2ms width to vary the servo angle using the PULSE command in MMBasic. If you let us know the model of your servo we could check that It is the same type. David |
||||
Fiesta90150 Newbie Joined: 09/10/2013 Location: FrancePosts: 5 |
thanks, so this is what i want it to do : http://www.youtube.com/watch?v=t9PzvgC3oPI I would use a motor which i could do and use the program i made but i have a servo so i would like to use it, and i think the arm between the motor and the "pole" (to turn the pump inside the tank) will be alot simpler to do. I at first wanted it to go back and forth all day long but thought, hey? i have a program which i can modify which will enable me to have variable and random sequences replicating more of a natural ocean current. (Some people are probably asking themselves why i take so much trouble for a fish tank lol) I do not have any idea on how i could simplify the part of the program with the sequences, though,... So I could use the program i have and just plug the signal wire from the servo into the audio outuput? how do i add this to the program, i guess i have to tell the duinomite mega that i'm using the audio output as a PWM output? In my program i used pin(1)=1 to send 3.7V to that pin and then pin (1) = 0 to send 0V. This is not translating a PWM signal like said in the following post by David... or am i not understanding correctly? i got these: http://cgi.ebay.fr/ws/eBayISAPI.dll?ViewItem&item=3308206361 14&ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1439.l2649 they are mini ones which i didnt see when ordering but they seem pretty strong. Its the first time i use/buy servos. David, the peice of program on that servo link looks similat to what you would use on a arduino am i right? So i now understand the 1 ms etc being a different angle each time, so where do i add this too my program? I mean in my program i now actually have pin(1)=1 to send 3.7V pin(2)=0 to snd 0V do i just replace the =1 buy for example =1.5? nick |
||||
TassyJim Guru Joined: 07/08/2011 Location: AustraliaPosts: 6100 |
From the help file: In the main program, decide what angle you want at the time and then set the angle with the PWM command. It will then stay at that setting until you change it. Jim VK7JH MMedit  MMBasic Help |
||||
Fiesta90150 Newbie Joined: 09/10/2013 Location: FrancePosts: 5 |
So i have to replace my subsequences program with those three functions ( PWM freq, ch1, ch2, PWM stop ) ? I looked at the file, and also checked pulse, pwm and pwm top I have only one channel so it would be like this: subseqa PULSE pin(1)= 0,01 Stop PWM output this doesnt look correct |
||||
crez Senior Member Joined: 24/10/2012 Location: AustraliaPosts: 152 |
Nick, Your Ebay link doesn't work for me so I am still not sure if your servo is the same type. IF IT IS then using the pwm command: pwm 50, x The frequency of 50 gives you 1 pulse every 20ms. The full range of x is 0 to 100, but in your case you want a pulse of 1 to 2ms every 20ms so x would vary from 100*1/20 = 5 to 100*2/20 = 10. x=5 would be 0 degrees and x=10 would be 180 degrees. If you had a variable called angle which varies from 0 to 180 then the value of x could be found from: x = 5 + angle*5/180 The pwm at the audio connector is reduced in level by some resistors. You would have to bypass these to have enough voltage to drive the servo. OR using the pulse command: you would not need to bypass resistors as the pulses would be on a standard pin at 3.3v level pulse pin,x in this case x = 1 + angle/180 David |
||||
paceman Guru Joined: 07/10/2011 Location: AustraliaPosts: 1329 |
Nick, I've tested a small MicroPower SG90 servo and as Panky says, the info is in previous threads of the forum. To save you some time I've included the heavily commented code below which demonstrates several ways of doing it and gives some info about driving servos. Greg 'SERVO - Program to test the Micro Power SG90 servo motor using
' the original mono-colour Maximite and MMBasic V4.4 ' ---------------------------------------------- 'Normal analogue servos hold position dependant on the incoming pulse width on 'the control lead. The pulse stream needs to be maintained to hold servo 'position and the normal pulse repetition rate is approx 50Hz but this is not 'critical over quite a wide range. 'The centre (neutral) posn'n for most servos is at a pulse width of approx. '1.5mS and the full pulse width range for most servos is approx 1mS to 2mS. 'The pulse width range needs calibrating for different servos so as to achieve 'their full movement range but not over-drive and thus possibly damage them. 'Pulse width Vs position is usually not fully linear, i.e. mid pulse width is 'not necessarily the centre servo position. Shorter pulses rotate the SG90 arm 'clockwise but this can be different for other servos. ' 'The SG90 has three leads: ' a) Gnd (usually brown) ' b) 5v supply (usually red - and usually the centre lead). This draws ' typically 50-80mA when moving and 5-10mA when holding or when ' there is no control pulse input. If over-driven the current can be ' above 200mA and damage may occur. Monitoring current on the servo ' lead is a good idea when testing! ' c) pulse control lead (usually yellow). ' 'Testing is conveniently done using a 10K linear pot connected across the 'Maximite's 3.3v supply and connecting the pot wiper to one of the Maximite 'analogue input pins via a 220 ohm resistor. Voltage at that pin can then be 'read by the program and scaled to provide the control pulses. The amplitude 'of the control pulses is not critical but should not exceed the 5v servo 'supply voltage. 3.3v pulses work well. ' 'The servo can be controlled with either the PULSE or PWM command. Control 'using PULSE requires the program to maintain the pulse stream. Control using PWM 'is simple and provides a continuous pulse stream in the program background till 'changed with another PWM command or stopped with a PWM STOP command. Another 'method is to connect the PWM output running at 50Hz to an input interrupt pin 'and issue PULSE commands within the interrupt routine. 'When using the PWM command the first argument is frequency and the second 'argument is a percentage of the period. At 50 Hz the period is 20mS, thus e.g. '10% of that equates to a 2mS pulse. ' 'NOTE 1: versions of MMBasic prior to V4.4 had a bug which limited the accuracy 'of the pulse width (it's 'resolution') from the PWM command to about 1%, i.e. '0.2mS at 50Hz which 'equates to around 10% of the full servo range. Thus using PWM control with 'MMBasic versions earlier than V4.4 creates very 'stepped' output. With V4.4 the ''resolution' is 0.1%, i.e. 0.02mS at 50hZ which gives fine control. ' 'NOTE 2: when using PWM control, the Maximite's PWM output circuit must have 'the voltage divider network removed to supply the full 3.3v pulse height. ' ' ----------------------------------------------------- 'Rough SG90 pulse width Vs position calib'n using the PULSE command. ' Full range on the SG90 is: 2.4 mS (~90o) to 0.6mS (~270o) clockwise. ' 'Rough SG90 PWM command Vs position calib'n when running at 50Hz (20mS period). ' Full range: 12.4% (~90o) to 3.2% (~270o) clockwise. ' ----------------------------------------------------- ' Initialise: SetTick 0,0: SetPin 11,0: SetPin 5,0: PWM STOP Print "Input type of servo control to use:" Print "1=Keybd_PULSE, 2=Keybd_PWM, 3=Pot_PULSE, 4=Pot_PWM" Input controltype On controltype GoTo Keybd_PULSE,Keybd_PWM,Pot_PULSE,Pot_PWM Keybd_PULSE: SetPin 11,8 'set pin 11 as digital out Pin(11)=0 'set pin 11 to 0 (in case it's at 1) Input "Input pulse width in mSecs: ",width 'range approx 0.6 to 2.4 mS SetTick 20,Pulseout 'set timer interrupt for pulse out every 20mS (50Hz) GOSUB Wait goto Keybd_PULSE Keybd_PWM: Input "Input pulse width in mSecs: ",width 'range approx 0.6 to 2.4 mS percent = width*5 'assuming frequency of 50Hz (i.e. 20mS period), thus %=width*100/20 PWM 50,percent 'start 50 Hz continuous pulse train GOSUB Wait goto Keybd_PWM Pot_PULSE: SetPin 11,8 'set pin 11 as digital out Pin(11)=0 'set pin 11 to 0 (in case it's at 1) SetPin 5,1 'set pin 5 as analog in SetTick 20,Pulseout 'interrupt for pulse out every 20mS (50Hz) Do volts = Pin(5) 'read wiper voltage at the pot position width = (0.5454*volts)+0.6 'from: slope=(2.4-0.6)/3.3 and y=Sx+c key$ = Inkey$ If key$ <> "" GOTO Initialise loop Pot_PWM: SetPin 5,1 'set pin 5 for analog input do volts = Pin(5) 'read wiper voltage at the pot position width = (0.5454*volts)+0.6 'from: slope=(2.4-0.6)/3.3 and y=Sx+c percent = width*5 'assuming frequency of 50Hz (i.e. 20mS period), thus %=width*100/20 PWM 50,percent 'start 50 Hz continuous pulse train Pause 20 'delay needed for PWM at 50Hz otherwise no pulse output key$ = Inkey$ If key$ <> "" GOTO Initialise loop Pulseout: Pulse 11,width IReturn Wait: key$ = Inkey$ If key$ = "" GOTO Wait 'wait for a keyboard press to input another pulse width return |
||||
bigmik Guru Joined: 20/06/2011 Location: AustraliaPosts: 2914 |
Your Ebay link doesn't work for me so I am still not sure if your servo is the same type. David Hi David, The link suffered from `THE BACK SHED' lets add random spaces in long `words' feature. You should use the `link button' when adding an URL to a post (looks like a small bit of a chain) Then you get this New link to ebay item Regards, Mick Mick's uMite Stuff can be found >>> HERE (Kindly hosted by Dontronics) <<< |
||||
Fiesta90150 Newbie Joined: 09/10/2013 Location: FrancePosts: 5 |
yep those are my servos =) |
||||
paceman Guru Joined: 07/10/2011 Location: AustraliaPosts: 1329 |
They look very similar to the MicroPower SG90's I have. Guess there's a bit of "sticker" engineering going on here. Greg |
||||
Print this page |