servo driving

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
User avatar
achillis1
Posts: 347
Joined: Thu Oct 09, 2008 9:19 am
Has thanked: 91 times
Been thanked: 8 times

servo driving

Post by achillis1 »

Hello Ben,

Regarding your routine for solar tracker. I run in simulation mode the routine and it seems that the timer does not work because the macro scan for light is never being called!
On the orher hand I think that I might doing something wrong or could it be that the interrupt does not simulate? Do I have to do something in order for the interrupt to work in simulation mode?

Also Ben, what kind of servos does this routine require? I mean the degrees of rotation!

Thank you,

Best Regards,

Andreas Achilleos
Last edited by achillis1 on Fri May 27, 2011 1:42 pm, edited 1 time in total.

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times

Re: servo driving

Post by medelec35 »

Hi Achilleos,

I have tried the Solar_Tracker flowchart in question, and it does simulate, but it does take about 38 seconds to access interrupt macro (well it does on this old xp win version). I suppose it could depend on how fast your PC operating system to how fast interrupt routine is accessed?
But I could be wrong on that point.
It is timer1 and timer2 which does not simulate at all.

If I am simulating within flowcode, and using timer1 or timer2, I just add a call macro function at the bottom of main to access macro, then delete it when finished testing.

Have you tried right clicking and select toggle breakpoint on the Flag=1 calculation within Scan_For_LIght interrupt macro?

Martin
Martin

User avatar
achillis1
Posts: 347
Joined: Thu Oct 09, 2008 9:19 am
Has thanked: 91 times
Been thanked: 8 times

Re: servo driving

Post by achillis1 »

I will try in a bit but first if what you say that Timer1 does not simulate then the servo icon should not be simulating since servo uses the PWM and timer1 interrupt!!!!

User avatar
achillis1
Posts: 347
Joined: Thu Oct 09, 2008 9:19 am
Has thanked: 91 times
Been thanked: 8 times

Re: servo driving

Post by achillis1 »

Ben, I have a request, can you attach another photo of you minature solar project at the article you wrote? MX013 - Solar Panel Light Tracking System

Also you mention in it that the servo-LDR scans every two minutes but the interrupt for the macro that sets the flag to 1 in order to scan fro light is set to be called 9000 times per two minutes!!!!

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: servo driving

Post by Benj »

Hello,

Im afraid the program doesn't really simulate as a high speed interrupt is required. The Flowcode timer0 simulation is not great and seems to be firing under simulation about every 30 seconds.

The actual hardware has also been cannibalized so I cannot take another photo. I can however detail the connections if you need them.

The scan for light macro is called 9000 times per second on hardware and this sets the flag which then allows the main to continue.

For timer count 0 - 1023 (14 seconds) the servo's connected to the LDR are moved to try to sense the maximum light level.

For timer count 1024 - 8999 (106 seconds) the servo's connected to the solar panel move into the optimum position and then remain there until the count reaches 9000 and is reset back to 0.

User avatar
achillis1
Posts: 347
Joined: Thu Oct 09, 2008 9:19 am
Has thanked: 91 times
Been thanked: 8 times

Re: servo driving

Post by achillis1 »

Hello,

Can't I use the PWM macro in order to drive a servo?
Can the PWM have a period of 20 ms?

Thank you

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: servo driving

Post by Benj »

Hello,

The answer is probably yes you can but it would be very tricky to get it right.

The simulation does not use the timer 1 instead the simulation just goes off the values you pass to the component macros so you should have no problems with this.

The problem with the solar tracker program simulation is that the timer 0 interrupt runs very infrequently. This is not the case on the hardware.

As medelec suggested try adding a call to the interrupt macro somewhere in the while 1 loop and see if this help the simulation to run better.

User avatar
achillis1
Posts: 347
Joined: Thu Oct 09, 2008 9:19 am
Has thanked: 91 times
Been thanked: 8 times

Re: servo driving

Post by achillis1 »

Hello,

I see what you mean.
Actually my case here is that, dowloading the different routines ( servo examples from Matrix, my own, forum user's) I kind of getting different responses from the servo!!!!!
At 90% the servo seems that it is going to behave as the routine says but usually, either it stops, or behaving strange or rotates at different degrees!
So my guess is that a ''good'' servo driving routine might need some ''trick'' in order to work!

E.g. I dowload a routine that it will send a command via macro to the servo and then trhe servo suppose to go to point 1, have a delay there and go to point 200. When I test in hardware the servo goes to some point and then without delay comes back and maybe again will make some other movements 2 or three times and then stop. Also sometimes when it finishes the movements the servo stays enabled(when I try to rotate by hand it resists) and some times it just powers off and all that with the same routine!

Is my servo haunted!!!! :)

I had not had the chance to work with Ben's routine cause I got no LDR setup.

User avatar
achillis1
Posts: 347
Joined: Thu Oct 09, 2008 9:19 am
Has thanked: 91 times
Been thanked: 8 times

Re: servo driving

Post by achillis1 »

Hello Ben,

I am trying to set the PWM cycle to 1.75 ms = 1750 us and it does not reach up to there, it goes up to 833.3333 us.
If I am going to drive a servo via the PWM don't I have to sent pulses of 1.25, 1.5 and 1.75 ms?
The pulses have to be sent in every 2 ms. Will I controll the 2ms via the timer interrupt?

Thank you,

Andreas Achilleos

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: servo driving

Post by Benj »

Hello Andreas,

Which family of devices are you using? and are you sure your oscillator configuration and clock speed are defined correctly in Flowcode? Have you done a 1 second flasher test to confirm everything is ok? Controlling a servo using only the PWM is going to be a absolute nightmare and probably wont work.

Post Reply