MC68HC11A8-ADC
The project is based on Motorola Microcontroller. The data base is intended to
show how to work with ADC module of M68HC11A8. An arrangement of
variable resistor and a DC voltage source is used as analog input. The analog voltage
value from the potentiometer is given to Port E (0), channel 0 of ADC
module. The peripheral is configured to use system clock, continuous single
channel conversion in channel 0, by placing appropriate value in ADC
control register - ADCTL. CCF flag bit in ADCTL goes high on
completion of conversion.
Corresponding digital value of analog input will be available in ADC
result register, ADR1, when CCF (7th bit of ADCTL) goes
high. For next conversion, CCF flag has to be reset. This can be done by
performing a write operation with ADCTL register. The converted value is copied Port B, which can be observed
with waveform viewer.
The program includes a general purpose ADC configuration function (initADC ())
and associated definitions for initializing ADC.
The source code written in C language and can be viewed from the
code editor window.
It can be compiled after making any modifications (editing) and also
debugged during simulation. ORTS.h"
The program is as shown:
#include "Test_PORTS.h"
#define CONT_M 0x30 //continuous conversion with multiple channelse LIM_M 0x10 //limited (4) conversion with multiple channels
#define LIM_S 0x00 //limited (4) conversion with single channel
#define RC 0xc0 //Use internal RC clock
#define E 0x80 //use external E clock
#define CH0 0x00 //Select Channel 0
#define CH1 0x01 //Select Channel 1
#define CH2 0x02 //Select Channel 2
#define CH3 0x03 //Select Channel 3
#define CH4 0x04 //Select Channel 4
#define CH5 0x05 //Select Channel 5
#define CH6 0x06 //Select Channel 6
#define CH7 0x07 //Select Channel 7
char config[] __attribute__((section(".config"))) =
{
NOSEC | NOCOP | ROMON | EEON
};
void initADC(uint8, uint8, uint8);
int main()
{
lock();
PIOC |= HNDS;
while(1)
{
initADC(CONT_S, E, CH0);
while (!(ADCTL && 128));
PORTB = ADR1;
}
unlock();
return(0);
}
void initADC(uint8 m, uint8 clk, uint8 ch)
{
OPTION |= clk;
ADCTL = m|ch;
}
The source code in the
code editor window
has to be
compiled
after making any modifications
(editing).
Also the code can be
debugged
during
simulation.