ADC code for MC9S08QG8, please help

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

ADC code for MC9S08QG8, please help

1,352 Views
Magic86
Contributor I

Hi there. I have a demo board for MC9S08QG8, its not an official one. Anyway it has a potentiometer connected to channel 0 PTA0.

All Im trying to do is output the adc value to 8 lights connected to port B. Can you please correct my code? Im using interrupts to read the data after the conversion is completed:

 

 

 

 

<code>

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

#include "derivative.h" /* include peripheral declarations */


void adcISR(void);

volatile unsigned char result;



 

void main(void) {



  EnableInterrupts; /* enable interrupts */

  SOPT1_COPE=0;

  

  

  ADCSC1=0x40; //interrupst enable, one conversion, input channel 0

  ADCSC2=0x00; //software trigger, no comparison

  

  APCTL1=0x01;  //pin AD0 I/O disabled

  ADCCFG=0x90;   //low power, bus clock, long sample, 8bit mode

  

  

  PTBDD=0xFF;    //Set port b as output

  

  PTBPE=0x00;    //pull-up resistors

  

  



  for(;:smileywink:;

  

}


  

  interrupt 19 void adcISR(void) {

 

  PTBD=ADCRL; // read the ADC result and put it onto port B

 

  

  

  return;

  }

  

  

      

    

  

 </code> 

 

Thank you in advance.

Labels (1)
0 Kudos
Reply
1 Reply

451 Views
bigmac
Specialist III

Hello,

 

You do not say what specific problem you are experiencing.

 

However, keep in mind that the ADC conversion is started by a write to ADSC1 register.  Therefore the other ADC registers require to be initialised prior to starting the conversion.  The ADSC1 register should be the last one to be written.

 

This does not currently seem to be the case, so the result of the first (and only) conversion is likely to be incorrect.

 

Regards,

Mac

 

0 Kudos
Reply