Welcome To Turbofuture!: Internet Computers Cell Phones Consumer Electronics
Welcome To Turbofuture!: Internet Computers Cell Phones Consumer Electronics
Welcome to TurboFuture!
Welcome to TurboFuture!
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
DEC 28, 2020
The author completed his final year engineering project with the dsPic micro-
controllers, gaining extensive insight in these devices.
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
dsPic30f4011 micro-controller along with its programmer.
Own work
This tutorial is aimed at teaching the basics of A/D conversion modules to all
those who are beginning their projects with the dsPics.
Sampling a DC Signal
For initial testing, you may use a potentiometer connected across a 5 V supply
and give input to the ADC analogue pins directly.
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
To sample an AC signal (line voltages or currents), you will have to:
1. Step down the signal to the required voltage level with the help of
transformers.
2. Level-shift the signal so that negative values below zero are shifted up. The
ADCs in Pics are not able to sample negative signals.
This reference circuit design may help you with the level shifting circuits:
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Sampling an AC signal with ADC. (Gain of Op-amp may be tuned through the variable
resistor to achieve an output in the range of 0 - 5V, I however use a value of 2.7 kOhms
in its place.)(Click to enlarge).
Own Work
1. You can connect a debugger with the Pic like the one pictured above. In
debug mode, you can check the value in registers ADCBUF0 through 10 to
INTERNET COMPUTERS CELL PHONES
see if they are being loaded with correctly sampled values.
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
2. You can send the values of ADCBUF register thorough UART and monitor
them on a PC with the help of serial monitor.
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
//__delay_ms( 100 );
ADCON1bits.SAMP = 0; // start sampling, automatic
conversion will follow
while ( !ADCON1bits.DONE ); // wait to complete the
conversion
ADCValue = ADCBUF0; // read the conversion result
}
void main( void )
{
init_ADC();
int data;
while( 1 )
{
readADC();
data = ADCValue;
}
}
Steps 1 through 7 are essential. After 7, any or all of them may be skipped.
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
1. Port B, on which the ADC input pins are present, must be set as an input
port. (line - 21).
2. They must be set in the analogue input mode by the ADPCFG register. (line -
22).
Here AN1 is selected as the analogue pin input to channel 0. (line - 2).
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Possible
Resulting Analouge Input Pin
Configurations Code Line
Configuration
of ADCHS
Selecting different combinations of ADC analogue inputs and channels for dspic30f
devices.
(dspic33f devices may have more channels and inputs available)
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
A voltage reference must be selected to match the input range of the
analogue inputs. There are two options for this:
1. The Vcc and Gnd can be made upper and lower reference limits.
This is done with the help of VCFG bit in the ADCON2 register. (line - 47)
0 AVdd AVss
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
below:
0 integer
1 signed integer
2 fractional
3 signed fractional
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
SSRC Conversion Trigger Source
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
This is decided by the ASAM bit in ADCON1 register.
ASAM Mode
The minimumINTERNET
value of Tad that can be used is
COMPUTERS 154 nanoseconds.
CELL PHONES
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
8. Decide if Simultaneous Sampling
Is Required or Not (Optional)
Simultaneous sampling can be enabled by the SIMSAM bit in the ADCON1
register. Simultaneous sampling captures the samples of all input channels at
precisely the same instant. If Simultaneous sampling is disabled, the channels
will be sampled one after the other.
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Channel 0 of the ADC module can be configured to scan multiple analogue
inputs. This can be used if their are multiple input sources and not all of them
are active at the same time.
For more information on interrupts refer to this detailed tutorial: How to Use
INTERNET COMPUTERS CELL PHONES
Interrupts in Pic MicroControllers
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Interrupt Based Code for ADCs in
dspic30f and dspic33f
#define FCY 30000000
#include <xc.h>
#include <stdio.h>
#include <delay.h>
#include <libpic30.h>
#include <math.h>
#include <p30F4011.h>
_FOSC(CSW_FSCM_OFF & FRC_PLL16); // Fosc=16x7.5MHz, i.e. 30
MIPS
_FWDT(WDT_OFF); // Watchdog timer off
_FBORPOR(MCLR_DIS);
void Interrupt_Init( void )
{
IEC0bits.ADIE = 1; //Enable ADC Interrupt
IPC2bits.ADIP = 6; //set interrupt priority = 6
}
void __attribute__((interrupt, auto_psv))_ADCInterrupt (void)
{
while ( !ADCON1bits.DONE ); // wait to complete the
conversion
sample.Va = ADCBUF0;
sample.Vb = ADCBUF1;
IFS0bits.ADIF = 0;
}
int main( void )
{
// Make RD0 a digital output
_TRISD0 = 0;
Interrupt_Init();
ADC_Init();
while(INTERNET
1 ) COMPUTERS CELL PHONES
{
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
_LATD0 = 1;
__delay32(15000000);
_LATD0 = 0;
__delay32(15000000);
}
}
This article is accurate and true to the best of the author’s knowledge.
Content is for informational or entertainment purposes only and does not
substitute for personal counsel or professional advice in business, financial,
legal, or technical matters.
© 2017 StormsHalted
Comments
StormsHalted (author) from Karachi, Pakistan on May 08, 2020:
INTERNET COMPUTERS CELL PHONES
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
The code lines displayed in this article are tested to work, if you copy and
paste it, it will be the same as if I send you the code.
You might want to recheck the MCU model and its configuration bits. This one
is for dsPic30f4011.
Hello!
Could you explain a little bit about the code [ADCS = 9] (on "ADC Example
Code for dsPic") ?
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
In the comments, you said that the clock conversion is 6Tcy, but according to
the datasheet, Conversion time = (Tcy/2) * (ADCS + 1)..
So,
Am I wrong?
Thank you
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
You will have to disconnect and plugin pickit back. This type of issue is not
uncommon with pickit.
Hello,
BY STORMSHALTED
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Related Articles
COMPUTERS MISCELLANEOUS
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
How to Use Interrupts
in Pic and dsPic Code Optimization in
MicroControllers Microcontrollers
BY STORMSHALTED · DEC 29, 2020 BY STORMSHALTED · DEC 25, 2020
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
SOFTWARE & OPERATING SOFTWARE & OPERATING MISCELLANEOUS
SYSTEMS SYSTEMS
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
How to Convert PSD & C++ Program to
PSB to JPG in Estimate the Value of
Photoshop 'e' and e^x
BY STORMSHALTED · JAN 31, 2021 BY STORMSHALTED · JAN 20, 2021
COMPUTERS MISCELLANEOUS
SEE MORE
INTERNET COMPUTERS CELL PHONES
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Privacy Policy · Terms of Use · About Us · Editorial Policy
© 2021 Maven Media Brands, LLC and respective content providers on this website. Other product and company names shown may be
trademarks of their respective owners. Maven Media Brands, LLC and respective content providers to this website may receive compensation
for some links to products and services on this website.
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD