Controlling An R/C Car With A Pic16F84

[youtube=http://www.youtube.com/watch?v=0hoFxx1EaN8]

[GuySoft] sent in this project. He doesn’t normally mess with electronics, but decided to give it a try. He chose a fairly complicated project to be his first, but seems extremely comfortable with it. This project was to control his R/C car with a pic16f84. That chip was chosen simply because it was the only one available at local stores. Though we’ve seen much more complicated projects in the past, he does a great job of showing exactly what has been done. He shares his thoughts and source code with us as well. He has express a little frustration about the closed source compiler he was using, so if anyone has any suggestions for him, he would probably appreciate it.  The funny part is that he mentions that people would just tell him to “get an AVR”. We think the readers here will probably be happy with how he pulled it off.

27 thoughts on “Controlling An R/C Car With A Pic16F84

  1. That “get an AVR” attitude that’s appearing now is really weird – it’s like school, with all the ‘cool kids’ ganging up to put peer pressure on everyone else to conform. Get over it! Who cares if someone is using a technology other than the one you like? If it works for them, it’s fine.

  2. I only took a brief look – but I saw that his one complaint with the open source compiler was that a delay_ms() function did not work for his chip.

    I recall using some sort of plugin for piklab that was a sort of “Delay Calculator” which would generate the assembly for a desired delay. Dropping that inline with the C code could be one solution (although, busy loops are certainly not very elegant).

    When I plan on needing some rough ms delays, I tend to set up a timer interrupt to occur once every ms, and increment a counter variable (or a couple if I’m on an 8-bit system — I never tend to have anything on long enough to overflow 32-bits).

  3. I agree that the get an AVR campaign is strange. The only reason I use PICs are that I started on them so I have experience with them. Really, I think it’s good to foster a community that has diverse talents. At least the microchip C compiler is free for academic use (they don’t verify). I really want to start trying to use the NXP arm processors… embedded linux, woo!

  4. Hey all, well, I am getting a bumble-b as said in the post. So I will update when that works.

    Andrew, I am actually looking now for an IDE for Linux, that will be good as Piklab, for AVRs.
    Eclipse is too heavy, and vim is too basic. I found something called konroller, but can’t test it yet. Also, why use an LPT, when I can use USB?

  5. I will disagree that programmers for AVR any cheaper, actually from what I see they not those official from Atmel that can in circuit debug and support wide range of chips are much more expensive. For example there is nothing so universal and cheap as PICkit 2 for price of arduino (and even half of it if you student). So I dont really understand from where such argument started? Same goes for chips price, yes old ones as 16f84 are overpriced but Atmel discontinue their old chips at all instead rising their price. So arguments king of way outdated?

  6. I have a PIC dev kit (from http://www.mikroe.com) and I’m really happy with it, although the compiler and libraries source is closed, it’s Windows only and doesn’t run on Linux using WINE, which means I’m adding the cost of another Windows PC devoted only to MCU programming to the toolkit price.
    For this and other reasons I’m considering to move someday in the future to the more open AVR platform when my dev kit and its supported processors will become obsolete, provided that the platform I’ll choose can be programmed and debugged without using Java. Don’t ask why, I just don’t want to mess with it.

    AVRs are probably expected to replace PICs in the future, still, in some projects PICs seem to be a better choice than AVRs. Correct me if I’m wrong, but due to their internal difference you can build a 50 MHz frequency counter using a PIC and no external prescaler (http://www.sprut.de/electronic/pic/projekte/frequenz/freq.htm and a ton of other projects like that one) but apparently you can’t do the same with an AVR. Please don’t make a flame war out of this post, I’m genuinely interested in knowing if this can or cannot be done with AVRs, and why.

  7. I don’t know why people always use the PIC16F84.. as therian says it is way overpriced and can’t do anything.
    I own a PICkit 2 and it is worth it’s $40 price tag. You can in circuit debug your code on most modern PIC’s and that’s a really useful feature. Programming speed is also very high, comparable to a bootloader. (on the 16-bit PIC’s there is in fact a programming executive installed, with which you get about 12kB/s programming speed)
    And if you need a cheaper programmer there are of course many different parallel/serial port programmers on the net.
    I personally hate the 10F, 12F and 16F series because of their instruction set, the fact that many of them have a banked SFR map and they have just one indirect addressing register is really limiting the power of these MCU’s when it comes to more complex applications. (and there is no reasonable free C-compiler available for them)
    I mainly use the dsPIC33F series from microchip because they have a lot of power (40MIPS, DMA, DSP) for less than $10!
    For simpler applications i recommend the 18F series because microchip offers a free C-compiler.
    As for the compiler I just use the microchip C-compilers which are free for academic use and generally produce very optimized code. (the C-compilers for the 16-bit PIC’s are derived from gcc; although full optimatisation is only available in PRO-version, but for most applications the limited optimatisation (-O1) is sufficient and when I need more optimized code I just write it in assembler..)

    I think the biggest problem of PIC’s is that microchip only supports Windows. As far as I know there is no comparable IDE to MPLAB (with integrated ICD and Emulator) for UNIX.
    The command line compilers should work through wine though.

  8. I’d recommend the Microchip Pickit 2/3 or a clone, you can program, debug, use as USB UART, logic analizer, and can drive small circuits.

    In the software part, you have different compilers to choose, for ASM you have the GNU tools, and for C you can use SDCC or PIC-GCC. There is also an arduino like enviroment called pinguino.

    But I would recommend to take a look at JalV2+Jallib and use CodeBlocks as IDE, it’s AWESOME! (And very active community).

  9. @FJ_Sanchez
    Please see my SDCC problem on the blog post! Note I also gave code in the comments.
    Also, will CodeBlocks work with AVRs? Since piklab I use for PICs. I am looking for an AVR IDE.

    @laube
    As I said, that chip was the cheapest option here ($2), I guess because there is an old stack of it. I hope to update once I get the bumble-b. That’s the cheapest usb AVR+programmer I found.

  10. @laube:

    “I don’t know why people always use the PIC16F84.. as therian says it is way overpriced and can’t do anything.”

    The reason I fell into 16F84s first was that there are a couple of very cheap parallel-port programmers for them: The no-ppp (no-parts pic programmer) and one similar that came free (cct bd only) with the book “Programming and Customizing PICmicro Microcontrollers”.

    This was before PicAxe and before Arduino – it was the easiest way I could find to get to programming ANY microcontroller without spending $200 plus on a programmer.

    Unfortunate that the programmer could only program a tiny subset of the PIC microcontrollers, but it was better than nuthin’.

    Also the series of Square 1 books like Easy PIC’n is written around them.

    So there is a whole bunch of people who may not yet have moved on and up to the Arduino. :-D

  11. Most people use the PIC16F84 because up to about three or four years ago it was the most widely known low end PIC in the world, which translates into being cheap, easy available and covered on nearly all electronics magazines/sites. It is certainly obsolete now and overpriced to dicourage its use and probably also cash on those who buy it because they absolutely need it. A cheap substitute is the PIC16F628, which will need only minor code adjustment.

  12. @J
    I didn’t know that it even supports ICD but I must admit that I haven’t tried it a lot because MPLAB gives me everything I need – and I have no problem using windows for developing.
    @FJ_Sanchez
    that’s why i like hack a day.. thank you for the info. I’ll have a look at those tools.
    @xyz
    I started with microcontrollers 4 years ago and with exactly the PIC16F628!
    At that time it was the cheapest option I could find in getting started with microcontrolers in Switzerland.. well probably there were cheaper options but I was young and new to everything related with computers; I actually started programming in assembler for PIC MCU’s xD

  13. Your delay routine might not work,because
    you didnt put 2 4pico capacitors on the crystal, its stated in mictochips datasheet. Without the pic is very unstable. try it out

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.