TIMotorLIBExample1/main.c

This is an example on how to use adc units. The shown code adds two channels to de AD sequencer and reads the values in the ISR.

//-----------------------------------------------------------
// Includes
// -------------------------------------------------------------
#include "Example1.h"  // includes for our particular project

//-----------------------------------------------------------
// Define
//-----------------------------------------------------------
// A/D #defines
#define IA_CH                 0                   // ia A/D channel
#define IB_CH                 0                   // ib A/D channel

//-----------------------------------------------------------
// Implemented Functions
// -------------------------------------------------------------
interrupt void ADInterrupt(void);

//-----------------------------------------------------------
// Globals
//-----------------------------------------------------------
// A/D variables
volatile _iq ia, ib;          // measured currents


//-----------------------------------------------------------

interrupt void ADInterrupt(void)
{
  ia = ReadADInputWriteRaw(ADCINA2);
  ib = ReadADInputWriteRaw(ADCINB2);
  // prepare next adquisition
  ReinitAD();
}

//-----------------------------------------------------------

//-----------------------------------------------------------
// main
// -------------------------------------------------------------
void main(void)
{
  // SYSCLKOUT = 150Mhz
  // HSPCLK SYSCLKOUT/8 = 18.75MHz
  // LSPCLK= SYSCLKOUT/4
  InitCPU(8, 4);
  
  // AD initialization
  ConfigureAD(ADInterrupt, CASCADED_SEQ_MODE, 
    SIMULTANEOUS_MODE, PWM_SOC, 0);

  // ------------------ Add AD channels
  // ------------------- Current Sensor data -----------------------------
  // loops = 2;
  // rt = 1/1000;
  // Rm = 150;     (143 measured between input and GND)
  // op_gain = 0.5;
  // MAXBITS = 4096;
  // Vmax = 3
  // GAIN: % 1/(loops*rt_sensor*Rm*op_gain*MAXBITS/Vmax)
  // ------------------- Current Sensor data------ ------------------------

  AddChannel(ADCINA2, IA_CH, _IQ(0.03493696), _IQ(0.00512));                    // ia current
  AddChannel(ADCINB2, IB_CH, _IQ(-0.104635519999999), _IQ(0.00512));            // ib current

  // Configure Memory to store AD samples (OVERWRITE/NOVERWRITE)
  InitDataStorageBuffer(NOVERWRITE);

  SetTrigger();     // enable trigger to store AD samples

  // enable PIE module and CPU interrupts
  EnableInterrupts();         // <-- PABLO: This call MUST BE the last one
  // main loop
  while(1){
    IDLE;
  }
}
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines
Generated on Mon Apr 23 12:59:20 2012 for TIMotorLIB by  doxygen 1.6.3