Showing posts with label PIC32. Show all posts
Showing posts with label PIC32. Show all posts

Sunday, 31 May 2015

YetAnotherPWM.c with the Pic32MX250F128B


During one of my tests, i was scratching my head for ages about why the PWM signal wasnt coming out on one of the remappable pins PPS. Went through examples, family datasheet, etc...
 Only to come to the conclusion that it would never work without disabling the JTAG ports in the configuration bits.

anotherpwm.c
YetAnotherpwm.X\anotherpwm.c
 1 /* 
 2  * File:   YetAnotherpwm.c
 3  * Author: Ras B.
 4  *
 5  * Created on 26 May 2015, 19:20
 6  */
 7 
 8 #include <plib.h>
 9 #include <p32xxxx.h>
10 
11 #pragma config   JTAGEN    = OFF // // disable the JTAG port  DDPCONbits.JTAGEN = 0;
12 #pragma config   FNOSC     = FRCPLL
13 #pragma config   FPLLIDIV  = DIV_2
14 #pragma config   FPLLMUL   = MUL_20
15 #pragma config   FPLLODIV  = DIV_2
16 #pragma config   FPBDIV    = DIV_1
17 #pragma config   POSCMOD   = OFF
18 #pragma config   FWDTEN    = OFF
19 //
20 #define GetSystemClock()        (40000000ul)
21 #define GetPeripheralClock()    (GetSystemClock()/(1<<OSCCONbits.PBDIV))// #define GetPeripheralClock()        (GetSystemClock()/(1<<OSCCONbits.PBDIV))
22 #define PWM_FREQ                33250
23 
24 volatile unsigned int incCount = 0; /*
25  * 
26  */
27 
28 void initAudio(void) {
29     // configures peripherals for Audio playback  
30     // Activate the PWM module
31     // OC1 in PWM mode, TMR2 based
32     OpenOC1(OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0);
33     // timebase   
34     // enable TMR2, prescale 1:1, internal clock, period  
35     OpenTimer2(T2_ON | T2_PS_1_1 | T2_SOURCE_INT, 0);
36     mT2SetIntPriority(4);
37     // set TMR2 interrupt priority     
38 } // initAudio
39 
40 void startAudio(int bitrate) { // begins the audio playback
41     //  set the period for the given bitrate
42     PR2 = GetPeripheralClock() / bitrate - 1; //fpb
43     //  enable the interrupt state machine
44     mT2ClearIntFlag();
45     // clear interrupt flag   
46     mT2IntEnable(1);
47     // enable TMR2 interrupt      
48 } // startAudio
49 
50 void haltAudio(void) {
51     // stops playback state machine
52     mT2IntEnable(0);
53 } // halt audio
54 
55 main() {
56     SYSTEMConfig(GetPeripheralClock(), SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE);
57     INTEnableSystemMultiVectoredInt();
58     //
59     TRISBbits.TRISB7 = 0; //Set port as output
60     RPB7Rbits.RPB7R = 0x0005;
61     mPORTAClearBits(BIT_0); //Clear bits to ensure light is off.
62     mPORTASetPinsDigitalOut(BIT_0); //Set port as output
63     //mPORTAClearBits(BIT_0); //Clear bits to ensure light is off.
64     // Set OC1 to pin RB7 with peripheral pin select
65     RPB7Rbits.RPB7R = 0x0005;
66     initAudio();
67     OC1RS = (PR2 + 1) * ((float) 50 / 100); // pwm duty cycle can be updated here on in interrupt
68     startAudio (PWM_FREQ);
69     //timer init
70     //mT2ClearIntFlag();
71     // clear interrupt flag
72     //mT2IntEnable(1);
73     //
74     while (1) {
75         if (incCount >= (PWM_FREQ/2)) {
76             incCount = 0;
77             mPORTAToggleBits(BIT_0);
78         }
79     }//while 1
80 }//main
81 
82 void __ISR(_TIMER_2_VECTOR, ipl4) T2Interrupt(void) {
83     // 
84     incCount++;
85     // 1. load the new samples for the next cycle  
86     OC1RS = (PR2 + 1) * ((float) 50 / 100);
87     // 2. clear interrupt flag and exit
88     mT2ClearIntFlag();
89 } // T2Interrupt  
90 

Wednesday, 29 April 2015

chipKIT DP32 Simple dub Siren Code



Sampling Rate 22.050 kHz, with 12 bit DAC MCP4725 ( breakout board)
Using button 2(Pin 17) on DP32 and Variable pot (A2).
For the signal out, the ac coupling circuit from previous post is necessary.
*Check also I2C Speed post HERE





















#include <sys/attribs.h>
#include <Wire.h>
#define MCP4725_DID 96 // define device id - see datasheet
//
#define SYS_FREQ            (40000000L)
#define PB_DIV              4
#define PRESCALE            2
#define FRQ                 22050 //21504
#define T1_TICK             (SYS_FREQ/PB_DIV/PRESCALE/FRQ)

#define WAVE_SAMPLES 256
const int buttonPin = 17; 
// variables will change:
int buttonState = 0;         // variable to read the pushbutton status
uint8_t playOn=0;            // Variable of play state/button state
volatile uint16_t a;
uint16_t b;
uint16_t d;
uint16_t e=0;
uint16_t inc;
uint8_t statedown=0;
boolean c;
boolean togg;
uint16_t sineData [WAVE_SAMPLES];
//


void setup()
{
  // Serial.begin(57600);
  initTmr();
  pinMode(A2, INPUT); //
  pinMode(13, OUTPUT); //
  //set pins to output because they are addressed in the main loop
  sine ();  
  Wire.begin() ;
}

void loop()
{
  uint16_t aIn =analogRead(A2);
  inc=aIn >>4;
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {  
    playOn=1;   
    // play is On    
  } 
  else{
    playOn=0;
    // play is Off

  }
  if(c !=togg){

    if(playOn==1){

      a = a++  ;
      a+= (inc+(e >>4));
      if(a>=WAVE_SAMPLES){
        a-=WAVE_SAMPLES;
        // ramp up or down variables
        if (statedown==0){
          e++;
          if(e>=1023){
            statedown=1;
            e--;
          }
        }
        else{
          e--;
          if (e==0){
            statedown=0;
            e++;
          }
        }
      }
      //
      Wire.beginTransmission(MCP4725_DID); //device adress
      Wire.send(64);                     // cmd to update the DAC
      Wire.send(sineData[a] >> 4);        // the 8 most significant bits...
      Wire.send((sineData[a] & 15) << 4); /* the 4 least significant bis...*/
      Wire.endTransmission();
      /*
       */
    } 
  }//
  c=togg;
}

// call interrupt handling vector
extern "C" {

  void __ISR(16, ipl6) int1Handler(void) 
  {
    togg= !togg;
    //
    //
    IFS0CLR = 0x80000;// Clear the T4 interrupt flag Bit 19
    //
  }
}

void initTmr(){
  // 
  T4CON=0x0; //Stop timer and clear registers
  T4CONSET = 0x0010; // set prescalar 1:2 ox60 to experiment
  TMR4 = 0x0; //Clear Timer 4 register
  PR4 = T1_TICK ; //0x17; // set timer to 23 
  IFS0CLR = 0x80000;// Clear the T4 interrupt flag Bit 19
  IPC4SET = 0x00000016;// Interrupt priority 5, 2
  IEC0SET = 0x80000;// Enable T4 interrupt Bit 19
  T4CONSET = 0x8000;// Enable Timer4  
}
void sine (){
  uint16_t i;
  for(i=0;i<WAVE_SAMPLES;i++){
    b = 2047*sin((2*PI/WAVE_SAMPLES)*i);
    b+=2047;
    sineData [i]=b;
  }
}


ChipKIT DP32 I2C Bus Speed with a MCP4725 DAC

Both arduino and MPIDE seem to have the I2C bus speed set to 100 kHz by default. So, here it is how to change it to 400kHz.
Inside the MPIDE folder, go to hardware\pic32\libraries\Wire\utility.
Inside file twi.h Find the string #define TWI_FREQ 100000 and change it to:  #defineTWI_FREQ 400000.
In my simple test i went from a 20Hz sinewave to a 72Hz just by effecting this change to the bus speed.
On the DP32 Board, SDA is assigned to Pin RB9 and SCL to Pin RB8.





Tuesday, 2 September 2014

Binary counter- 6 bit r2r DAC example for chipKit DP32 - PIC32MX250F128B

/*
Dubworks 6 bit r2r DAC example u4 LSB's using board leds 
 to display ;for chipKit DP32 board - PIC32MX250F128B
 @2014
 */
unsigned int i=0;
void setup(){
  Serial.begin(19200);
  LATBCLR = 0x3F;  // BIN 111111 ; 0xF for 4 leds only
  TRISBCLR =0x3F;  // Ports RB0-RB5 as Output ; 0xF for 4 leds only
}
void loop(){
  LATBCLR = 0x3F; //  clear 0xF for 4 leds only
  LATB |= i ;
  int a;
  a=PORTB;

  Serial.println(" I DEC ");
  Serial.println(i,DEC);
  Serial.println(" PORTD BIN ");
  Serial.println(a,BIN);

  i++;
  /* if you want to use the 5 bits of port B 0-4 */
  //  if(i < = 32){
  //    i=0; 
  //  }

  if(i < = 64){
    i=0;  
  }

  delay(250); //

}




note : P0-05 == RB0-RB5 ports

Wednesday, 30 July 2014

quick experiment with chipKit DP32 timers

quick experiment with chipKit DP32 timers



#include <sys/attribs.h>
#define WAVE_SAMPLES 256
uint16_t a;
uint16_t b;
uint16_t d;
uint16_t inc;
boolean c;
boolean togg;
uint16_t sineData [WAVE_SAMPLES]; // void setup() {   Serial.begin(19200);   initTmr();   pinMode(A2, INPUT); //   pinMode(13, OUTPUT); //LED   sine ();   } void loop() {   uint16_t aIn =analogRead(A2);   inc=aIn>>2;   d=sineData[a];   // if(c !=togg){   // Serial.println(a);   // Serial.println(d);   // Serial.println("inc");   // Serial.println(inc);   //   // //Serial.println("togg");   // //Serial.println(togg,DEC);   // } //   c=togg; } // call interrupt handling vector extern "C" {   void __ISR(16, ipl6) int1Handler(void)   {     togg= !togg;     analogWrite(13, d); //a++;     //     //     a++;     a+=inc;     if(a>=WAVE_SAMPLES)       a-=WAVE_SAMPLES;     IFS0CLR = 0x80000;// Clear the T4 interrupt flag Bit 19     //   } } void initTmr(){   //   T4CON=0x0; //Stop timer and clear registers   T4CONSET = 0x0070; // set prescalar 1:256   TMR4 = 0x0; //Clear Timer 4 register   PR4 = 0x1D1; // set timer to 465   IFS0CLR = 0x80000;// Clear the T4 interrupt flag Bit 19   IPC4SET = 0x00000016;// Interrupt priority 5, 2   IEC0SET = 0x80000;// Enable T4 interrupt Bit 19   T4CONSET = 0x8000;// Enable Timer4 } void sine (){   uint16_t i;   for(i=0;i<WAVE_SAMPLES;i++){     b = 127*sin((2*PI/WAVE_SAMPLES)*i);     b+=127;     sineData [i]=b;   } }

Tuesday, 29 July 2014

Dub && Wise Synth


*some decoupling capacitors 100nFclose to the analog pins should be added.




My initial intention was to create something focused for the soundsystem culture. This turned out to be much more difficult than i thought .
Dub siren/Elec tom synth/And oscilattor+ MAD Lfos (some trying to recreate some of the sounds in a synare that Jah Shaka got us all used to)...All this synthesized on the fly with the help of some wavetables (all created during the start up)
.
Pots for :
-Oscillator wave selector ( Sine,cosine  Saw, Inverted Saw, Square wave, triangle and 1 extra slots for now )
-LFO rate
-LFO modulator type select ( Any of the above tables, plus a few more specific and tailored options)
-Attack
-Release
* Both attack and release can interact with the LFO
- Mode selector ( Dub Siren, Sound effects " a la Synare", Elec-Tom synth)

This video is just as an update on the proceedings.
Here i am using the Arduino Due.
Due to its complexity, i ended up re-writing the whole code from scratch and fresh to suit this specific idea.
Already started porting a similar idea to the chipKit DP32, and Pinguino and an Xmos version also soon to come, subject to availability of spare time.



Thursday, 21 November 2013

Father Christmas to bring new PIC32MZ

I am a bit short for words, but had to share !
I actually thought it would never be more than a rumour eh eh !
December come...

Microchip will soon release new PIC32MZ, with first members of the family expected starting from December , with :
- 200 MHz & 330 DMIPS !!!
- 2 MB Flash with Live Update
- 512 KB high speed SRAM


Tuesday, 12 November 2013

PLBP for chipKit DP32 { Proverbial (4) Led Blink Program }





Ok I just could not resist, and had to post the Proverbial Led blink Program adapted for the DP32, that has 4 LED's on the board ( Digital Pins 11 to 14).
Will scroll them from right to left, speed varying on the variable resistor on board( trim pot).






/* Proverbial (4) Led Blink Program
 
 Scrolls 4 light emitting diodes(LED), by turning on and off connected to 4 different digital  
 pins, using the delay() function and the current millis alike :) . 
 
 The circuit:
 * 4 LED's on board - pins D11, D12, D13 and D14 
 ** Variable resistor/trimpot on A2
 
 *** Version done for the chipKit board DP32 **
 ****  http://dubworks.blogspot.co.uk/
 */

// constants won't change. Used here to 
// set pin numbers:
const int ledPin =  11;      // the number of the LED pin
const int ledPin1 =  12; 
const int ledPin2 =  13; 
const int ledPin3 =  14; 
int i;
// Variables will change:
int ledState = LOW;             // ledState used to set the LED
int ledState1 = LOW;
int ledState2 = LOW;
int ledState3 = LOW;
long previousMillis = 0;        // will store last time LED was updated

// the follow variables is a long because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
//long interval = 500;           // interval at which to blink (milliseconds)

void setup() {
  // set the digital pin as output:
  pinMode(ledPin, OUTPUT);
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(ledPin3, OUTPUT);
  pinMode(A2, INPUT);
  ledState = !ledState;  //Toggle the bits to start
  ledState1 = !ledState1;
  ledState2 = !ledState2;
  ledState3 = !ledState3;  
}

void loop()
{
  boolean b; 
  long interval = analogRead(A2); // interval at which to enter function.(milliseconds)
  interval= interval/3; //So it is not too slow
  digitalWrite(ledPin, ledState);
  digitalWrite(ledPin1, ledState1);
  digitalWrite(ledPin2, ledState2);
  digitalWrite(ledPin3, ledState3); 
  // 

  // check to see if it's time 
  unsigned long currentMillis = millis();

  if(currentMillis - previousMillis > interval) {
    // save the last time  
    previousMillis = currentMillis;   
    // 
    int var;
    var=interval-(currentMillis - previousMillis);
    // conditional depending on increment accumulator
    if(!b){
      switch (i) {

      case 0 :    
        ledState = !ledState;
        digitalWrite(ledPin, ledState); 
        delay((var*0.5));
        break;

      case 1 :    
        ledState1 = !ledState1;
        digitalWrite(ledPin1, ledState1); 
        delay((var));
        break;

      case 2 :    
        ledState2 = !ledState2;
        digitalWrite(ledPin2, ledState2); 
        delay((var*1.5));
        break;

      case 3 :    
        ledState3 = !ledState3;
        digitalWrite(ledPin3, ledState3); 
        delay((var*2));
        break;

      default:
        b=!b;
        break;
      }
    }
    else{
      switch (i) {

      case 0 :    
        ledState = !ledState;
        digitalWrite(ledPin, ledState); 
        delay((var*2.5));
        break;

      case 1 :    
        ledState1 = !ledState1;
        digitalWrite(ledPin1, ledState1); 
        delay((var*3));
        break;

      case 2 :    
        ledState2 = !ledState2;
        digitalWrite(ledPin2, ledState2); 
        delay((var*3.5));
        break;

      case 3 :    
        ledState3 = !ledState3;
        digitalWrite(ledPin3, ledState3); 
        delay((var*4));
        break;

      default:
        b=!b;
        break;
      }
    }
    i++; // Increment our accumulator
    i=i%5; 
    // Keep the value within  the parameters needed for our switch case
    // in this case 5, so we can have 4 + 1 
    // (0, 1, 2 and 3) + 1 for default toggling of boolean variable b. (aesthetic reasons ?!)  
  }
}




Saturday, 2 November 2013

A DP32 chipKit from Dangerous prototypes... for free ?!? Yes Please !!



As some of you might have noticed, i love to dig into,  learn with, bash my head against, and ultimately discover new platforms. In my perspective it is essential to develop new and wide skills that ultimately will make one a better prepared and experienced programmer and engineer !
Recently i have been looking into the PIC32 as the most probable option to the Retro-inspired drum-synth i been developing for quite a while now, despite the fact i been using several chips along the way to develop ideas for the final version.

So, i took my chance and proposed an idea i been working in for a while, as part of a Dangerous Prototypes give-away with Microchip and Diligent in the form of a contest .
And guess what ?! I won !

QUOTE
Another winner is Ras B, and his idea for a CHipKit version of a Retro-Inspired Cynare Drum Synth scored him a chipKIT DP 32:
Id use the DP32 to make a CHipKit version of a Retro-Inspired Cynare Drum Synth( ADSR with variable exponential attack, LFO’s included) and some additional features ( Modulation related Like phaser, flanger and some basic reverb and delay- This through an additional memory chip to allow some leverage in the chips memory limitations) 
I am still working on implementing some of it, while a lot of it i have or am currently implementing it
* Funny thing was i was actually working on it when , during a break, i came across the news that i'd won !! :) .

I have already worked with the dip version of the PIC32 , even posted about it.
And i am not sure as yet, if all these features are all possible in a DIP version of it ( as it only runs at around 40 MHz, compared with th 80MHz of SMD versions).
But i vow to make a lighter version ( if need be) for the dip version, as i love it myself.
There are some limitations that might become an issue to take it as far as intend , due to the abstraction created by higher level languages as the "Arduino-based" used by the MPIDE. But, bit by bit (pass the pun) , i intend to present any limitations i might come across and reference them, so it helps anyone else !





Thursday, 8 August 2013

PIC32- Variable type defs

One of the main concerns about migrating/working with other type of uC’s ( 8 bits like AVR PIC, or 16 like PIC24 or the DSC’s dsPIC family), was how the 32 bit architecture will influence any previous code i might have regarding variable type definitions.
As its based on the GCC compiler, it is prepared for both ANSI with CCI compliance. Ill keep with the basics out of type defs.
The ANSI C Standard does indicate minimum requirements for these
types, as specified in .
* For more info on compiler compliance check the XC32 Compiler User guide in chapter “2.4.6 Sizes of Type



From researching the include files, one can get this info :

/* 7.18.1.1 Exact-width integer types */

typedef __signed char __int8_t;
typedef unsigned char __uint8_t;
typedef short int __int16_t;
typedef unsigned short int     __uint16_t;
typedef int __int32_t;
typedef unsigned int       __uint32_t;
#ifdef __COMPILER_INT64__
typedef __COMPILER_INT64__ __int64_t;
typedef __COMPILER_UINT64__    __uint64_t;
#elif defined(_LP64)
typedef long int __int64_t;
typedef unsigned long int      __uint64_t;
#else
/* LONGLONG */
__extension__ 
typedef long long int __int64_t;
/* LONGLONG */
__extension__ 
typedef unsigned long long int __uint64_t;
#endif

#define __BIT_TYPES_DEFINED__

Which gives us :

// MPLAB C32 range of Signed values
char c; // -128 to 127
short s; // -32,768 to 32,767
int i; // -2,147,483,648 to 2,147,483,647
long l; // -2,147,483,648 to 2,147,483,647

Of course, we also have the unsigned attribute:

//  MPLAB C32 range of  Unsigned values
unsigned char c; // 0 to 255
unsigned short s; // 0 to 65,535
unsigned int i; // 0 to 4,294,967,295
unsigned long l; // 0 to 4,294,967,295

For int, 4 bytes in the physical RAM is used.
So, if we do not have to use int and long, we should use char.
To hold one char variable, C32 compiler will use only 8 bits.
Another possibility is short type, which will use 16 bits to hold one short variable
PIC32‘s ALU  is performing all arithmetic operations in the same number of cycles for 32-bit, 16-bit or 8-bit integers, which turns the variable long into just a synonym of the basic integer type int.
It is ok from performance point of view, but it comes with a price.
The only limiting factor, preventing us from always using 32-bit integers , is the consideration of the internal resources , and in this case the RAM memory
*  keep the size of your variables to the minimum necessary; operating on bytes versus  word  can make a big difference in terms of code compactness/efficiency.

If really a large range of values is needed, we can use 64-bit types

//  C32 range of 64-bit type values
long long l; // ranges from -2 to the power of 63 to +2 to the power of 63-1
unsigned long long l; // ranges from 0 to +2 to the power of 64

//  C32 range of Floating point type values
float f; // 32-bit floating point
double d; // 64-bit floating point 
long double d; // 64-bit floating point, synonym of double

The long long integer type offers 64-bit support and requires 8 bytes of memory; So, we can expect a small performance decrease for using long long integers.

Ill leave  several excerpts from the header files...

/* 7.18.1.1 Exact-width integer types */

typedef __signed char __int8_t;
typedef unsigned char __uint8_t;
typedef short int __int16_t;
typedef unsigned short int     __uint16_t;
typedef int __int32_t;
typedef unsigned int       __uint32_t;
#ifdef __COMPILER_INT64__
typedef __COMPILER_INT64__ __int64_t;
typedef __COMPILER_UINT64__    __uint64_t;
#elif defined(_LP64)
typedef long int __int64_t;
typedef unsigned long int      __uint64_t;
#else
/* LONGLONG */
__extension__ 
typedef long long int __int64_t;
/* LONGLONG */
__extension__ 
typedef unsigned long long int __uint64_t;
#endif

#define __BIT_TYPES_DEFINED__

/* 7.18.1.4 Integer types capable of holding object pointers */

#ifdef _LP64
typedef long int       __intptr_t;
typedef unsigned long int     __uintptr_t;
#else
typedef int       __intptr_t;
typedef unsigned int      __uintptr_t;
#endif

#endif /* !_MIPS_INT_TYPES_H_ */


Also :

* 7.18.1.2 Minimum-width integer types */

__extension__
typedef __signed char  int_least8_t;
typedef unsigned char uint_least8_t;
typedef short int int_least16_t;
typedef unsigned short int uint_least16_t;
typedef int int_least24_t;
typedef unsigned int uint_least24_t;
typedef int int_least32_t;
typedef unsigned int uint_least32_t;
#ifdef __COMPILER_INT64__
typedef __COMPILER_INT64__ int_least64_t;
typedef __COMPILER_UINT64__ uint_least64_t;
#elif defined(_LP64)
typedef long int int_least64_t;
typedef unsigned long int uint_least64_t;
#else
/* LONGLONG */
__extension__
typedef long long int int_least64_t;
/* LONGLONG */
__extension__
typedef unsigned long long int uint_least64_t;
#endif

/* 7.18.1.3 Fastest minimum-width integer types */
typedef int   int_fast8_t;
typedef unsigned int  uint_fast8_t;
typedef int  int_fast16_t;
typedef unsigned int uint_fast16_t;
typedef int  int_fast24_t;
typedef unsigned int uint_fast24_t;
typedef int  int_fast32_t;
typedef unsigned int uint_fast32_t;
#ifdef __COMPILER_INT64__
typedef __COMPILER_INT64__  int_fast64_t;
typedef __COMPILER_UINT64__ uint_fast64_t;
#elif defined(_LP64)
typedef long int  int_fast64_t;
typedef unsigned long int uint_fast64_t;
#else
/* LONGLONG */
__extension__
typedef long long int  int_fast64_t;
/* LONGLONG */
__extension__
typedef unsigned long long int uint_fast64_t;
#endif

/* 7.18.1.5 Greatest-width integer types */

#ifdef __COMPILER_INT64__
typedef __COMPILER_INT64__      intmax_t;
typedef unsigned __COMPILER_INT64__  uintmax_t;
#elif defined(_LP64)
typedef long int      intmax_t;
typedef unsigned long int     uintmax_t;
#else
/* LONGLONG */
__extension__
typedef long long int      intmax_t;
/* LONGLONG */
__extension__
typedef unsigned long long int     uintmax_t;
#endif

#endif /* !_MIPS_INT_MWGWTYPES_H_ */


Regarding the limits of each type def...


/* $NetBSD: int_limits.h,v 1.3 2002/11/03 19:55:23 thorpej Exp $ */

/*-
 * Copyright (c) 2001 The NetBSD Foundation, Inc.
 * All rights reserved.
 */
...

/*
 * 7.18.2 Limits of specified-width integer types
 */

/* 7.18.2.1 Limits of exact-width integer types */

/* minimum values of exact-width signed integer types */
#define INT8_MIN (-0x7f-1) /* int8_t  */
#define INT16_MIN (-0x7fff-1) /* int16_t  */
#define INT32_MIN (-0x7fffffff-1) /* int32_t  */
#ifdef _LP64
#define INT64_MIN (-0x7fffffffffffffffL-1) /* int64_t  */
#else
#define INT64_MIN (-0x7fffffffffffffffLL-1) /* int64_t  */
#endif

/* maximum values of exact-width signed integer types */
#define INT8_MAX 0x7f /* int8_t  */
#define INT16_MAX 0x7fff /* int16_t  */
#define INT32_MAX 0x7fffffff /* int32_t  */
#ifdef _LP64
#define INT64_MAX 0x7fffffffffffffffL /* int64_t  */
#else
#define INT64_MAX 0x7fffffffffffffffLL /* int64_t  */
#endif

/* maximum values of exact-width unsigned integer types */
#define UINT8_MAX 0xffU /* uint8_t  */
#define UINT16_MAX 0xffffU /* uint16_t  */
#define UINT32_MAX 0xffffffffU /* uint32_t  */
#ifdef _LP64
#define UINT64_MAX 0xffffffffffffffffUL /* uint64_t  */
#else
#define UINT64_MAX 0xffffffffffffffffULL /* uint64_t  */
#endif

/* 7.18.2.2 Limits of minimum-width integer types */

/* minimum values of minimum-width signed integer types */
#define INT_LEAST8_MIN (-0x7f-1) /* int_least8_t  */
#define INT_LEAST16_MIN (-0x7fff-1) /* int_least16_t  */
#define INT_LEAST24_MIN (-0x7fffffff-1) /* int_least24_t  */
#define INT_LEAST32_MIN (-0x7fffffff-1) /* int_least32_t  */
#ifdef _LP64
#define INT_LEAST64_MIN (-0x7fffffffffffffffL-1) /* int_least64_t  */
#else
#define INT_LEAST64_MIN (-0x7fffffffffffffffLL-1) /* int_least64_t  */
#endif

/* maximum values of minimum-width signed integer types */
#define INT_LEAST8_MAX 0x7f /* int_least8_t  */
#define INT_LEAST16_MAX 0x7fff /* int_least16_t  */
#define INT_LEAST24_MAX 0x7fffffff /* int_least24_t  */
#define INT_LEAST32_MAX 0x7fffffff /* int_least32_t  */
#ifdef _LP64
#define INT_LEAST64_MAX 0x7fffffffffffffffL /* int_least64_t  */
#else
#define INT_LEAST64_MAX 0x7fffffffffffffffLL /* int_least64_t  */
#endif

/* maximum values of minimum-width unsigned integer types */
#define UINT_LEAST8_MAX 0xffU /* uint_least8_t  */
#define UINT_LEAST16_MAX 0xffffU /* uint_least16_t */
#define UINT_LEAST24_MAX 0xffffffffU /* uint_least24_t */
#define UINT_LEAST32_MAX 0xffffffffU /* uint_least32_t */
#ifdef _LP64
#define UINT_LEAST64_MAX 0xffffffffffffffffUL /* uint_least64_t */
#else
#define UINT_LEAST64_MAX 0xffffffffffffffffULL /* uint_least64_t */
#endif

/* 7.18.2.3 Limits of fastest minimum-width integer types */

/* minimum values of fastest minimum-width signed integer types */
#define INT_FAST8_MIN (-0x7fffffff-1) /* int_fast8_t  */
#define INT_FAST16_MIN (-0x7fffffff-1) /* int_fast16_t  */
#define INT_FAST24_MIN (-0x7fffffff-1) /* int_fast24_t  */
#define INT_FAST32_MIN (-0x7fffffff-1) /* int_fast32_t  */
#ifdef _LP64
#define INT_FAST64_MIN (-0x7fffffffffffffffL-1) /* int_fast64_t  */
#else
#define INT_FAST64_MIN (-0x7fffffffffffffffLL-1) /* int_fast64_t  */
#endif

/* maximum values of fastest minimum-width signed integer types */
#define INT_FAST8_MAX 0x7fffffff /* int_fast8_t  */
#define INT_FAST16_MAX 0x7fffffff /* int_fast16_t  */
#define INT_FAST24_MAX 0x7fffffff /* int_fast24_t  */
#define INT_FAST32_MAX 0x7fffffff /* int_fast32_t  */
#ifdef _LP64
#define INT_FAST64_MAX 0x7fffffffffffffffL /* int_fast64_t  */
#else
#define INT_FAST64_MAX 0x7fffffffffffffffLL /* int_fast64_t  */
#endif

/* maximum values of fastest minimum-width unsigned integer types */
#define UINT_FAST8_MAX 0xffffffffU /* uint_fast8_t  */
#define UINT_FAST16_MAX 0xffffffffU /* uint_fast16_t  */
#define UINT_FAST24_MAX 0xffffffffU /* uint_fast24_t  */
#define UINT_FAST32_MAX 0xffffffffU /* uint_fast32_t  */
#ifdef _LP64
#define UINT_FAST64_MAX 0xffffffffffffffffUL /* uint_fast64_t  */
#else
#define UINT_FAST64_MAX 0xffffffffffffffffULL /* uint_fast64_t  */
#endif

/* 7.18.2.4 Limits of integer types capable of holding object pointers */

#ifdef _LP64
#define INTPTR_MIN (-0x7fffffffffffffffL-1) /* intptr_t  */
#define INTPTR_MAX 0x7fffffffffffffffL /* intptr_t  */
#define UINTPTR_MAX 0xffffffffffffffffUL /* uintptr_t  */
#else
#define INTPTR_MIN (-0x7fffffff-1) /* intptr_t  */
#define INTPTR_MAX 0x7fffffff /* intptr_t  */
#define UINTPTR_MAX 0xffffffffU /* uintptr_t  */
#endif

/* 7.18.2.5 Limits of greatest-width integer types */

#ifdef _LP64
#define INTMAX_MIN (-0x7fffffffffffffffL-1) /* intmax_t  */
#define INTMAX_MAX 0x7fffffffffffffffL /* intmax_t  */
#define UINTMAX_MAX 0xffffffffffffffffUL /* uintmax_t  */
#else
#define INTMAX_MIN (-0x7fffffffffffffffLL-1) /* intmax_t  */
#define INTMAX_MAX 0x7fffffffffffffffLL /* intmax_t  */
#define UINTMAX_MAX 0xffffffffffffffffULL /* uintmax_t  */
#endif


/*
 * 7.18.3 Limits of other integer types
 */

/* limits of ptrdiff_t */
#ifdef _LP64
#define PTRDIFF_MIN (-0x7fffffffffffffffL-1) /* ptrdiff_t  */
#define PTRDIFF_MAX 0x7fffffffffffffffL /* ptrdiff_t  */
#else
#define PTRDIFF_MIN (-0x7fffffff-1) /* ptrdiff_t  */
#define PTRDIFF_MAX 0x7fffffff /* ptrdiff_t  */
#endif

/* limits of sig_atomic_t */
#define SIG_ATOMIC_MIN (-0x7fffffff-1) /* sig_atomic_t  */
#define SIG_ATOMIC_MAX 0x7fffffff /* sig_atomic_t  */

/* limit of size_t */
#ifdef _LP64
#define SIZE_MAX 0xffffffffffffffffUL /* size_t  */
#else
#define SIZE_MAX 0xffffffffU /* size_t  */
#endif

#ifndef WCHAR_MIN /* also possibly defined in */
/* limits of wchar_t */
#define WCHAR_MIN 0 /* wchar_t  */
#define WCHAR_MAX 0xffff /* wchar_t  */

/* limits of wint_t */
#define WINT_MIN (-0x7fffffff-1) /* wint_t  */
#define WINT_MAX 0x7fffffff /* wint_t  */
#endif

#endif /* !_MIPS_INT_LIMITS_H_ */



(1): http://ww1.microchip.com/downloads/en/DeviceDoc/51686F.pdf 
(2): http://www.youtube.com/watch?v=6FNKJSWuaJE