Advice for an adc on a MC9S08GB60A board

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

Advice for an adc on a MC9S08GB60A board

1,342 Views
Euan
Contributor I

Hi,

 

I am currently working with a MC9S08GB60A board and I want to take an analogue signal into the ADC, convert it into digital bits and then store it or somehow view the output. I am very new to this and have read the getting started pack and looked at some of the code out there but I do not understand it. I was wondering if anyone could suggest some code to do this action? I do have C knowledge but I do not understand how to program the chip and all the pins.

 

Any information or advice would be great.

 

Thanks for your time.

 

Euan

Labels (1)
0 Kudos
2 Replies

267 Views
J2MEJediMaster
Specialist I

Search these forums using the search feature (bottom left on this web page) , as this question has been brought up before. Here's a forum thread you can check for some information.

 

You may want to read the MCU specs to see what registers are involved in managing the ADC. That way the code you're looking at will make sense.

 

---Tom

0 Kudos

267 Views
Euan
Contributor I

Thanks Tom.

 

Using the links you gave me I tried to write my own code. It does compile however I still have a few questions.

 

1. Is it as simple as changing the output pin if I want to output the data out of the serial port?

2. I can't find the result from the ADC, hence ? in my code, does anyone have any ideas where I can find it?

3. Is there a way I can get the program to show me what it is doing or will connecting oscilloscope to the pins I have predefined show me what is happening?

4. And finally will this work?! Haha 

 

 

#include <hidef.h> /*for EnableInterrupts macro*/
#include "derivative.h" /*include peripheral declarations*/
#include <stdio.h>
#include <MC9S08GB60A.h>

#define OUT PTBD_PTBD0 /*Define pin PTB0 as output*/
#define IN PTBD_PTBD7 /*Define pin PTB7 as input*/

void main(void) {

  EnableInterrupts; /*Enable Interrupts*/
 
  for(; ; ) {
    __RESET_WATCHDOG(); /* feeds the dog */
    PTBD_PTBD7 = ATD1SC_ATDCH; /*Creates input to ADC*/
    ATD1SC_ATDCO; /*Enables continuous conversion*/
    ATD1C_PRS3_MASK; /*Mask three makes the ADC a 8 bit convertor*/
   
    while (!ATD1SC_CCF){  /*Keeps looping until ADC conversion is complete*/
  
    PTBD_PTBD0 = ? ;     /* Outputs 8bit ADC to pin PTB0*/
    }
  } /* loop forever */
  /* please make sure that you never leave main */
}

 

Thanks in advance!

 

Euan

0 Kudos