PIC12f1572 Servo error

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 7.

Moderator: Benj

Post Reply
Speed64
Posts: 39
Joined: Sat Jul 16, 2016 12:08 pm
Has thanked: 4 times
Been thanked: 2 times
Contact:

PIC12f1572 Servo error

Post by Speed64 »

hi,

i'm trying to control a small servo motor with my pic. But when i try to compile the code i get the following error messages:

Code: Select all

Device:        PIC.12F.12F1572
Generated by:  Flowcode v7.2.1.4
Microchip MPLAB XC8 C Compiler (Free Mode) V1.40
Build date: Nov 30 2016
Part Support Version: 1.40

Servo1330.c: main()
   109:	{
	^ (314) ";" expected
   122:	if (FCV_0dd21_Servo_Controller1__SERVO_IDX < 1)
	^ (192) undefined identifier "FCL_SERVOCAL"
	                                                                            (981) pointer required ^
	                                                                            (981) pointer required ^
   280:	MX_SERVO_REG_CCPR2H = ( FCL_SERVOCAL >> 8 );
	^ (192) undefined identifier "MX_SERVO_REG_CCPR2H"
   281:	MX_SERVO_REG_CCPR2L = ( FCL_SERVOCAL & 0xFF );
	^ (192) undefined identifier "MX_SERVO_REG_CCPR2L"
   306:	MX_SERVO_REG_CCP1Fbits.MX_SERVO_FLAG_CCP1F = 0;
	^ (192) undefined identifier "MX_SERVO_REG_CCP1Fbits"
	               (196) struct/union required ^
Servo1330.c:
   314:	{
	^ (374) missing basic type; int assumed (warning)
	^ (314) ";" expected
   321:	if (FCV_0dd21_Servo_Controller1__SERVO_IDX < 1)
	^ (285) no identifier in declaration
	^ (374) missing basic type; int assumed (warning)
	^ (314) ";" expected
	                  ^ (194) ")" expected
	                   ^ (285) no identifier in declaration
	                   ^ (374) missing basic type; int assumed (warning)
	                   ^ (314) ";" expected
Servo1330.c: 330: too many errors (21)
(908) exit status = 1
(908) exit status = 1
Internal oszilator 32mHz. component servo activated for the project. I tried to use the example and only changed the chip. The simulation works fine, but i can't compile without errors.

What do i have to do, to use the Servo with this type of pic?

Regards
Speed64

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

Re: PIC12f1572 Servo error

Post by medelec35 »

Hi Speed64,
Servos will only work if there are at lease two CCP channels.
Unfortunately 12F1572 only has one CCP channel hence the errors.

The only way to control servo with 12F1572 is the bit-bang method using a timer interrupt.
I can post an example tomorrow if interested?
The other way is choose a microcontroller with at least two ccp channels.
If you want to stay with 8 pins and use servo component then you can use 12F1612 as that has 2 ccp channnels

Martin
Martin

Speed64
Posts: 39
Joined: Sat Jul 16, 2016 12:08 pm
Has thanked: 4 times
Been thanked: 2 times
Contact:

Re: PIC12f1572 Servo error

Post by Speed64 »

Hi Martin,

Thank you for your quick response
Please send me your example

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

Re: PIC12f1572 Servo error

Post by medelec35 »

You can try this one.
It's normally not advisable to place delays within interrupts.
However in this case for the application, works very well.

Martin
Attachments
Servo 12F1572 V1.fcfx
(12.62 KiB) Downloaded 224 times
Martin

Speed64
Posts: 39
Joined: Sat Jul 16, 2016 12:08 pm
Has thanked: 4 times
Been thanked: 2 times
Contact:

Re: PIC12f1572 Servo error

Post by Speed64 »

Thank you, I will test it.

I can also use an external interrupt for the RS232 interface?
i / o Pin change interrupt on RX Pin.

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

Re: PIC12f1572 Servo error

Post by medelec35 »

Speed64 wrote:I can also use an external interrupt for the RS232 interface?
i / o Pin change interrupt on RX Pin.
It may not work that well with this application.

If you use not timer bit bang method with RX interrupt, the issue could be stretching of the pulse during RX interrupt times.
That will cause the servo to move slightly then back again.

You are best using the servo component if want to use RX interrupt at the same time.

Martin
Martin

Speed64
Posts: 39
Joined: Sat Jul 16, 2016 12:08 pm
Has thanked: 4 times
Been thanked: 2 times
Contact:

Re: PIC12f1572 Servo error

Post by Speed64 »

Thanks again.
I will use the other pic.
With your example, I will experiment a little.
Thanks for that.

jgu1
Posts: 1333
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1135 times
Been thanked: 299 times
Contact:

Re: PIC12f1572 Servo error

Post by jgu1 »

Hi Martin!

Does this applies to all devices, including Arduino?

Do you know why we/I need to have least two ccp channels. Please.

Thank´s in advance Martin

Br Jorgen

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: PIC12f1572 Servo error

Post by Benj »

Hi Jorgen,

The Arduino Uno and other AVR based Arduinos will work with the Servo component as they have 2 capture compare peripherals available.

We use 2 capture compare peripherals in the component as they allow us to specify the channel period (the length of time a single servo channel is active) as well as the channel duty (the length of time a single servo channel is outputting high) all based on interrupts leaving your program free to do other things.

jgu1
Posts: 1333
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1135 times
Been thanked: 299 times
Contact:

Re: PIC12f1572 Servo error

Post by jgu1 »

Thank¨s Ben! :D

Br jorgen

Speed64
Posts: 39
Joined: Sat Jul 16, 2016 12:08 pm
Has thanked: 4 times
Been thanked: 2 times
Contact:

Re: PIC12f1572 Servo error

Post by Speed64 »

Hi everybody,

I tested the PIC12F1612 today.
The servo is not running.
have I overlooked something?
A4 flashes 1 sec on 1 sec off

Thanks in advance
Servo1330.fcfx
(10.81 KiB) Downloaded 313 times

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

Re: PIC12f1572 Servo error

Post by medelec35 »

I can't see anything wrong with Flowchart.

Do you have a means of displaying waveform on pin A2?

Did the servo work using bit bang method I posted?

Perhaps try that first with PIC12F1612.

If it works then report the Servo component as having a bug.

Martin.
Martin

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: PIC12f1572 Servo error

Post by Benj »

Hello,

It looks like the CCP register bits have been shuffled around on the 12F1612.

After the Servo initialise icon can you try adding these lines in a C code icon to see if this helps at all.

Code: Select all

CCP1CONbits.EN = 1;
CCP2CONbits.EN = 1;
If this works then I can modify the component to reflect these changes.

Speed64
Posts: 39
Joined: Sat Jul 16, 2016 12:08 pm
Has thanked: 4 times
Been thanked: 2 times
Contact:

Re: PIC12f1572 Servo error

Post by Speed64 »

Hi,
has inserted the code and already runs the output.
I try to make a screen shot afterwards.
Thanks to all involved.

Speed64
Posts: 39
Joined: Sat Jul 16, 2016 12:08 pm
Has thanked: 4 times
Been thanked: 2 times
Contact:

Re: PIC12f1572 Servo error

Post by Speed64 »

servo.jpg
servo.jpg (64.79 KiB) Viewed 9519 times
measured at pin 5 AN2
how to adjust the frequency?
50Hz instead of 60Hz
thanks again

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: PIC12f1572 Servo error

Post by Benj »

Hello,

50Hz is correct for driving servo motors. Does your motor specifically require 60Hz? It's more the pulse then the frequency that the controller works from.

Speed64
Posts: 39
Joined: Sat Jul 16, 2016 12:08 pm
Has thanked: 4 times
Been thanked: 2 times
Contact:

Re: PIC12f1572 Servo error

Post by Speed64 »

Hello Benj,

the picture shows a curve with 64Hz.
it just checked again.
How can I switch to 50Hz?

Question: Can I use any pin for the servo if the chip has 2 CCPs?
Question: Does the servo also work with a chip that has a CCP and an ECCP?
PIC18F4553 with 44PINs for example
Q: Do I take a pin labeled CCP?
PIC18F4553 PIN35 RC1 CCP2, 36 RC2 CCP1 or 11 RB3 CCP2
Are the 44pins not included in the simulation?

Post Reply