PICing_n_grinning

MicroChip Inc has PIC   Programmable Interface Controllers Chips


packaging options (slightly) different:
PDIP = Plastic Dual-In-line Package
MDIP = Molded Dual-In-Line Package
Since both are DIP (Dual-In-line Package) you can use them on a breadboard. 
The silicon circuit inside is usually the same/similiar (and therefore switching times and voltage ranges)

Compilers

C18 is being phased out and replaced by the newer XC8 compiler

XC8 is the 8bit compiler for 8bit chips


http://www.engscope.com/pic24-tutorial/9-1-uart-setup/

SFR (Special Function Registers)
Ok, for all the inquiring minds longing for a MicroChip SFR (special function register) cheatsheet, I have finally created one: 
Status Register (IRP, RP1, RP0, TO, PD, Z, DC, C) 
Bank Selection (including Indirect Bank Selection IRP)
Timeout
Power Down
Math Results
OPTION_REG (RBPU,INTEDG, T0CS,T0SE, PSA,PS2,PS1,PS0)
Port B Pullups
INTerrupt upon rising or falling edge
Timer0 clock source
Prescaler assignment (Watch dog or Timer0)
Prescaler rate
INTCONfig (GIE,PEIE, T0IE,T0IF, INTF,INTE, RBIE, RBIF)
Global Enable
Peripheral Enable
Timer0
B0
B1...
PIE1/PIR1 (ADI_, RCI_, TXI_, SSPI_, CCP1I_, TMR1I_, TMR2I_)
CCP1 PWM
A/D converter operation complete
EUSART send/rcv
SSP comms (I2C,SPI)
Timer1 & 2
PIE2/PIR2 (CCP2I_, OSFI_, C1I_, C2I_, EEI_, BCLI_, ULPWUI_)
CCP2
Oscillator failure
Comparator 1 & 2
EEPROM write
Bus Collision
PCON (ULPWUE, SBOREN, POR, BOR)
Indicates how was chip was reset
wakeup
brownout
power on
reset pin
watchdog
PCL
Memory tracker (>8bits UNlike the others depending on capacity)

MicroChip family summary:


8 bit



  • pic10
  • pic12
  • pic16
  • pic18

16 bit


  • pic24e
  • pic24f
  • pic24h
  • dsPIC30
  • dsPIC33E
  • dsPIC33F

32 bit


  • pic32mx
  • pic32mz



PicKit3 in-circuit debugger device

MPLABx IDE GUI


http://www.microchip.com/pagehandler/en-us/family/mplabx


allows C, so better than picaxe/BASIC





and



and away you go

Chips I have used/coded/eeprom'ed

16F628A
18F4550

compilers


http://www.microchip.com/pagehandler/en_us/devtools/mplabxc/

all C Compilers allow embeding assembler 
  directly into the C code!!!

xc8, 16, 32

http://edablog.com/2012/03/27/mplab-xc-c-compiler/

The 8, 16 and 32-bit Free editions of Microchip’s MPLAB XC compilers 
 offer many optimizations, are fully functional and 
  have no license restrictions for commercial use. 

For designers who want to test their code with the Pro optimization levels, 
  which are approximately 50% better than the Free editions, 
   Microchip also offers evaluation editions with Pro optimization levels 
    that last for 60 days, after which they convert to the Free compilers. 

Like the Free editions, the evaluation editions are fully functional 
 and have no license restrictions for commercial usage.

Microchip is also offering the ability to purchase 
  both single-user licenses 
   and the full suite of MPLAB XC compilers 
for all ~900 8, 16 and 32-bit PIC MCUs 
and dsPIC DSCs. 

interrupts 

interrupts - like java OnChange listener (rising or falling edge)

Onchg pin2 means on rise or fall

Intcon.x register

Oscon register

Ioc register

Global and local vars

interrupts - like java OnChange listener (rising or falling edge)

IOS (interrupt on change) is a handy microcontrollers feature. 
  when there is a state change in any of the port pin associated with this feature. 

PIC's use PORT B = Interrupt on Change 

The controller jumps into the interrupt vector when there is a change 
 in the state of any of the pins in the port.

as opposed to conventional polling techniques


interrupt let the controller know that something important happened 
  (without constantly looping/looking at it)

This saves time spent checking for that event. 

Maybe the mono ide will support pic dev in the future

http://www.monodevelop.com/



DSP/DSC/Microcontrollers


A digital signal controller (DSC) is a hybrid of 
microcontrollers and 
digital signal processors (DSPs). 

Like microcontrollers, fast interrupt responses, 
offer control-oriented peripherals like PWMs and watchdog timers, 
and are usually programmed using the C programming language, 
although they can be programmed using the device's native assembly language. 

Like DSP they incorporate 
single-cycle multiply–accumulate (MAC) units, 
barrel shifters, and 
large accumulators. 

Not all vendors have adopted the term DSC. 
The term was first introduced by Microchip Technology in 2002 

DSCs are used in a wide range of applications, but mostly 
motor control, 
power conversion, and 
sensor processing applications. 

Currently DSCs are being marketed as green technologies 
 for their potential to reduce power consumption 
   in electric motors and power supplies.

top 3 DSC vendors are 
Texas Instruments, 
Freescale, and 
Microchip Technology, 


32BIT


In general, going from 8 to 16 to 32 bit microcontrollers means more resources, particularly memory, 
 and the width of registers used for doing arithmetic and logical operations. 



The 8, 16, and 32-bit monikers generally refers to both the size of the internal and external data buses 

 and also the size of the internal register(s) used for arithmetic and logical operations 

  (used to be just one or two called accumulators, now there are usually register banks of 16 or 32).



I/O port port sizes will also generally follow the data bus size, 

  so an 8-bit micro will have 8-bit ports, a 16-bit will have 16-bit ports etc.



Despite having an 8-bit data bus, 
 many 8-bit microcontrollers have a 16-bit address bus 
   and can address 2^16 or 64K bytes of memory 
    (that doesn't mean they have anywhere near that implemented). 

  But some 8-bit micros, like the low-end PICs
   may have only a very limited RAM space (e.g. 96 bytes on a PIC16).


To get around their limited addressing scheme, some 8-bit micros use paging, 
  where the contents of a page register determines one of several banks of memory to use. 
   There will usually be some common RAM available no matter what the page register is set to.

16-bit microcontroller are generally restricted to 64K of memory, 
  but may also use paging techniques to get around this. 

32-bit microcontrollers of course have now such restrictions and can address up to 4GB of memory.

Along with the different memory sizes is the stack size. 
  In the lower end micros, this may be implemented in a special area of memory 
   and be very small (many PIC16's have an 8-level deep call stack). 

In the 16-bit and 32-bit micros, the stack will usually be in general RAM and be limited only by the size of the RAM.

There are also vast differences in the amount of memory -- both program and RAM -- implemented on the various devices. 
  8-bit micros have 100's  of bytes of RAM, and  1,000+ bytes of program memory. 
 16-bit micros have 1000's of bytes of RAM, and 10,000+ bytes of program memory. 
 32-bit micros have >64K      bytes of RAM, and     1/2 MB    of program memory.

If you are programming in assembly language, the register-size limitations will be very evident, 
  for example adding two 32-bit numbers is a chore on an 8-bit microcontroller but trivial on a 32-bit one. 

If you are programming in C, this will be largely transparent, 
  but of course the underlying compiled code will be much larger for the 8-bitter.

I said largely transparent, because the size of various C data types may be different from one size micro to another; 
 for example, a compiler which targets a 8 or 16-bit micro may use "int" to mean a 16-bit signed variable, 
  and on a 32-bit micro this would be a 32-bit variable. So a lot of programs use #defines to explicitly say what the desired size is, 
   such as "UINT16" for an unsigned 16-bit variable.

If you are programming in C, the biggest impact will be the size of you variables. 
 For example, if you know a variable will always be less than 256 (or in the range -128 to 127 if signed), 
 then you should use an 8-bit (unsigned char or char) on an 8-bit micro (e.g. PIC16) 
  since using a larger size will be very inefficient. Likewise re 16-bit variables on a 16-bit micro (e.g. PIC24). 

   If you are using a 32-bit micro (PIC32), then it doesn't really make any difference 
   since the MIPS instruction set has byte, word, and double-word instructions. 

  However on some 32-bit micros, if they lack such instructions, manipulating an 8-bit variable may be less efficient 
    than a 32-bit one due to masking.

on systems where you have a variable that is larger than the default register size 
  (e.g. a 16-bit variable on an 8-bit micro), 
  and that variable is shared between two threads or between the base thread and an interrupt handler, 
  one must make any operation (including just reading) on the variable atomic, that is make it appear to be done as one instruction. 
  This is called a critical section. The standard way to mitigate this is to surround the critical section with a disable/enable interrupt pair.

So going from 32-bit systems to 16-bit, or 16-bit to 8-bit, 
  any operations on variables of this type that are now larger than the default register size (but weren't before) 
  need to be considered a critical section.

Another main difference, going from one PIC processor to another, is the handling of peripherals. 
  This has less to do with word size and 
   more to do with the type and number of resources allocated on each chip. 

In general, Microchip has tried to make the programming of the SAME peripheral 
  used across different chips as similar as possible (e.g. timer0) , 
   but there will always be differences. Using their peripheral libraries will hide these differences to a large extent. 
    A final difference is the handling of interrupts. Again there is help here from the Microchip libraries.




PIC oscillator, timing, clock

The oscillator circuit can use several components as base of timing (external or internal)

PICmicros need a clock obtained from an oscillator:
Internal RC: accuracy/stability is not good, but the cheapest option and you save one or two pins that can be used as I/O ports. 
In modern PIC models, it varies from 32kHz to 8MHz. 
Some PICmicro have a calibration register where you can improve the accuracy.

External RC: connect cap+resistor to make the RC (resist/cap) "network" accuracy/stability is not good. 
These two types of oscillator are used in insensitive timing applications. Of course you lose some pin/ports.

LP (Low Power): low frequency crystal (32kHz to 200kHz) and two load capacitors (see table in the PIC datasheet). 
Used to save power and for low speed applications together with accuracy needed. 
Good for battery powered circuits. You lose two pins/ports.

XT (Crystal): mid 200kHz to 4MHz freqs. either crystal or ressonator (ceramic type). 
The crystal is very accurate (30 to 50ppm deviation) 
and temperature stable (you need two more ceramic load capacitors). 
Ceramic resonator is less accurate but doesn´t need the load capacitors (embedded in the resonator package) 
so it is cheaper than crystal choice. You lose tow pins/ports (unless they are exclusive for the crystal)

HS (High Speed): higher speed version of XT oscillator for freqs >4MHz. crystal or ceramic resonator. 
more power consumption for high speed processing.
max freq 20MHz (normally)

HSPLL (High Speed Phase Locked Loop): in some 18F PIC models, clock up to 40MHz, using a 10MHz crystal (together with the 2 load capacitors), 
which frequency is multiplied by 4 to obtain the full speed of 40MHz. 
You cannot use 40MHz crystal directly (because you would have EMI and it is hard or impossible to find 40MHz fundamental tone crystals).

There is an option to use external clock signals (coming from an external oscillator circuit, so using only one pin), 
and options with clock output from the PIC, etc.

The choice depends on the 
timing of the application, 
power consumption, 
temperature stability, 
use of pins (ports), 
cost of components, etc.
Pins:
Resonators usually have 3 pins (or 2 but not common)
Crystals have 2 pins
Oscillators modules have 4 pins (dil metal can) to 6 pins (smds) used for the 
GND, 
VDD, 
OUTPUT and 
Enable/Disable pins



On electrical schematic diagrams, crystals are designated with the class letter Y (Y1, Y2, etc.). 
Oscillators, whether they are crystal oscillators or others, are designated with the class letter G (G1, G2, etc.)
Crystals may also be designated on a schematic with X or XTAL, or a crystal oscillator with XO.



Examples/Links/tutorials:

http://picnote.blogspot.com/search/label/PIC16F628

http://www.robot-electronics.co.uk/htm/pic18_examples.htm

http://www.rakeshmondal.info/pic18f4550-tutorial-blinking-led#source_code_blink

http://singularengineer.com/programming-pic-18-using-xc8-mplab-x-io-ports/

http://embedded-lab.com/blog/making-a-digital-capacitance-meter-using-microcontroller/

http://embedded-lab.com/blog/making-a-simple-clap-switch/

http://www.gooligum.com.au/tutorials.html

http://www.amqrp.org/elmer160/lessons/index.html



Comments

Popular Posts