The document discusses analog to digital conversion using PIC microcontrollers. It describes different ADC architectures like successive approximation register (SAR) and flash ADCs. It explains the steps of ADC conversion and how to configure the ADC module of PIC24 microcontrollers. It provides examples of reading analog sensor values using interrupts and scanning multiple input channels. It also discusses using DMA with dsPIC ADCs to improve data transfer efficiency.
Ce cours présente les principaux moyens de communications que l'on peut déployer au sein d'un système embarqué. Après un rappel sur les différents types de communication (série/parallèle, synchrone/asynchrone, half-duplex/full-duplex), le cours présente le port série ainsi que l'implémentation UART. Vient ensuite le bus USB et les deux modes en hôte ou périphérique. Après cela, le cours présente les protocoles I2C et puis SPI. Enfin, il termine avec le simple bus 1-Wire. Tous ces différents moyens de communication sont disponibles sur la BeagleBone Black et le cours illustre comment les manipuler à l'aide du Linux embarqué.
Ce cours présente les principaux moyens de communications que l'on peut déployer au sein d'un système embarqué. Après un rappel sur les différents types de communication (série/parallèle, synchrone/asynchrone, half-duplex/full-duplex), le cours présente le port série ainsi que l'implémentation UART. Vient ensuite le bus USB et les deux modes en hôte ou périphérique. Après cela, le cours présente les protocoles I2C et puis SPI. Enfin, il termine avec le simple bus 1-Wire. Tous ces différents moyens de communication sont disponibles sur la BeagleBone Black et le cours illustre comment les manipuler à l'aide du Linux embarqué.
Formation Bus de Terrain _Partie 3_1 _Modbus tcpWojciech GOMOLKA
Formation basique pour nos techniciens.
Complément de la formation plus générale (partie 3).
Présentations de quelqeus détails du protocole Modbus TCP.
Ce premier cours introduit la notion de système embarqué en commençant par en donner une définition. Il les caractérise ensuite sur base de plusieurs critères : type d'application, de fonction visé, taille, fiabilité, efficacité. Il présente ensuite plusieurs aspects hardware (unité de calcul, architecture matérielle, composants clés) et software (niveau de programmation, processus de développement). Enfin, il conclut en discutant sur ce qu'est un ingénieur en systèmes embarqués.
ARDUINO + LABVIEW : CONTRÔLE DE LA TEMPÉRATUREHajer Dahech
les Liens des fichiers du projet et le rapport PDF sur la page
https://hajereducation.tn/arduino-labview/
voir aussi
https://hajereducation.tn/category/embedded-system-projects/
===============
lien site https://hajereducation.tn
ce cours est destiné aux élèves de génie électrique est plus spécialement aux filière STE ,discipline sciences de l'ingenieur.N'hesiter pas à me faire parvenir vos remarques et vos critiques sur mon adresse zahidiabdo@yahoo.fr;
Projet de communication numérique Réalisation d'une chaîne de transmission nu...Yassine Nasser
Une chaîne de transmission numérique a pour mission de transporter des données en minimisant le nombre d’erreurs et de pertes. D’autres paramètres sont tout aussi importants comme par exemple la puissance d’émission nécessaire ou la bande-passante. C’est pourquoi l’étude des performances d’une chaîne de transmission est une étape essentielle de développement d’un système de télécommunications car l’écart par rapport aux performances théoriques peut être grand. Cependant, la réalisation de prototype étant coûteuse et longue, il est apparu évident qu’une simulation sur ordinateur d’une chaîne complète de transmission permettrait de réduire les coûts et de donner une bonne estimation des résultats réels.
Suite à la demande du lycée Etienne Mimard, nous avons réalisé un projet permettant de déterminer la cause d'un pic de consommation énergétique afin de réduire les coûts engendrés inutilement. Pour cela, il a été installé deux centrales de mesure qui ont faits l'objet d'un projet de BTS Electrotechnique. Ces centrales sont disposées en aval des installations électriques. On a réalisé un logiciel et un site web permettant de traiter le flux de données venant des deux boitiers d'acquisition afin d'avoir un suivi en temps réel et archivés sur le poste de supervision. Il a pour but d'être utilisé par des professionnels afin de déterminer précisément les causes de ces surconsommations.
Formation Bus de Terrain _Partie 3_1 _Modbus tcpWojciech GOMOLKA
Formation basique pour nos techniciens.
Complément de la formation plus générale (partie 3).
Présentations de quelqeus détails du protocole Modbus TCP.
Ce premier cours introduit la notion de système embarqué en commençant par en donner une définition. Il les caractérise ensuite sur base de plusieurs critères : type d'application, de fonction visé, taille, fiabilité, efficacité. Il présente ensuite plusieurs aspects hardware (unité de calcul, architecture matérielle, composants clés) et software (niveau de programmation, processus de développement). Enfin, il conclut en discutant sur ce qu'est un ingénieur en systèmes embarqués.
ARDUINO + LABVIEW : CONTRÔLE DE LA TEMPÉRATUREHajer Dahech
les Liens des fichiers du projet et le rapport PDF sur la page
https://hajereducation.tn/arduino-labview/
voir aussi
https://hajereducation.tn/category/embedded-system-projects/
===============
lien site https://hajereducation.tn
ce cours est destiné aux élèves de génie électrique est plus spécialement aux filière STE ,discipline sciences de l'ingenieur.N'hesiter pas à me faire parvenir vos remarques et vos critiques sur mon adresse zahidiabdo@yahoo.fr;
Projet de communication numérique Réalisation d'une chaîne de transmission nu...Yassine Nasser
Une chaîne de transmission numérique a pour mission de transporter des données en minimisant le nombre d’erreurs et de pertes. D’autres paramètres sont tout aussi importants comme par exemple la puissance d’émission nécessaire ou la bande-passante. C’est pourquoi l’étude des performances d’une chaîne de transmission est une étape essentielle de développement d’un système de télécommunications car l’écart par rapport aux performances théoriques peut être grand. Cependant, la réalisation de prototype étant coûteuse et longue, il est apparu évident qu’une simulation sur ordinateur d’une chaîne complète de transmission permettrait de réduire les coûts et de donner une bonne estimation des résultats réels.
Suite à la demande du lycée Etienne Mimard, nous avons réalisé un projet permettant de déterminer la cause d'un pic de consommation énergétique afin de réduire les coûts engendrés inutilement. Pour cela, il a été installé deux centrales de mesure qui ont faits l'objet d'un projet de BTS Electrotechnique. Ces centrales sont disposées en aval des installations électriques. On a réalisé un logiciel et un site web permettant de traiter le flux de données venant des deux boitiers d'acquisition afin d'avoir un suivi en temps réel et archivés sur le poste de supervision. Il a pour but d'être utilisé par des professionnels afin de déterminer précisément les causes de ces surconsommations.
Analog to digital converter is one of the most important feature of micro controller. here i am explaining about basic of ADC, working and how exactly controller do it. Here i also explaining registers of ADC and attached a sample code.
2. 2
ADC architectures
Steps of A/D conversion
Configure A/D module of PIC24
A/D Interrupt
Using multiple channels
dsPIC utilizing DMA
Industrial Embedded Systems
Outline
3. 3
Successice Approximation Register
AD Converter with feedback
Generally N=8-16 bit (PIC24FJ128GA010 has N=10bit ADC)
Conversion time: N cycle
Initially set VDAC to ½ Vref, then see if Vin higher or lower than VDAC. If >
½ Vref, then next guess is between Vref and ½Vref, else next guess is
between Vref and GND. Do this for each bit of the ADC
ADC architectures
SAR
4. 4
Counter ramp ADC
Simple
Slow
Conversion time: 2N cycle
Fast
Conversion time: 1 cycle
Requires the most transistors of any
architecture, N-bit converter requires 2N-1
comparators.
Commercially available flash converters
up to 12 bits.
Flash ADC
Industrial Embedded Systems
ADC architectures
5. 5Industrial Embedded Systems
Input hardware for ADC
Some low-pass filtering and
a Zener diode to protect the
input PIN from overvoltage
If input voltage is
higher, a voltage divider
can be used to fit the
voltage level.
To improve the
performance a voltage
follower is also applied (use
a rail-to-rail Op-Amp)
6. 6
Configuring AD modul
Enable analog input channel(s)
Set the reference voltage
Clock cycle, clock source (TAD)
Sampling and conversion settings
Form of the result
Enable modul
Configure A/D interrupt (if required)
Delete flag belonging to the ADC
Enable interrupt
Select the given analog channel
Sampling time (1-31 TAD)
Time to charge up the storage capacitor
Conversion time (12 TAD)
The end of the conversion is indicated by a flag
Read the value from the buffer register
If required delete interrupt flag
Industrial Embedded Systems
Steps of AD conversion
7. 7
AD module has 6 Special Function Register (SFR)
AD1CON1, AD1CON2, AD1CON3, AD1CHS, AD1PCFG, AD1CSSL
PIC24 has 16 analog input pin (AN0-AN15)
Enable analog input channel(s)
Using AD1PCFG register
0s will mark the analog inputs, and 1s will configure the respective
pins as digital inputs
AD1PCFG = 0xFFDF; // AN5 analog input
Set the reference voltage
AD1CON2 register<15:13>
Internal voltage level (AVDD, AVSS)
External reference voltage
Combination of the two
AD1CON2bits.VCFG = 0b000; // ref+=VDD, ref-=VSS
Configure AD modul
Industrial Embedded Systems
8. 8
Clock cycle (TAD)
In the case of PIC24FJ128GA010 minimum clock cylce TAD is 75ns
Clock derived from sytem clock (TCY)
AD1CON3bits.ARDC = 0; //system clock, TCY=2*TOSC
TAD=TCY (ACDS + 1)
AD1CON3bits.ADCS = 0; //TAD=TCY=250ns>75ns
Configure AD modul
Industrial Embedded Systems
9. 9
Sampling time
Its value depends on the input resistane of the signal and the storage
capacitor
The frequency of the input signals also has to be taken into consideration
The accuracy can be improved by increasing the sampling time
Configure AD modul
Industrial Embedded Systems
10. 10
Sampling and conversion settings
The sampling time and the beginning of the conversion can be determined
By software (delete AD1CON1bits.SAMP bit)
By hardware (Active transition on INT0 pin ends sampling and starts
conversion)
Automatic conversion
AD1CON3bits.SSRC = 0b000; //software conversion
AD1CON3bits.SSRC = 0b111; //automatic conversion
In the case of software conversion the enough sampling time should be
guaranteed in the code
In the case of automatic conversion the sampling has to set:
AD1CON1bits.SAMC = 31; //TSAMP=31TAD=7.75us
After conversion automatically
Sampling begins immediately after last conversion completes
Sampling begins when SAMP bit is set
AD1CON1.ASAM = 0; //no automatic sampling
Configure AD modul
Industrial Embedded Systems
11. 11
Data output format
integer/fractional and signed/nonsigned
AD1CON1bits.FORM = 0b00; //integer
PIC put the result of the AD conversion in to a 16-bit register
ADC1BUF x
Enable the module
AD1CON1bits.ADON = 1; //turn on ADC
Configure AD modul
Industrial Embedded Systems
16. 16
#include <p24fj128ga010.h>
_CONFIG1( JTAGEN_OFF & FWDTEN_OFF )
_CONFIG2( POSCMOD_HS & FNOSC_PRI )
void initADC(); // AD inicializalo fv deklarálása
int main ( void )
{
initADC(); // call ADC init
TRISA = 0xFF00; // PORTA lower 8 bit output
LATA = 0x0000; // delete PORTA
while(1) //infinite loop
{
AD1CHSbits.CH0SA=5; //select AN5 (potentiometer)
AD1CON1bits.SAMP = 1; //Start sampling (we do not need Timer1)
while (!AD1CON1bits.DONE); //end of conversion
LATA=(ADC1BUF0>>2); //put the 10bit result to the 8 LED
} //end of infinit loop
} //end of main loop
Example 2 (automatic conversion)
Industrial Embedded Systems
18. 18
Priority level
IPC3bits.AD1IP
Flag
IFS0bits.AD1IF
Enable bit
IEC0bits.AD1IE
We can select, after how many samling/conversion
We can give after how many completion of sample/convert sequence an
interrupt occur
AD1CON2bits.SMPI
Interrupt function
void _ISR _ADC1Interrupt (void)
{
… //instruction
IFS0bits.AD1IF = 0; // delete ADC interrupt flag!!!
}
ADC interrupt
Industrial Embedded Systems
19. 19
#include <p24fj128ga010.h>
_CONFIG1( JTAGEN_OFF & FWDTEN_OFF )
_CONFIG2( POSCMOD_HS & FNOSC_PRI )
void initADC(); //declaration of ADC initialization
void _ISR _ADC1Interrupt (void); //declaration of interrupt function
int main ( void )
{
initADC(); // call ADC initialization
SRbits.IPL = 0; // priority level of processor
IPC3bits.AD1IP = 3; //priority level of ADC
IEC0bits.AD1IE = 1; //enable ADC interrupt
TRISA = 0xFF00; // PORTA lower 8 bit output
LATA = 0x0000; // delete PORTA
AD1CHSbits.CH0SA=5; //select AN5 (potentiometer)
AD1CON1bits.SAMP = 1; //Start sampling (we do not need Timer1)
while(1); //infinite loop
}
Example 3 (automatic conversion + interrupt)
Industrial Embedded Systems
20. 20
void _ISR _ADC1Interrupt (void)
{
LATA=(ADC1BUF0>>2); //instruction: put the result to the LED
IFS0bits.AD1IF = 0; //delete ADC interrupt flag
}
void initADC() // define of ADC initialization
{
AD1PCFG = 0xFFDF; // enable AN5 chnnel
AD1CON1bits.SSRC = 0b111; //automatic conversion
AD1CON1bits.FORM = 0b00; //integer
AD1CON1bits.ASAM = 1; //after conversion automatically new sampling
AD1CON2bits.VCFG = 0b000; // ref+=VDD, ref-=VSS
AD1CON3bits.ADRC = 0; //system clock, TCY=2*TOSC
AD1CON2bits.SMPI = 8; //interrupt after 8 sampling/conversion
AD1CON3bits.ADCS = 0; //TAD=TCY=250ns>75ns
AD1CON3bits.SAMC = 31; //Tsamp=31TAD
AD1CON1bits.ADON = 1; //turn on ADC
}
Example 3 (automatic conversion + interrupt)
Industrial Embedded Systems
21. 21
To read multiple channel the „scan” instruction can be helpful, which put
the ADC value in different ADC1BUFx register
To turn on scan:
AD1CON2bits.CSCNA = 1;
The required channels should be enabled in the AD1PCFG register
In the AD1CSSL register we have to give the channels
pl. AD1CSSL = 0x0030; //AN4 és AN5
If we want to read the value of n channel, it is worth to make an interrupt
after n sampling/conversion sequence
pl. AD1CON2bits.SMPI = 0b0001; //2 channels
Read the value of the channels
pl. value01 = ADC1BUF0; //AN4
value02 = ADC1BUF1; //AN5
PIC fill up the ADC1BUFx register from x=0
Read multiple channel
Industrial Embedded Systems
22. 22
void initADC()
{
AD1PCFG=0xFFCF; //AN4 and AN5
AD1CON1bits.SSRC = 0b111; //automatic conversion
AD1CON1bits.FORM = 0b00; //integer
AD1CON1bits.ASAM = 1; //new sampling after conversion
AD1CON2bits.VCFG = 0b000; //ref+=VDD, ref-=VSS
AD1CON2bits.SMPI = 2; //interrupt after 2 AD conversion
AD1CON2bits.CSCNA = 1; //scan
AD1CON3bits.ADRC = 0; //TCY=2*TOSC
AD1CON3bits.ADCS = 0; //TAD=TCY=250ns>75ns
AD1CON3bits.SAMC = 31; //Tsamp=31TAD
AD1CON1bits.ADON = 1; //ADC turn on
AD1CSSLbits.CSSL4=1; //include AN4 in the scan cycle
AD1CSSLbits.CSSL5=1; //include AN5 in the scan cycle
}
Example 4 (read multiple channel)
Industrial Embedded Systems
23. 23
Read the actual value of the temperature sensor and the poteniometer and
write their value in Celsius and Volt to the LCD display
Industrial Embedded Systems
Example 4 (read multiple channel)
void LCDFloat(float L,int length, unsigned int acc)
{
signed int intpart=(int) L;
if (intpart==0)
LCDNumber(intpart,1);
else
LCDNumber(intpart,-1);
putLCD('.');
int fraction, multi=1;
while(acc--)
{
multi*=10;
if(intpart>=0) //if positive
{
fraction=(L-(int)L)*multi;
}
else fraction=((int)L - L)*multi; //if negative
LCDNumber(fraction,1);
}
}
24. 24
ADC of dsPICs
Up to 32 ADC input channel (100/121/144 pin device)
10-bit ADC with four S&H block (simultaneous sampling, 1.1 Msps)
12-bit ADC with one S&H block (500 ksps)
DMA (Direct Memory Access) can be used
DMA is an efficient mechanism of copying data between
peripheral SFRs and buffers or variables stored in RAM with
minimal CPU intervention
If multiple conversions are done without DMA 16 registers named
ADCxBUF0-15 can be used for buffering the results and the ADC
interrupt is used to signal when a group of conversions is finished
By using DMA, these registers are not present and DMA memory
is used to buffer the results and the DMA interrupt occuring when
a group of conversions has finished
Using dsPIC with DMA
Industrial Embedded Systems
25. 25
DMA block diagram in dsPIC
Industrial Embedded Systems
CPU communicates with conventional SRAM across the data space X-bus (modified
Hardvard architecture). It also communicates to port 1 of the dual port SRAM. It talks to
the peripherals acrosss a separate peripheral data space bus
DMA communicates with port 2 of the dual port SRAM and the DMA port of each of the
DMA-ready peripheral across a dedicated transfer bus
27. 27
Operating modes
Industrial Embedded Systems
Moves a single block of data from a fixed (peripheral) address
Alert CPU that the block is ready for processing
One-shot mode
28. 28
Operating modes
Industrial Embedded Systems
Moves multiple blocks of data to/from a fixed (peripheral) address
Alert CPU that each block is ready for processing
Automatically re-initializes DMA channel for the next block transfer
Suitable for applications when CPU can stay ahead of CPU
Auto-repeat mode
29. 29
Operating modes
Industrial Embedded Systems
Alerts CPUwhen each block is half way through its total count
Allows CPU time to start processing the buffer before it is overwritten
Requires that the DMA data transfers stay ahead of CPU processing of
the buffer
Half Buffer transfer interrupt
30. 30
Operating modes
Industrial Embedded Systems
Moves multiple blocks of data to/from a fixed (peripheral) address
Alert CPU that each block is ready for processing
Automatically re-initializes DMA channel for next block transfer to an
alternate buffer (ping-pongs between 2 buffers)
Allows CPU to process one buffer while the other fills/empties
Ping-Pong
31. 31
Adressing mode
Industrial Embedded Systems
Conventioanl DMA transfer moves the data into a sequential buffer
The peripheral provides the address of DPSRAM address, the task of the
DMA to coordinate the data transfer and generate the CPU interrupts
Scatter-gather addressing mode
PIA: Peripheral indirect addressing mode
32. 32
The presence of DMA requires the following:
The ADC ISR (Interupt Service Routine) is no longer used. Now the
ADC interrupt occurs adter each conversion, at point the DMA
module transfers the results to a DMA buffer. The DMA interrupt is
used to do something with the ADC samples
The DMA channel must be configured to be linked to the ADC module
and a buffer in DMA memory allocated for the ADC results
There are two choices for storing the ADC results in DMA memory
Conversion order
Scatter/gather mode
DMA
Industrial Embedded Systems
33. 33
Configure oscillator of the dsPIC
Industrial Embedded Systems
Example 5 (ADC with DMA)
// Configure Oscillator to operate the device at 40Mhz
// Fosc= Fin*M/(N1*N2), Fcy=Fosc/2
// Fosc= 8M*40/(2*2)=80Mhz for 8M input clock
PLLFBD=38; // M=40
CLKDIVbits.PLLPOST=0; // N1=2
CLKDIVbits.PLLPRE=0; // N2=2
OSCTUN=0; // Tune FRC oscillator, if FRC is used
// Disable Watch Dog Timer
RCONbits.SWDTEN=0;
// Clock switch to incorporate PLL
__builtin_write_OSCCONH(0x03); // Initiate Clock Switch to Primary
// Oscillator with PLL (NOSC=0b011)
__builtin_write_OSCCONL(0x01); // Start clock switching
while (OSCCONbits.COSC != 0b011); // Wait for Clock switch to occur
// Wait for PLL to lock
while(OSCCONbits.LOCK!=1) {};
34. 34
Initialize ADC
Industrial Embedded Systems
Example 5 (ADC with DMA)
void initADC(void)
{
AD1CON1bits.FORM = 0; // integer
AD1CON1bits.SSRC = 2; // Timer3 as sample clock source
AD1CON1bits.ASAM = 1; //auto sampling
AD1CON1bits.AD12B = 0; // 10-bit ADC operation
AD1CON1bits.SIMSAM = 1; //Simultaneous sampling
AD1CON2bits.CSCNA = 1; // Scan Inputs
AD1CON2bits.CHPS = 0;
AD1CON3bits.ADRC = 0; // ADC Clock is derived from Systems Clock
AD1CON3bits.ADCS = 63; // Tad=Tcy*(ADCS+1)= (1/40M)*64 = 1.6us (625Khz)
// ADC Conversion Time for 10-bit Tc=12*Tab = 19.2us
AD1CON1bits.ADDMABM = 0; //scatter/gather mode
AD1CON2bits.SMPI = 3; // 4 ADC Channel is scanned
AD1CON4bits.DMABL = 0b011; // Each buffer contains 8 words
AD1CSSH = 0x0000; //no scan for AN16-31
AD1CSSLbits.CSS4=1; // AN4 for scan
AD1CSSLbits.CSS5=1; // AN5 for scan
AD1CSSLbits.CSS10=1; // AN10 for scan
AD1CSSLbits.CSS13=1; // AN13 for scan
35. 35
Initialize ADC
Industrial Embedded Systems
Example 5 (ADC with DMA)
//AD1PCFGH/AD1PCFGL: Port Configuration Register
AD1PCFGL=0xFFFF;
AD1PCFGH=0xFFFF;
AD1PCFGLbits.PCFG4 = 0; // AN4 analog input
AD1PCFGLbits.PCFG5 = 0; // AN5 analog input
AD1PCFGLbits.PCFG10 = 0; // AN10 analog input
AD1PCFGLbits.PCFG13 = 0; // AN13 analog input
IFS0bits.AD1IF = 0; // Clear the A/D interrupt flag bit
IEC0bits.AD1IE = 0; // Do Not Enable A/D interrupt
AD1CON1bits.ADON = 1; // Turn on the A/D converter
}
36. 36
Initialize DMA
Industrial Embedded Systems
Example 5 (ADC with DMA)
void initDMA(void)
{
DMA0CONbits.AMODE = 0b10; // Peripheral indirect addressing mode
DMA0CONbits.MODE = 0b10; //Continuous Ping-Pong mode
DMA0PAD=(int)&ADC1BUF0; //contains the static address of the peripheral data register
DMA0CNT = 31; //8*4-1, the block transfer complete
DMA0REQ = 13; // Select ADC1 as DMA Request source
DMA0STA = __builtin_dmaoffset(BufferA);
DMA0STB = __builtin_dmaoffset(BufferB);
IFS0bits.DMA0IF = 0; //Clear the DMA interrupt flag bit
IEC0bits.DMA0IE = 1; //Set the DMA interrupt enable bit
DMA0CONbits.CHEN=1; // Enable DMA
}
37. 37
Locate buffer for DMA
Industrial Embedded Systems
Example 5 (ADC with DMA)
#define MAX_CHNUM 13 // Highest Analog input number (AN4,AN5,AN10,AN13)
#define SAMP_BUFF_SIZE 8 //size of input buffer/channel
#define NUM_CHS2SCAN 4 //Number of channels
// Number of locations for ADC buffer = 14 x 8 = 112 words
//The buffer should be aligned to 128 words or 256 bytes
int BufferA[MAX_CHNUM+1][SAMP_BUFF_SIZE] __attribute__((space(dma),aligned(256)));
int BufferB[MAX_CHNUM+1][SAMP_BUFF_SIZE] __attribute__((space(dma),aligned(256)));
38. 38
Interrupt function
Industrial Embedded Systems
Example 5 (ADC with DMA)
void __attribute__((interrupt, no_auto_psv)) _DMA0Interrupt(void)
{
if(DmaBuffer == 0)
{
// ProcessADCSamples(&BufferA[4][0]);
ProcessADCSamples(&BufferA[5][0]);
// ProcessADCSamples(&BufferA[10][0]);
// ProcessADCSamples(&BufferA[13][0]);
}
else
{
// ProcessADCSamples(&BufferB[4][0]);
ProcessADCSamples(&BufferB[5][0]);
// ProcessADCSamples(&BufferB[10][0]);
// ProcessADCSamples(&BufferB[13][0]);
}
DmaBuffer ^= 1;
IFS0bits.DMA0IF = 0; // Clear the DMA0 Interrupt Flag
}
39. 39
Singal processing function
Industrial Embedded Systems
Example 5 (ADC with DMA)
void ProcessADCSamples(int * AdcBuffer)
{
int a=0;
int i=0;
while(i<8)
{
a+=*AdcBuffer++; //simple averaging
i++;
}
LATA=a>>5; //divison by 4 to show the ten bit value on 8 leds and divison by 8 due to
the averaging
}