Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Asking for input on my first real Schematic (an RC motor driver)

Status
Not open for further replies.

Triode

Well-Known Member
This is for a project I've been working on for a while, but I'm newer to electronics, so I would like input on how it could be improved, or problems that you spot.
**broken link removed**
-The receiver inputs will connect to an RC receiver output where it normally connects to the servos.
-The motor pins 1 and 2 will connect to the first DC motor and 3 and 4 will connect to the second.
-The PIC chips are programmed to capture the width of the PWM signal and output a motor control signal, depending on direction it sets one pin low and pulses the other pin. The ideal frequency is not something I've settled, as it seems to be debated wherever I ask, but the pics can be reprogrammed whatever the case may be.
-The Calibrate buttons will set the range of incomming pwm that the chip interprets as the top, bottom and middle of the range. If you look at my code that I've posted in my blog and elsewhere, you'll see that the parts to do that arent added yet.
-The 18V will come from a pair of 9V batteries

I have acess to a PCB milling machine, but it's not unlimited, so I want to make sure this is a good plan before I try to make it. And since I've never made a board I can use advice.

To try to anticipate a question, the reason I'm using a pair of 18F1320's instead of one chip that has two Capture inputs is that the electronics club at my university has a few shoe boxes full of them, and the only chips they have that have two Capture modules are the expensive USB chips (18F4550) which are actually worth more than two 1320 chips.

Thanks for any help :)
 
Last edited:
If you use a standard RC system the pulses to the servos are not overlapping and so you can capture them with one CCP input. If you're using a spread spectrum one then forget it as they output all pulses at the same time.

Edit, reread your post so ignore below.
Also, how are two motors controlled with one pulse? If it's just both, left, right then one chip can easily do two channels.

Mike.
 
Last edited:
Thanks for replying,
I didnt realize that the pulses might be offset, it took me a while to get my capture code to work, but I might be able to manage that. I'm using a pretty normal traxxas 3 channel reciver. I don't recall the model number, but I doubt that two traxxas recievers are going to vary much.

As for the motors, they move independantly of eachother. If I could capture two servo signals I don't think it would be a problem at all to controll two motors.

Heres the bit that controlls one motor on one chip
Code:
	//Timer 2 flag
	if(PIR1bits.TMR2IF == 1)
	{
		PIR1bits.TMR2IF = 0; //clears the timer 1 interupt flag

					//handle motor controll pulses
					//upper is about 2150, lower is about  1210
					//middle is near 1640 to 1660
					//vars are MOT1CyclePos MOT1HighTime
					MOT1CyclePos++; //move up in cycle
					if(MOT1CyclePos > MotorControlRez){MOT1CyclePos = 0;} //loop at end of cycle
			
					//Port output of PWM signal
					if(MOT1CyclePos > MOT1HighTime)
					{
						LATAbits.LATA6 = 0;
						LATAbits.LATA0 = 0;
					}
					else
					{
						if(PWM1Width > PWMCenterTop)
						{
							LATAbits.LATA6 = 0;
							LATAbits.LATA0 = 1;
						}
						
						if(PWM1Width < PWMCenterBottom)
						{
							LATAbits.LATA6 = 1;
							LATAbits.LATA0 = 0;
						}
						
					}
		

	}

MOT1HighTime is the amount of time that motor should remain high, So really I could just repeat this code with a 2 added to the variables for the second motor.

The part that would take some figuring on my part is the capture side:
Code:
//ccp interrupt
	if(PIR1bits.CCP1IF == 1)
	{	
		PIR1bits.CCP1IF = 0; //clear the flag
		if(PWM1Edge == 1)//if detecting rising
		{	
			
			PWM1RiseTime = CCPR1;//save the low timer value for the rise time
			CCP1CON = 0b0000100;//switch to detect falling edge
			PWM1Edge = 0;//switch to indicate falling edge is next

			//Generate motor controll timing length
			if(PWM1Width > PWMCenterTop) //scaled distance from center in positive direction
			{
				MOT1HighTime = ((PWM1Width-(PWMCenterTop-30))*MotorControlRez)/(PWMRangeTop - PWMCenterTop);
			}
		
			if(PWM1Width < PWMCenterBottom) //scaled distance from center in negative direction
			{
				MOT1HighTime = (((PWMCenterBottom+30)-PWM1Width)*MotorControlRez)/(PWMCenterBottom-PWMRangeBottom); //the 30 is for a end space to go to full power
			}

			if(PWM1Width > PWMCenterBottom && PWM1Width < PWMCenterTop)
			{
				MOT1HighTime = 0;
			}



		}
		else //set to detecting falling edge of incomming PWM signal
		{

			PWM1Width = CCPR1 - PWM1RiseTime;
			CCP1CON = 0b0000101;//switch to detect rising edge
			PWM1Edge = 1;//switch to indicate rising edge is next
		}

		
	}

As you can see it waits for a transition to high, switches to wait for a transition to low, then times the difference. I guess to capture two I would plug two servo feeds in to the one pin, and then take every other pulse to be a different one? But then even if that worked it seems like if it missed one pulse your servo controlls would switch sides, and you coulden't tell which side would be which when you first turned it on. I'm sure theres a way but its going to take some doing.
 
Last edited:
I just had an idea that might work. The pulses should be out of sync for different channels right? Would it work to connect two servo signals to the capture pin, and connect one of them to a second pin so that when its capturing a signal it could reference that second pin to tell which one it was? Since the two servo signal lines would be connected to the same pin I guess I would need to put a diode in there to keep the second pin from getting both signals. Would a 1N4148 Diode do the job? from what I know it seems like it would be fast enough and low enough impedance, but I'm not certain. I'll have to try this on a breadboard when I'm home. I could test if the diode works to allow and block the servo signals just by plugging one in on my current breadboard of the project.
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top