Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PIC16F877a ADC C coding using MPLAB

Status
Not open for further replies.

andyan02

Newbie level 2
Joined
Apr 10, 2010
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
malaysia
Activity points
1,294
i have 6 Force Sensitive Resistor and i am currently using pic16f877a. the FSR produces an analog signal which needs to be converted to digital signal using the pic.. im new to c programming as i am not majoring in programming.. i was wondering does anyone have the coding for the ADC. the pic have 8 port and i only need to use 6. i am using a 20 MHz crystal oscillator. some reference would be such a great help as i need to present it in a week time.
 

well, which programming language do you use?

did you search in the board and google for that?
 

andyan02 said:
im using c language.

Find Examples in Internet. it is very easy to write .

Added after 30 minutes:

Here my code
But comments in Russian
I am lazy to translate them :)))


// Микроконтроллер PIC18F4620
// Частота внешнего кварца = 40 МГц (Fcy = Fosc / 4 = 10 МГц - одна инструкция выполняется за 0.1 мкс)


// Настройка АЦП (13 аналоговых входов)

// Tad(min) = 0.7 мкс
// правое выравнивание (ADFM = 1), VCFG1 = Vss, VCFG0 = Vdd
// Fosc/32 -> Tad = 0.8 мкс, Tacq = 8*Tad = 6.4 мкс
// 0000-канал RA0, 0 - состояние ожидания, модуль АЦП выключен

// Tcy = 4*Tosc
// 32*Tosc = 16*0.5*Tcy (визуальный инициализатор не запоминает !?)

ADCON0bits.ADON = 1; // Включаем АЦП-модуль


// ------------------------------------------------------------------ //
unsigned int Read_Data_From_ADC (unsigned char uc_Channel_Number) // считывание данных с аналоговых каналов
{
// Результат преобразования - 10 битный, правое выравнивание
// Tacq = 11.5 мкс (для заряда конденсатора модуля АЦП), Tad(min) = 1.6 мкс, Tad = 2 мкс
// Tпреобразования = 11*Tad, 2*Tad - перед началом след. преобразования

uc_Channel_Number <<= 2; // shift left 2 times

ADCON0 &= 0b11000011;
ADCON0 |= Channel_Number_uc;


// Wait 15 mks

uc_i = 15;

do
{
Nop();
Nop();
}
while (--uc_i);

ADCON0bits.GO_DONE = 1;
while (ADCON0bits.GO_DONE); // ожидаем сброса GODONE (~20 мкс)

return (ADRESH << 8) | ADRESL; // результат АЦП 10-битный // not smile but ( << eight)

}
// ------------------------------------------------------------------ //
 

For PIC16F use:

GODONE = 1;
while (GODONE);
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top