interrupt function with an A/D converter of a S12

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

interrupt function with an A/D converter of a S12

Jump to solution
3,238 Views
Delphine
Contributor I
Hello,
 
I am working on the configuration of the ATD0 of the M9S12DP256B and my problem is that I can't go through the interrupt function.
 
My program is described below:
 
#include <hidef.h>           /* common defines and macros */
#include <mc9s12dp256.h>     /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12dp256b"
//Le résultat de la conversion est mis dans la variable ATD0DR0
//Accessible en lecture uniquement donc on recupere sa valeur
//Resultat sur 16 bits
int V_16bits = 0x0000; 
 
 
//Initialisation des registres du convertisseur Analogique-Numerique
void Init_CAN() { 
   
 /*ATDCTL0 et ATDCTL1 sont reserves*/
 
 /*initialisation de ATDCTL2*/
 ATD0CTL2 = 0x82; 
 
 /*initialisation de ATDCTL3*/
 ATD0CTL3 = 0x08;   
 
 /*initialisation de ATDCTL4*/
 ATD0CTL4 = 0x00;   
 
 /*l'ecriture dans le registre ATDCTL5 commence la conversion*/
  ATD0CTL5 = 0x80;
 
}
  
//-----------------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------------
     
void main(void) {
 /* put your own code here */
 
 EnableInterrupts;
 
 Init_CAN();
  
  for(;:smileywink: { } /* wait forever */
 
}
 
//---------------------------------------------------------------------
//---------------------------------------------------------------------
 
//gestion de l'interruption de fin de capture du signal a convertir
#ifndef __SMALL__
#pragma CODE_SEG __NEAR_SEG NON_BANKED
#endif
 
interrupt 22 void interrupt_CAN() {    
    V_16bits = ATD0DR0;             
    ATD0STAT0_SCF = 1;  //conversion sequence has completed
 }
 
//---------------------------------------------------------------------
//---------------------------------------------------------------------
 
This program converts very well the analog voltage put in input.  
Could somebody help me to explain what is wrong in this problem to let me continue my project?
 
Thank you,
 
Delphine.
 
Labels (1)
Tags (1)
0 Kudos
1 Solution
638 Views
Blackwolf
Contributor III

Hello Delphine,

humm well... This issue may require some further investigations, but as starting line I would recommend you to check the following points:

1.) In the *.map file generated in the.\bin\ subfolder of your application, check that the interrupt routine is correctly placed in none banked memory

2.) in the *.map file check out the 'UNUSED_OBJECT' section and make sure that none of your variables/procedures were optimized

3.) I would recommend you to enable the interrupts 'after' the init routine...

On the other hand I would invite you to use Processor expert, the graphical code generator of Codewarrior to create an A/D driver as code sample.

hope this helps :smileywink:

Blackwolf

View solution in original post

0 Kudos
3 Replies
639 Views
Blackwolf
Contributor III

Hello Delphine,

humm well... This issue may require some further investigations, but as starting line I would recommend you to check the following points:

1.) In the *.map file generated in the.\bin\ subfolder of your application, check that the interrupt routine is correctly placed in none banked memory

2.) in the *.map file check out the 'UNUSED_OBJECT' section and make sure that none of your variables/procedures were optimized

3.) I would recommend you to enable the interrupts 'after' the init routine...

On the other hand I would invite you to use Processor expert, the graphical code generator of Codewarrior to create an A/D driver as code sample.

hope this helps :smileywink:

Blackwolf

0 Kudos
638 Views
Delphine
Contributor I
Thank you for your help...
 
In fact, the problem was that there was a mistake into the datasheet of the M9S12DP256B, concerning the functioning principle of the flag (ATD0STAT_SCF)used for an A/D conversion...
 
It 's incredible, isn't it?
 
Delphine.
0 Kudos
638 Views
petr
Contributor I
Hello
I would say that it is not exactly mistake in the datasheet, but a hardware bug. Check errata of this cpu.
Regards
Petr
0 Kudos