Problems with ATD ch7 conversion -  HCS12C32

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Problems with ATD ch7 conversion -  HCS12C32

3,964 次查看
StefX2
Contributor I

        Hello,

I want to make a conversion using the 7th channel but it will not work, please tell me what is wrong. It works fine using ch 0 :


 ATDCTL2 = 0x80;          
 ATDCTL3 = 0x08; 
 ATDCTL4_SRES8=1;
 
 ATDCTL3_S4C=0;
 ATDCTL3_S2C=0;    
 ATDCTL3_S1C=1;
 
 ATDCTL4_SMP1=0;
 ATDCTL4_SMP0=0;
 
 ATDCTL4_PRS0=0;/
 ATDCTL4_PRS1=0;
 ATDCTL4_PRS2=0;
 ATDCTL4_PRS3=0;
 ATDCTL4_PRS4=0;
 
 
 
 ATDCTL5_SCAN = 1;             
 ATDCTL5_MULT=0;
 
 ATDCTL5_CA=1; 
 ATDCTL5_CB=1;
 ATDCTL5_CC=1;

x=ATDDR7H;
     PORTB=x; //the LED's from PORTB should start blinking

x- never changes it's value (it is always 0). The same in the the debugger: x=0......:smileysad:

If I select channel 0, it works fine, the LED's are blinking..x changes it's value.
I would use ch0, but it is ocupied by a potentiometer .

Thank you

 

 

 

 

Added p/n to subject.




Message Edited by NLFSJ on 2008-01-29 03:31 PM
标签 (1)
0 项奖励
回复
9 回复数

1,861 次查看
JimDon
Senior Contributor III
As the risk of stating the obvious, what is connected to that input?

0 项奖励
回复

1,861 次查看
StefX2
Contributor I
To ch7 there is connected the output of a g-sensor(also made by freescale). The sensor is power suplied  by the uC's testboard. The only thing missing is a cappacitor which connected between the ground and the sensor's output. But I don't think that could affect the conversion in such an ugly way.


Message Edited by StefX2 on 2008-01-27 07:26 PM
0 项奖励
回复

1,861 次查看
JimDon
Senior Contributor III
Ok, what processor chip is it?

Are you sure that the sleep pin on the accelerometer chip is pulled high?

Also, create a dummy (test) project and use Processor Expert to generate some test code.

It can generate an interrupt driven channel scanner that is prettry cool, since you will need to read at least three channels.


0 项奖励
回复

1,861 次查看
StefX2
Contributor I
   
The chip is an: HCS12C32, on a Softec development board.
The sensor is working fine. If I use a regular voltmeter I can clearly see it working very fine(with voltage rnaging from 1.5V-3V.

I'll try with the Processor Expert..allthough I never used it :smileyhappy: .

The code I have written, does it look OK?
0 项奖励
回复

1,861 次查看
JimDon
Senior Contributor III
Well, there are al lot factors, so it would be best if you do it.

You need the interrupt driven mulit-channel set-up any way - you have 3 axis and a pot to read.

Create the test project,  then in the bean selector go to CPU Internal Peripherals/Converter/ADC
There is a control with +/- to add channels.
Then it is just a matter of fill in the form.  Any thing with a red ! needs to be changed.
Then on the processor expert menu, click generate code.
There will be a file AD1.c you also need the code in vectors.c. If you already have a vector table, just add the one you need. If not just cut and paste the vectors.
It's pretty easy, and then when you need other peripherals  set up you know how.
There are three functions you need:

byte AD1_Measure(bool WaitForResult)  - Call this to start a mesurement
byte AD1_GetValue16(word *Values) - Call this with an array the size of the number of channels. It will return 0 when done.
void AD1_Init(void) - Call this before using
ISR(AD1_Interrupt) - this is the interrupt vector.

You also need these:
#define ERR_BUSY         8             /* Device is busy. */
#define ERR_OK           0             /* OK */

I usually also look up the register in the spec to figure out how it is  done.
0 项奖励
回复

1,861 次查看
StefX2
Contributor I
      
Ok..I think I know what I have to do. Thank you a lot!

Stefan
0 项奖励
回复

1,861 次查看
StefX2
Contributor I
    ....I had no success..... :smileysad:   I have no ideea what the problem might be.

Does anybody have a pice of code(the init. of the ADC) which workes for sure(tested)?

Stefan
0 项奖励
回复

1,861 次查看
JimDon
Senior Contributor III
 This works for sure on a Dx (DP,DG,DT, ect) 256.

Code:
//===============================================================================// ADC// Dragons have a pot on channel 7. We use// this for controlling the brightness of the 7-seg LEDs.//=============================================================================== // ADC Defines.#define MULTI_MODE    0x10#define SINGLE_MODE   0#define SCAN_MODE     0x20#define NO_SCAN_MODE 0#define POT_CHANNEL_NUM   0x7  // reading input from AN07#define SCF           0x80      //Sequence Complete Flag in ATD0STAT0byte ADTValue;//===============================================================================// Trigger Read, wait, then read a channel and return 8-bit value..//===============================================================================byte ReadADC(byte channel) {  byte status;  // This resets the conversion done flag and starts a new conversion.  ATD0CTL5 = SINGLE_MODE+NO_SCAN_MODE+channel;    for (;;)   {     status = ATD0STAT0;     if( status & SCF )       break;  }    status = ATD0DR7H;     // Just the hi byte. Ignore LSB's  ADTValue = status;    return status; }

// Init code - put in main.
  // ATD block set up.
  ATD0CTL2 = 0x80;      // Enable power up mode for ADC Block
  ATD0CTL3 = 0x40;      // Set 8 bit conversions.
   
  // Set the enable digital input for the switches SW1-SW4
  ATD0DIEN  = 0xff;





Message Edited by JimDon on 2008-01-29 10:49 AM

Message Edited by JimDon on 2008-01-29 10:50 AM
0 项奖励
回复

1,861 次查看
StefX2
Contributor I
       It is working! Taking a look at your software helped me find the error in mine.

    Thank you!
0 项奖励
回复