Page 1 of 1

12F675 + servo + analog command

Posted: Fri Dec 16, 2011 3:33 pm
by helesmes
Hello;

I use flowcode V4 and I have "problem" with a servo, a 12F675 and an analog command.

I send my flowcode about the 12F675 to drive a servo with an analog command.

I use an analog signal 0/ 5 volts, but in the flowcode, I create an offset of 4 volts

this new analog signal is used to drive a servo via the Pic12F675.

I want :

0 ° rotation for 4 volts
10 % rotation for 4.1 volts
20 % rotation for 4.2 volts
...
...
90 % rotation for 4.9 volts
100 % rotation for 5 volts


I do not understand 2 points
- why my servo works from 4.4 volts and not from 4 volts ( 255 equal 5 volts ==> 200 equal 4 volts ?????)
- I have no plage to drive the servo.

Can you explain me, can you help me?

Thanks.

helesmes in France.

Re: 12F675 + servo + analog command

Posted: Fri Dec 16, 2011 3:47 pm
by Benj
Hello,

I have made some amendments to your file and it should now work as expected.

Re: 12F675 + servo + analog command

Posted: Fri Dec 16, 2011 4:22 pm
by helesmes
benj; Thank you for this answer.

As you tell me, the servo works correctly, but this is the servo in Flowcode.

I meet an other problem, Flowcode does not allow me "to translate" the file in hexa, so I can not try with a real servo on the HP Board.

Thank you. helesmes;

Re: 12F675 + servo + analog command

Posted: Fri Dec 16, 2011 4:29 pm
by helesmes
benj; Thank you for this answer.

As you tell me, the servo works correctly, but this is the servo in Flowcode.

I meet an other problem, Flowcode does not allow me "to translate" the file in hexa, so I can not try with a real servo on the HP Board.

Thank you. helesmes;

Re: 12F675 + servo + analog command

Posted: Fri Dec 16, 2011 5:33 pm
by medelec35
I thought you need two CCP channels for PWM. So It wont work with 12F675?
I created an article on driving a servo using timer0 instead of a servo component:
http://www.matrixmultimedia.com/article.php?a=435

Ideally if you have a chip that is capable, then it's much easier using the inbuilt servo component.


I can help you to get it working with 12F675 if you like?

Martin

Re: 12F675 + servo + analog command

Posted: Fri Dec 16, 2011 5:52 pm
by helesmes
medelec35 wrote:I thought you need two CCP channels for PWM. So It wont work with 12F675?
I created an article on driving a servo using timer0 instead of a servo component:
http://www.matrixmultimedia.com/article.php?a=435

Ideally if you have a chip that is capable, then it's much easier using the inbuilt servo component.


I can help you to get it working with 12F675 if you like?

Martin
*********************************
**********
*********************************
Martin, thank you for your answer.

I am going to try to adapt your flowcode for my problem with the 16F88.

But if you can find a chip which works with the pic 12F675, I thank you

Regards.

helesmes

Re: 12F675 + servo + analog command

Posted: Fri Dec 16, 2011 7:36 pm
by medelec35
Hi helesmes,
Here's a flowchart that uses a 12F675 and 19.6609MHz crystal, since that what you have set your flowchart to.
0 and 4V will give a pulse duration of 1ms every 20ms.
>4 to 5V will give a pulse duration between 1.1mm and 2ms
This will not have the same resolution as either built in servo, or a target device that runs at 48MHz.

But I am working on one with a higher resolution for 12F675, and if it works I will post it when ready.

Martin

Re: 12F675 + servo + analog command

Posted: Sun Dec 18, 2011 9:43 am
by helesmes
medelec35 wrote:Hi helesmes,
Here's a flowchart that uses a 12F675 and 19.6609MHz crystal, since that what you have set your flowchart to.
0 and 4V will give a pulse duration of 1ms every 20ms.
>4 to 5V will give a pulse duration between 1.1mm and 2ms
This will not have the same resolution as either built in servo, or a target device that runs at 48MHz.

But I am working on one with a higher resolution for 12F675, and if it works I will post it when ready.

Martin

Martin, thank you very much, I am going to try this flowchart.

Helesmes

Re: 12F675 + servo + analog command

Posted: Sun Dec 18, 2011 11:09 am
by helesmes
hello Martin,
may I send you 2 flowchart?

in the first, ( base675 correcteplageservomoteur1)

the servo runs correctly,
when I fix "plage" with a value, the servo goes to his position, here

with "plage" = 40==> the position of the servo is "min

with "plage" = 140 ==> the position of the servo is max,

and I am "happy", I "solve" my problem.

**************
**************

But in the second ( envoi_disturb)

when I try to use an analog value, the servo does not run.

With the analog command, I choose the working:

analog value = 0 to 4 volts ==> servo is in position min

from 4 to 5 volts, the angle is divided in 20

so I try with one octet

5 volts ==> 255

from 0 to <4 volts, I put 40 in "plage"

4 volts ==> 204 ==> I put the value 40 in "plage" for the rotation

4.05 volts ==> 257 ==> I put the value 45 in "plage"

4.1 volts ==> 209 ==> value 30 in "plage"

etc to 5 volts ==> "plage" = 140.

Can you explain the place I make my "bug", I look for, but I do not find, I do not understand.

Thanks and regards.

helesmes.

Re: 12F675 + servo + analog command

Posted: Sun Dec 18, 2011 11:11 am
by helesmes
hello Martin,

I send you the first flowchart which runs.


may I send you 2 flowchart?

in the first, ( base675 correcteplageservomoteur1)

the servo runs correctly,
when I fix "plage" with a value, the servo goes to his position, here

with "plage" = 40==> the position of the servo is "min

with "plage" = 140 ==> the position of the servo is max,

and I am "happy", I "solve" my problem.

**************
**************

But in the second ( envoi_disturb)

when I try to use an analog value, the servo does not run.

With the analog command, I choose the working:

analog value = 0 to 4 volts ==> servo is in position min

from 4 to 5 volts, the angle is divided in 20

so I try with one octet

5 volts ==> 255

from 0 to <4 volts, I put 40 in "plage"

4 volts ==> 204 ==> I put the value 40 in "plage" for the rotation

4.05 volts ==> 257 ==> I put the value 45 in "plage"

4.1 volts ==> 209 ==> value 30 in "plage"

etc to 5 volts ==> "plage" = 140.

Can you explain the place I make my "bug", I look for, but I do not find, I do not understand.

Thanks and regards.

helesmes.

Re: 12F675 + servo + analog command

Posted: Tue Dec 20, 2011 1:31 pm
by medelec35
Hi helesmes,
I have corrected both of your flowcharts for you. The problem was you had the timer0 interrupt set at 1:64 which means the interrupt is accessed evey 3.3ms (300Hz). So evey 3.3ms port A0 goes high for just over 1 ms. A servo requires between 1 & 2 ms pulse every 20ms. So to get round this I have altered timer0 to 150Hz. In the timer0 interrupt macro there is a divide by 3:

Code: Select all

if count>=3
So now port A0 is high every 20ms.
By the way I do like the different way you are controlling the servo.
Its something for me to remember.

Flowchart with ADC you may need to alter formula slightly since minimum pulse is 0.7 ms approx

Martin