Shop OBEX P1 Docs P2 Docs Learn Events
PIC16F84 emulation — Parallax Forums

PIC16F84 emulation

Chris MerckChris Merck Posts: 55
edited 2008-05-13 20:13 in Propeller 1
heater's post on his 8085 emulator (this one: http://forums.parallax.com/showthread.php?p=711157) made me smile, and then seriously consider writing a PIC emulator.

I am thinking a starting point would be emulating the PIC16F84. Since it uses a 34-instruction RISC this should be relatively simple. And, since the PIC is typically run at 4Mhz (and up to 20Mhz max) there is a chance that emulator performance will approach that of the real device. Furthermore, due to the plethora of existing PIC projects and tools, this emulator may be valuable in quickly moving projects over to the propeller. And if the emulation could run fast enough, perhaps there could be a "real-time" mode where timing-critical PIC code targeted for 4Mhz operation could run properly in the emulator! Lastly, there is the potential for high-level emulation, if certain methods of hardware interfacing are taken as standards. For example, the emulator could be extended with video peripherals in the following way: code the emulator-on-prop to function in the same way as Jesus Arias's emulator-on-pc does (www.ele.uva.es/~jesus/pic/).

Anyway, this summer I will probably be tied up with my maglev research (which may use a prop), but this is another idea. I am especially looking for comments on the 1) technical feasibility and 2) expected usefulness of such an emulator.

Thanks,
Chris

Comments

  • HarleyHarley Posts: 997
    edited 2008-05-03 22:27
    Thanks Chris for including Arias's web page. That project was nicely done.

    The PIC16F84 was the first PIC I got involved with. Using a BS2 OEM pcb and Al Williams' application and loader/programmer; not the easiest device to begin with. Was tough without a debugger/simulator/emulator to debug programs. Later graduated to -87x PICs; enjoyed that much more.

    Hope you have the time to do more than just consider a PIC emulator. I'm sure others will be interested in such an emulator. yeah.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Harley Shanko
  • heaterheater Posts: 3,370
    edited 2008-05-04 04:10
    Glad to hear someone got a smile out of the 8085 emulator, perhaps there is even some useful code/ideas in there that can be used for other emulations.

    I have been considering attempting another emulation project and PIC was a first thought but I think I'm more tempted by Atmel's AVRs. You see one main motivation behind the 8085 project was to be able to use a free C compiler (BDS) for the 8085. With AVRs we also have a free C development kit for Windows and Linux courtesy of GCC.

    Not sure I'd want to get into trying to emulate all the peripherals that these devices have though.

    Anyway looks like my available time will be limited for such things in the future.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    For me, the past is not over yet.
  • Chris MerckChris Merck Posts: 55
    edited 2008-05-04 05:08
    heater said...
    With AVRs we also have a free C development kit for Windows and Linux courtesy of GCC.

    That is very true. Unfortunately I have never worked with AVRs (maybe because Microchip gives out freebies smilewinkgrin.gif). I have heard good things though, like less quirky assembler and as you mention GCC port.
  • heaterheater Posts: 3,370
    edited 2008-05-04 18:13
    Most of my Atmegas were freebies from ATMEL [noparse]:)[/noparse]
    But if we are going to emulate them, who cares if they can't get the real ones?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    For me, the past is not over yet.
  • heaterheater Posts: 3,370
    edited 2008-05-04 18:58
    I just took a look at the AVR instruction set manual. At first sight this looks very emulator unfriendly. Most instructions are 16 bit words so a simple dispatch table is out of the question. The opcodes, register numbers, immediate values etc are spread throughout the 16 bits many times with the bits of one thing (say an immediate value) appearing in disjoint parts of the word !! Looks like we would spend a lot of time shifting/masking/oring these bits to extract the real values out of the opcodes.

    There are quite a few addresing modes to take care of.

    Things like skip (an instruction) can skip 2 or more bytes depending on the following instruction so you can't just bump the PC but have to decode the following instruction redundantly to see what size skip to make.

    I don't think I'm up for that.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    For me, the past is not over yet.
  • hippyhippy Posts: 1,981
    edited 2008-05-13 16:19
    In emulating any processor the first question has to be, Why? For fun is good enough for me, but for real usefulness access to that processor's toolchain and compilers is perhaps the most logical reason.

    Choosing a processor is the next tough choice, and it definitely helps if one has experience with whatever's chosen.

    First question is how complicated is it, which really means how easy is it to decode the opcodes and the fewer opcodes the better, and then how well does the instruction set sit with the Propeller hardware - a 32-bit processor limits the number of object code instructions which can be held in RAM, 8-bit may allow more but comes with more complex decoding.

    For the PICmicro, 12-bit and 14-bit instruction sets don't fit nicely with 8/16/32-bit, and the special operations with specific SFR registers (FSR, INDF) and register banking complicates things. I wouldn't say don't but it wouldn't be my choice in expecting a clean and lean emulation.

    Another issue is Status Register bits. They can really mess up an otherwise elegant emulator.

    I'd not paid much attention to the Texas Instruments MSP430 until recently, but that looks like it could be a nice architecture to emulate but it still has a few complications in addressing modes ( especially load constants ) ...

    mspgcc.sourceforge.net/manual/x223.html
  • AleAle Posts: 2,363
    edited 2008-05-13 20:13
    I think that more than emulating a processor, a JIT or a tool to convert compiled code, analyzing it, to prop code or something else could be a bit more useful. But if you want a nice processor with some useful software, maybe the 6809 would be a nice candidate, I think OS/9 can be got somewhere smile.gif
Sign In or Register to comment.