Page 1 of 1

PIC12f1572 Servo error

Posted: Mon Oct 16, 2017 7:39 pm
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

Re: PIC12f1572 Servo error

Posted: Mon Oct 16, 2017 10:42 pm
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

Re: PIC12f1572 Servo error

Posted: Tue Oct 17, 2017 8:27 am
by Speed64
Hi Martin,

Thank you for your quick response
Please send me your example

Re: PIC12f1572 Servo error

Posted: Tue Oct 17, 2017 10:19 am
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

Re: PIC12f1572 Servo error

Posted: Tue Oct 17, 2017 10:56 am
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.

Re: PIC12f1572 Servo error

Posted: Tue Oct 17, 2017 8:47 pm
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

Re: PIC12f1572 Servo error

Posted: Wed Oct 18, 2017 5:55 am
by Speed64
Thanks again.
I will use the other pic.
With your example, I will experiment a little.
Thanks for that.

Re: PIC12f1572 Servo error

Posted: Thu Oct 19, 2017 12:20 pm
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

Re: PIC12f1572 Servo error

Posted: Mon Oct 23, 2017 10:32 am
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.

Re: PIC12f1572 Servo error

Posted: Mon Oct 23, 2017 6:54 pm
by jgu1
Thank¨s Ben! :D

Br jorgen

Re: PIC12f1572 Servo error

Posted: Wed Oct 25, 2017 9:08 pm
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 325 times

Re: PIC12f1572 Servo error

Posted: Thu Oct 26, 2017 9:33 am
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.

Re: PIC12f1572 Servo error

Posted: Thu Oct 26, 2017 10:34 am
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.

Re: PIC12f1572 Servo error

Posted: Thu Oct 26, 2017 5:02 pm
by Speed64
Hi,
has inserted the code and already runs the output.
I try to make a screen shot afterwards.
Thanks to all involved.

Re: PIC12f1572 Servo error

Posted: Fri Oct 27, 2017 3:43 pm
by Speed64
servo.jpg
servo.jpg (64.79 KiB) Viewed 9728 times
measured at pin 5 AN2
how to adjust the frequency?
50Hz instead of 60Hz
thanks again

Re: PIC12f1572 Servo error

Posted: Mon Oct 30, 2017 9:40 am
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.

Re: PIC12f1572 Servo error

Posted: Mon Oct 30, 2017 4:11 pm
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?