Sunday, August 31, 2014

PIC16F1788 Interrupts

I've been working with the Enhanced 14 bit core lately, and porting my code over from an old 14 bit core (PIC16F876).  The new PIC16F1788 has a lot more peripheral functionality, which creates some difficulties when setting up the device.  On this particular project I am using the external interrupt to trigger a pulse generator.  In the code I defined my interrupt routine, set the interrupt register to fire on INTE (External interrupt), and branch to the pulse generator routine.  This is pretty simple on the regular, old 14 bit core, but with the enhanced 14 bit core there are analog options on port B, and they are set to on by default.  So I got everything setup, installed the new processor, and loaded my code, and went to test the board, no interrupts.  I got stuck there for some time because I didn't know about the analog select register, which disconnects the INTE interrupt signal from the external pin, and turns the port into an analog input.  The ANSEL (Analog Select Registers) are set by default, and you have to clear these bits to use the port as a digital I/O pin.
The boards I build are usually hand assembled on a piece of Vectorboard, and wired point to point.  There are noise issues because there is no ground plane in the Vectorboard.  This has been a problem in the past because I was limited to running my boards at 4 MHz.  This is the reason I moved to the Enhanced 14 bit core.  The PIC16F1788 has an internal oscillator that can run up to 32 MHz, making my pulse generator a lot faster, and solving a big problem...
This particular project required a dual core board.  Each processor has a specific task, which cannot be interrupted by another process.  One is a frequency converter running a tachometer, and the other is a PWM generator used for brushless DC motor control.  Switching from the old 14 bit core to the enhanced 14 bit core allowed me to get the high speed clock to meet the timing requirements for the project.  Now I am in the process of learning to use the PSMC (Programmable Switch Mode Controller) which can do high performance PWM, and other high performance pulse schemes used to run brushless DC motors.

2 comments:

  1. Thank you a million times! After almost 3 wasted days (and replacement of the MCU), you have uncovered the incredible stupidity of Microchip who changed the default condition for PORTA pins on the 16F1788 from digital to analog input (as on all previous chips I have used). Setting ANSELA = 0x00 solved my problem. Why MC did this is beyond me but your discovery has saved me from more frustration. Their documentation is way too subtle on this. I see others having similar problems, too. Thanks again!

    Kit Ryan
    Ryan Sound Lab

    ReplyDelete
  2. My Grandfather used to say Thanks a Million... LOL!

    Yeah, had some difficulties learning the Enhanced 14 bit core architecture, but I think the added flexibility, and features make up for it. I've got a PIC16 Explorer board, and am kinda intimidated by it because of the architecture, and instruction set changes. That'll be a vertical learning curve...

    Glad my suffering helped someone out...

    -Z.Monkey

    ReplyDelete