Ryan Andrews

ADC trouble MC9S08QG8

Discussion created by Ryan Andrews on Mar 31, 2009
Latest reply on Apr 4, 2009 by Davide Munari

Hi there, Im a junior who is doing a project where i am doing some uP work with the MC9S08QG8 and anaccelerometer. For the first part of the project, the accelerometer must be displayed on the 8 bits of PortB. The rest of my class is using assembly and i am using C so i cant get much help. I am having trouble getting the A/D to work right and was wondering if someone could give me some help.

 

Here is my code:

 

#include <hidef.h> /* for EnableInterrupts macro */
#include <MC9S08QG8.h> /* include peripheral declarations */

/*define outputs*/
#define out1 PTBD_PTBD0
#define out2 PTBD_PTBD1
#define out3 PTBD_PTBD2
#define out4 PTBD_PTBD3
#define out5 PTBD_PTBD4
#define out6 PTBD_PTBD5
#define out7 PTBD_PTBD6
#define out8 PTBD_PTBD7


void main(void) {
EnableInterrupts; /* enable interrupts */

PTADD = 0x00; //initialize as input

PTBDD = 0xff; // make port b output
PTBPE = 0xff; //Pullups on output

for(;:smileywink: {
 
__RESET_WATCHDOG(); /* kicks the dog */

 
ADCSC1_ADCO = 1; // enable continuous conversion
ADCCFG_MODE = 0x00; // 8 bit mode
ADCSC1_ADCH = 0x00;       // set channel 00 = PTA0 with Acc
  while(ADCSC2_ADACT);
  while(!ADCSC1_COCO);      // ADC conversion complete?
 
PTBD = ADCRL; // output 8bit ADC to Port B

 
 } /* loop forever */
}

 

 

Thanks for your help

Outcomes