Kirk Humphries

DEMO9S12XDT512 Interrupt Questions

Discussion created by Kirk Humphries Employee on Jan 27, 2006

This message contains an entire topic ported from a separate forum. The original message and all replies are in this single message. We have seeded this new forum with selected information that we expect will be of value to you as you search for answers to your questions.

 

Posted: Thu Dec 8, 2005  8:00 pm

 

Hello,

 

Does anybody know here how to work with A/D on the HC12 using C?

 

Thanks.

 


 

Posted: Thu Dec 8, 2005  10:44 pm

 

> Does anybody know here how to work with A/D on the HC12 using C?

 

Meee, I know how...

 


 

Posted: Fri Dec 9, 2005  9:54 am

 

May you please let me know how I can start it? on HCS12 (I'm using dragon12).

 

I look forward to hear from you.

 

Thanks.

 


 

Posted: Fri Dec 9, 2005  3:26 pm

 

Below the code I use for ADC. The processor I use is s12dp256, compiler ICC12 Pro version. Here, I use ADC0 for analog inputs, and ADC1 for digital inputs (s12dp256

owns 2 ADC).

 

Code:

// Init analog port : system convert each channel     ATD0CTL2 = 0xc0; // port analog 0 ON, ADPU + AFCC  ATD0CTL3 = 0x00; //  ATD0CTL4 = 0x65; // 10 bits, sample time 16 A/D ck, clock prescaler 5  ATD0CTL5 = 0x30; // left, unsigned, Scan, multiples conversion  ATD0DIEN = 0x00; // enable analog inputs     ATD1CTL2 = 0x00; // port analog 1 digital  ATD1DIEN = 0xff; // port analog 1, 8 digital inputs           // Reading analog inputs in a 8 elements tab  void DBLE_ReadTabAnalog (char *t)  { *t = ATD0DR0H;  t++;  *t = ATD0DR1H;  t++;  *t = ATD0DR2H;  t++;  *t = ATD0DR3H;  t++;  *t = ATD0DR4H;  t++;  *t = ATD0DR5H;  t++;  *t = ATD0DR6H;  t++;  *t = ATD0DR7H;  }



 

Hope that help you.

 


 

Posted: Fri Dec 9, 2005  7:06 pm

 

Joel thanks indeed. It was a big help. I also need to know what value should be compared with the input.

 

Any idea? i'm a new one in embedded field and thinking there must be a table or reference which tells us what value i have to compare it with.

 

i hope it makes sense.

 


 

Posted: Sat Dec 10, 2005  3:55 am

 

interesting!!!!

 

i was told that i shouldn't use ad0 since it is for d-bug12. how can i get more information on this?!!

 

thanks indeed.

 


 

Posted: Fri Dec 9, 2005  5:38 pm

 

> May you please let me know how I can start it? on HCS12 (I'm using

> dragon12).

 

Do you mean you don't have a C environment? Since Dragon12 comes with

AsmIDE from Eric Engler, you might like this:

 

http://www.ericengler.com/EmbeddedGNU.aspx

 


 

Posted: Fri Dec 9, 2005  6:58 pm

 

hi,

 

no. I have downloaded the IDE. What I meant was how I can make it work. I was trying to capture some input analog from a battery but it didn't work. What I'm confused about is if there is any reference or table which let a programmer to know what the input must be compared with.

 

let's say the HC12 is capturing an voltage on pin 6 of the A/D. What value I should consider to compare with?

 

thanks.

 


 

Posted: Fri Dec 9, 2005  9:34 pm

 

> let's say the HC12 is capturing an voltage on pin 6 of the A/D. What value I should

> consider to compare with?

 

Assuming you really do have it working, it is simply a ratio comparing with the reference VRL and VRH. Typically VRL is 0 V and VRH is 5 V (the regulator on Dragon12).

 

So if you read a 10-bit value, then 0x3ff means +5 V.

 

In general, I find the volts per count (resolution):

 

res = 1 / (2^10 - 1)

 

Then to read an input:

 

volts = res * readval

 

You might need some more details about finding readval, depending on how you have set it up and how much you know.

 

I do wonder what IDE you are using. Could be EmbeddedGNU, CodeWarrior, etc. It will be important to know what compiler if it is still not working.

 


 

Posted: Sat Dec 10, 2005  3:52 am

 

i appreciate your great help. currently i'm using the free one (EmbeddedGNU) does it really matter?!!!

 

regards,

Outcomes