PDA

View Full Version : Newbie needs example RC code



PickyBiker
- 16th March 2010, 20:10
I have some basic programming skills but I am brand new to PICS. My first project is a n RC flight controller and the stumbling block is the pulse width determination of 4 inputs synchronously using a PIC16F884 and PICBASIC. I know how to determine the pulse width of any input, but 4 at a time escapes me.

The 4 inputs are throttle, rudder, aileron, and elevator. I need to accurately determine the pulse width, 1-2 ms, of all 4 for each 20 MS cycle.

Next, I will modify them and output the modified pulse widths to the servos.

Can a PIC 16f884 do that with PICBASIC Pro?

Thanks,

Mike

Acetronics2
- 16th March 2010, 20:41
Hello Michel Gauthier 711

Yes PBP can input 4 channels, treat them and output the 4 channels ... in a 20 ms slot. I did it aboard a 16F628 some years ago ...

BUT ... are you so sure the 4 inputs are synchronous ???

Alain

PickyBiker
- 16th March 2010, 20:51
Actually, you may be right, I know that the 4 pulses each occur during the 20ms period, but not necessairily starting at the same time. So I guess that is not synchronous. I actually havent looked at the pulses coming out of the receiver yet, I am just going on the RC data I have come across so far.

Thanks,

Mike

Macgman2000
- 16th March 2010, 20:55
Mike,

Are you getting your pulses from a hobby radio receiver? One way is to use one of your outputs from the receiver, say elevator as an interrupt trigger. Determine if the 4 line pulses are all going out (1 ~ 2ms pulse width) at the same time not staggered in time (if they are staggered then this will not work).

If all receiver lines are updated at the same time, at the PIC use an external interrupt to trigger on a rising edge and capture all 4 signals in an assembly routine within a tight loop. Increment a unique counter for each I/O line if the line remains high (you will need a delay so you don't exceed 255 counts @ 2ms max). If you need higher resolution sample higher at the pic and use word size counters. Each snap shot will be no more than 2ms long. Once your 2ms is up, jump back to your main code and update all 4 outputs from the pic. Do this every 16.67ms.

I am sure others here have their tried and true way of doing it also.

Nick

ScaleRobotics
- 16th March 2010, 21:07
That is a pretty aggressive first project. To read 4 channels real time each at 50 hertz, you will need to use interrupts. Darrel Taylor's interrupts http://darreltaylor.com/DT_INTS-14/intro2.html are the easiest to use, but there is still some complications to use it to read the pulses. I have an example running on a 12f683 reading 5 channels, so it is definately doable on a 16f884. It uses the CCP1 pin, but it uses assembly for the interrupt routines.

http://www.picbasic.co.uk/forum/showthread.php?t=12657

PickyBiker
- 16th March 2010, 22:58
Thanks for the help guys. That sample code reading the 5 inputs is just what I needed. Yes, this is a challenging first PIC project, but I have the electro-mechanical and programming skills needed to accomplish this. The PIC functions and programming is the only part I am actually needing help with.

PickyBiker
- 17th March 2010, 01:30
snip:

so it is definately doable on a 16f884. It uses the CCP1 pin, but it uses assembly for the interrupt routines.

http://www.picbasic.co.uk/forum/showthread.php?t=12657[/QUOTE]

That link led me to another link, http://www.scalerobotics.com/PWMpassthrough.html
that looks like the perfect starting point for me except that it's not compiling. I found the source for DT_INTS-14.BAS but it still gets error:

ERROR: Unable to execute mpasmwin.Error[118] C:\DOCUMENTS AND SETTINGS\MIKE\MY DOCUMENTS\MPLAB\TEST.ASM 197 : Overwriting previous address contents (2007)

unfortunately that doesn't seem to point to a particular code line.

I set the device to the same one described in the text, PIC12F683

Thoughts?

ScaleRobotics
- 17th March 2010, 01:39
Since I put configs in the code, you will need to edit out the configs that are automatically added by PBP. Go to the PBP directory, find the 12F683.INC file, and do the following:

Edit out the config statements like in this post:

http://www.picbasic.co.uk/forum/showpost.php?p=14288&postcount=15

ScaleRobotics
- 17th March 2010, 02:07
This was a helpful site for me, but it is 100 percent assembly code:

http://www.mcmanis.com/chuck/robotics/projects/lab-x3/pulse_measure.html

PickyBiker
- 18th March 2010, 02:10
Okay, this is awesome. the program compiles perfectly now and I can manipulate the servos the way I want in BASIC. This is way better a start than I was hoping for.

Thank you soo much.

Best regards all,

Mike