how to use the adc interrupt - MC68HC908MR

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

how to use the adc interrupt - MC68HC908MR

1,939 Views
quimey
Contributor I
hello micromans i need to use the adc interrupt but  is no working
this code would be to turn on the pta01 way do not work???
 
void init_adc(void){
 
ADSCR_ADCO=1;/*CONVERSION continua*/
ADSCR_ADCH0=1;/*ELIJO ATD1 PIN 63*/
ADSCR_ADCH1=0;
ADSCR_ADCH2=0;
ADSCR_ADCH3=0;
ADSCR_ADCH4=0;
ADCLK_ADIV2=1;/*ELIJO EL PRESCALER EN 8 PARA TENER APROX 0,5MHZ DE CLOCK DE ADC*/
ADCLK_ADIV1=0;/*8,9MHZ CRISTAL*/
ADCLK_ADIV0=0;
ADCLK_MODE1=0;/*ELIJO TRUNCAR A 8 BIT*/
ADCLK_MODE0=0;
ADSCR_AIEN=1;
}

void init_output(void){
DDRA=0b00000010;
}
 

interrupt 17 void lecturaadc(void)
{
  #pragma TRAP_PROC SAVE_REGS 
 ADC=ADRL;
 PTA_PTA1=1;     
}
 
 
Added p/n to subject


Message Edited by NLFSJ on 2009-01-26 09:26 AM
Labels (1)
0 Kudos
4 Replies

516 Views
Ake
Contributor II
Hi,
Which MCU are you using?
I looked but could not find any 9S08 with an ADC interrupt vector at 17.
 
Regards,
Ake
 
 
 
 
 
 
0 Kudos

516 Views
quimey
Contributor I
hi
I use the hc08 mr32 mcu
rewards
Quimey
 
0 Kudos

516 Views
Ake
Contributor II
Hi,
I tried it on an ICS08MR board and after some small changes, it seems to work.
 
Here is the code I have changed:
 
/******************************************************************
* InitADC - initialize the ADC
*
* Calling convention:
* InitADC()
*
* Returns: nothing
******************************************************************/
void InitADC(void) {
  ADSCR = 0;            //stop conversion
#if ADC_8BIT
  ADCLK = ADCLK_ADICLK_MASK; //internal bus clock/1, 8 bit result,        
#else
  ADCLK = ADCLK_ADICLK_MASK
         |ADCLK_MODE0_MASK; //internal bus clock/1, right justified 10 bit result                
                            //divide by 4, right justified       
#endif
        ADSCR_ADCH0=1;       //read ATD1 PIN 63
        ADSCR_ADCO=1;       //continous conversion
        ADCLK_ADIV2  = 1;   //divide input clock by 16
        ADSCR_AIEN = 1;      //enable the interrupts
};
 
/******************************************************************
* main - entry point to this program
*
* Calling convention:
* main()
*
* Returns: nothing
******************************************************************/
void main(void) {
        CONFIG_COPD = 1;   // turn off the COP

        InitIO();
        InitPLL();
       
        
        InitADC(); 
        EnableInterrupts; /* enable interrupts */
        for(;:smileywink: {
               asm nop;
                               
 } /* loop forever */
};
 
/******************************************************************
* Interrupt for the ADC
*
* Calling convention:
* lecturaadc()
*
* Returns: nothing
******************************************************************/
interrupt VectorNumber_ADC void lecturaadc(void)
{
 ADCresult = ADRL;      //get and store ADC result
 PTC_PTC2 ^= 1;     
}
 
I haven't checked the program but it seems to work. The PTC2 pin toggled at 4.8 kHz, which means that the interrupt was running at about every mS.
 
Regards,
Ake
0 Kudos

516 Views
denny_george
Contributor I
Hi Ake,
 
He seems to be using MC68HC908MR .
 
 
 
I need your help in solving my problem: "Bus clock independent code snippet"
 
 
 


Message Edited by Geo*** on 2009-01-16 01:44 PM
0 Kudos