Servo on PIC18F87k22

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
etillol
Posts: 8
Joined: Tue Feb 12, 2013 3:31 pm
Location: Carpentras, France
Has thanked: 2 times
Been thanked: 3 times

Servo on PIC18F87k22

Post by etillol »

Hello,
I'm experimenting the servo macros on my custom board based on PIC18F87k22.
I'm trying to drive a hobby servo on port RF7, but nothing moves.
I tried to drive this pin manually and I can make this servo move, though I'm asking myself if there is some restrictions for using the servo macro commands (must it be a capture compare pin or something)?
You can see in my attachement 2 files:
- servo.fcf does not work and uses servo macro commands
- servo_test.fcf is just toggling an output pin at the desired chronogramm to make the servo move between 2 positions.

If you have any idea that could explain why the servo macro commands cannot be used, I'll be happy to check tem.

Thank you,
Attachments
servo_test.fcf
(4.5 KiB) Downloaded 310 times
servo.fcf
(5 KiB) Downloaded 295 times

User avatar
Dan81
Valued Contributor
Valued Contributor
Posts: 268
Joined: Sun Jan 15, 2006 4:07 pm
Location: Albi France
Been thanked: 60 times
Contact:

Re: Servo on PIC18F87k22

Post by Dan81 »

Hello Etillol

I think there is a little bug in Flowcode.
If you put only 1 channel , it doesn't work.
Put 2 channels and it should be OK.

Daniel

etillol
Posts: 8
Joined: Tue Feb 12, 2013 3:31 pm
Location: Carpentras, France
Has thanked: 2 times
Been thanked: 3 times

Re: Servo on PIC18F87k22

Post by etillol »

Hello,
Thank you for the tip but it doesn't work yet.
I took a look on the C code and it seems that the servo macros are based on interrupts on ccp1 (or ccp2) peripherals.
But I was wondering if it could use ccp peripheral to generate timings without using corresponding pins?
As I don't use this pins, it may explain why I don't have any pulse on RF7 pin.
What do you think of that?

Code: Select all

void MX_INTERRUPT_MACRO(void)
{
	
	#ifndef MX_MIAC_SYSTEM
		if (ts_bit(pir1, CCP1IF) && ts_bit(pie1, CCP1IE))
		{
			if (MX_SERVO_IDX < MX_SERVO_NO_CHAN)
			{
				FCD_Servo0_TogglePort(MX_SERVO_PORT_ARRAY[MX_SERVO_IDX], MX_SERVO_PIN_ARRAY[MX_SERVO_IDX], 1);	//Start Servo duty cycle

				MX_SERVO_CALC = MX_SERVO_TRIM[MX_SERVO_IDX] + MX_SERVO_POSITION[MX_SERVO_IDX];		//Calculate the required position
				MX_SERVO_CALC = MX_SERVO_CALC * MX_SERVO_CLK_COUNT;									//Calculate the number of clock cycles required
				MX_SERVO_CALC = (MX_SERVO_CALC >> 8) & 0xFFFF;										//Shift back to be 16-bit

				ccpr2h = ( MX_SERVO_CALC >> 8 );			//Setup capture compare registers
				ccpr2l = ( MX_SERVO_CALC & 0xFF );
			}
			cr_bit(pir1, CCP1IF);							//Clear interrupt
		}


		if (ts_bit(pir2, CCP2IF) && ts_bit(pie2, CCP2IE))
		{
			if (MX_SERVO_IDX < MX_SERVO_NO_CHAN)			//If channel is active
			{
				FCD_Servo0_TogglePort(MX_SERVO_PORT_ARRAY[MX_SERVO_IDX], MX_SERVO_PIN_ARRAY[MX_SERVO_IDX],0);	//End of control pulse
			}
			MX_SERVO_IDX = (MX_SERVO_IDX + 1) & 0x07;		//Increment channel

			if (MX_SERVO_REQUIRED[MX_SERVO_IDX] > MX_SERVO_POSITION[MX_SERVO_IDX])
				MX_SERVO_POSITION[MX_SERVO_IDX] = MX_SERVO_POSITION[MX_SERVO_IDX] + 1;	//Increment duty

			if (MX_SERVO_REQUIRED[MX_SERVO_IDX] < MX_SERVO_POSITION[MX_SERVO_IDX])
				MX_SERVO_POSITION[MX_SERVO_IDX] = MX_SERVO_POSITION[MX_SERVO_IDX] - 1;	//Decrement duty

			cr_bit(pir2, CCP2IF);							//Clear interrupt
		}
	#endif


}
I also suspect some config bits that could interfere with CCP peripherals, but it's just an intuition.

Post Reply