Join our technical discussions about Freescale Microcontrollers: M68HC12. (Freescale Semiconductor is a Subsidiary of Motorola).
|
I would like some help in putting together some C Code to set-up and read one ADC Channel continuously and also set-up and Scan through multiple ADC channels continuously. I have Codewarrior for HCS12.Some help would be appreciated as I am a newcommer to embedded. |
|
|
|
In a message dated 9/10/02 10:00:57 AM Eastern Daylight Time, writes: > I would like some help in putting together some C Code to set-up and > read one ADC Channel continuously and also set-up and Scan through > multiple ADC channels continuously. Example for icc12 and hc12a4.... hope its similar....... somewhere in a setup subroutine: ATDCTL2=0xc0; //atd enab ATDCTL4=0x07; //sample rate ATDCTL5=0x70; //continuous scan, multichannel, 8 ch and later in the program: //-------------------- void readads(void){ //read 8 ch of internal a/d into addat[] unsigned char i; unsigned int tmp; unsigned char bh,bl; volatile unsigned char *p; ATDCTL5=0x70; //init multichannel conv while((ATDSTAT & 0x80)==0){}; //wait for sequence finished p=&ADR0H; //point to ch 0 for(i=0; i < 8; i++){ bl=*p++; //lo byte bh=*p++; //hi byte tmp=((unsigned int)bh << 8) | bl; //form word addat[i]=tmp & 0x3ff; //save 10 bit value } } //-------------------- void showads(void){ //show 8 ch of internal a/d unsigned char i; printf("\n"); for(i=0; i<8; i++){ printf("%3d ",i); } printf("\n"); while(!kbhit()){ readads(); for(i=0; i < 8; i++){ printf("%04x ",addat[i]); } printf("\r"); } printf("\n"); } [Non-text portions of this message have been removed] |
|
|
|
Thanks for the help Bob, can you explain to me why line (ATDCTL5=0x70; //continuous scan, multichannel, 8 ch) has to be put in the setup section as well as the conversion section? Please excuse me as I am a hardware engineer who is trying to get to grips with this even though my "C" code ability is basic. My company have just bought metrowerks for HCS12, it has been thrown on my desk and I have been told to get to grips with it!!!! difficult as the £2000 package only comes with a flashing LED program and a CD Rom with 5000 pages of PDF files!, none of which actually contains any useful "C" software routines ( accessing ADC, SPI, CAN,I/O Frequency/Pulse counting)....help!! I am trying to write a series of routines that tests the basic functionality of a custom made Analogue board with ADC, programmable gain amplifiers, programmable offset all accessed by SPI. --- In 68HC12@y..., BobGardner@a... wrote: > In a message dated 9/10/02 10:00:57 AM Eastern Daylight Time, > toby.merridan@s... writes: > > I would like some help in putting together some C Code to set-up and > > read one ADC Channel continuously and also set-up and Scan through > > multiple ADC channels continuously. > > Example for icc12 and hc12a4.... hope its similar....... > > somewhere in a setup subroutine: > ATDCTL2=0xc0; //atd enab > ATDCTL4=0x07; //sample rate > ATDCTL5=0x70; //continuous scan, multichannel, 8 ch > > and later in the program: > //-------------------- > void readads(void){ > //read 8 ch of internal a/d into addat[] > unsigned char i; > unsigned int tmp; > unsigned char bh,bl; > volatile unsigned char *p; > > ATDCTL5=0x70; //init multichannel conv > while((ATDSTAT & 0x80)==0){}; //wait for sequence finished > p=&ADR0H; //point to ch 0 > for(i=0; i < 8; i++){ > bl=*p++; //lo byte > bh=*p++; //hi byte > tmp=((unsigned int)bh << 8) | bl; //form word > addat[i]=tmp & 0x3ff; //save 10 bit value > } > } > > //-------------------- > void showads(void){ > //show 8 ch of internal a/d > unsigned char i; > > printf("\n"); > for(i=0; i<8; i++){ > printf("%3d ",i); > } > printf("\n"); > while(!kbhit()){ > readads(); > for(i=0; i < 8; i++){ > printf("%04x ",addat[i]); > } > printf("\r"); > } > printf("\n"); > } > > > [Non-text portions of this message have been removed] |
|
|
|
In a message dated 9/12/02 4:20:45 AM Eastern Daylight Time, writes: > Bob, can you explain to me why line > (ATDCTL5=0x70; //continuous scan, multichannel, 8 ch) has to be put > in the setup section as well as the conversion section? That's proabably redundant. Very observant. Original idea was to have all 8 channels continuously convert.... had some prob with that, so I fell back to the version where I initiate conversion.... good luck with metroworks... this list is full of guys looking for docs and tutorials on metroworks... a few of them have conquereed it... I think they are renting themselves out as consultants now... I like the imagecraft compiler... its inexpensive and the guy that wrote it will actually answer your questions if you have any... [Non-text portions of this message have been removed] |
|
Have a look as well on http://e-www.motorola.com/index.html there are a lot of application notes with code around ADS/SPI/etc as well. Erich > -----Original Message----- > From: hellfire1272000 [mailto:] > Sent: Thursday, September 12, 2002 10:19 AM > To: > Subject: [68HC12] Re: ADC HCS12 DP256 > Thanks for the help Bob, can you explain to me why line > (ATDCTL5=0x70; //continuous scan, multichannel, 8 ch) has to be put > in the setup section as well as the conversion section? > > Please excuse me as I am a hardware engineer who is trying to get to > grips with this even though my "C" code ability is basic. > My company have just bought metrowerks for HCS12, it has been thrown > on my desk and I have been told to get to grips with it!!!! difficult > as the £2000 package only comes with a flashing LED program and a CD > Rom with 5000 pages of PDF files!, none of which actually contains > any useful "C" software routines ( accessing ADC, SPI, CAN,I/O > Frequency/Pulse counting)....help!! > > I am trying to write a series of routines that tests the basic > functionality of a custom made Analogue board with ADC, programmable > gain amplifiers, programmable offset all accessed by SPI. > --- In 68HC12@y..., BobGardner@a... wrote: > > In a message dated 9/10/02 10:00:57 AM Eastern Daylight Time, > > toby.merridan@s... writes: > > > > > > > I would like some help in putting together some C Code to set-up > and > > > read one ADC Channel continuously and also set-up and Scan > through > > > multiple ADC channels continuously. > > > > Example for icc12 and hc12a4.... hope its similar....... > > > > somewhere in a setup subroutine: > > ATDCTL2=0xc0; //atd enab > > ATDCTL4=0x07; //sample rate > > ATDCTL5=0x70; //continuous scan, multichannel, 8 ch > > > > and later in the program: > > //-------------------- > > void readads(void){ > > //read 8 ch of internal a/d into addat[] > > unsigned char i; > > unsigned int tmp; > > unsigned char bh,bl; > > volatile unsigned char *p; > > > > ATDCTL5=0x70; //init multichannel conv > > while((ATDSTAT & 0x80)==0){}; //wait for sequence finished > > p=&ADR0H; //point to ch 0 > > for(i=0; i < 8; i++){ > > bl=*p++; //lo byte > > bh=*p++; //hi byte > > tmp=((unsigned int)bh << 8) | bl; //form word > > addat[i]=tmp & 0x3ff; //save 10 bit value > > } > > } > > > > //-------------------- > > void showads(void){ > > //show 8 ch of internal a/d > > unsigned char i; > > > > printf("\n"); > > for(i=0; i<8; i++){ > > printf("%3d ",i); > > } > > printf("\n"); > > while(!kbhit()){ > > readads(); > > for(i=0; i < 8; i++){ > > printf("%04x ",addat[i]); > > } > > printf("\r"); > > } > > printf("\n"); > > } > > > > > > > > > > [Non-text portions of this message have been removed] > > -------------------------------------------------------- > To unsubscribe from this group, send an email to: > To learn more about Motorola Microcontrollers, please visit > http://www.motorola.com/mcu |
|
Hello all I am trying to hook up my logic analyzer to a debug port in my project, I want to use my eclk as my external clock for my logic analyzer. I have one problem I cannot get a clock signal off my elck (PE4). Any idea what's going on? I am using a external crystal 16Mhz so I should see 8Mhz on the ECLK right? One more thing I measured the Clock signal into the D60A and it is 16Mhz but the amplitude is only 400mV seems small to me but the processor is working ok, is that small an amplitude ok? Stephen [Non-text portions of this message have been removed] |
|
|
|
Stephen, Are you running in single chip mode? If so, then the E clock defaults to a port pin function. You need to clear the NECLK bit in the PEAR register to enable the external E clock. ed -- At 10:50 AM 9/12/2002 -0300, you wrote: >Hello all > >I am trying to hook up my logic analyzer to a debug port in my project, I >want to use my eclk as my external clock for my logic analyzer. I have one >problem I cannot get a clock signal off my elck (PE4). Any idea what's going >on? I am using a external crystal 16Mhz so I should see 8Mhz on the ECLK >right? One more thing I measured the Clock signal into the D60A and it is >16Mhz but the amplitude is only 400mV seems small to me but the processor is >working ok, is that small an amplitude ok? > >Stephen >[Non-text portions of this message have been removed] > >-------------------------------------------------------- >To unsubscribe from this group, send an email to: >To learn more about Motorola Microcontrollers, please visit >http://www.motorola.com/mcu |
|
Hi Stephen, You should write to PEAR and MODE register for enabling the ECLK output. Regards, Venu // PEAR = 0x0; // to enable ECLK output for test purpose // MODE = 0x80; // to enable ECLK output for test purpose --- In 68HC12@y..., "Stephen Mac Neil" <macneil@d...> wrote: > Hello all > > I am trying to hook up my logic analyzer to a debug port in my project, I > want to use my eclk as my external clock for my logic analyzer. I have one > problem I cannot get a clock signal off my elck (PE4). Any idea what's going > on? I am using a external crystal 16Mhz so I should see 8Mhz on the ECLK > right? One more thing I measured the Clock signal into the D60A and it is > 16Mhz but the amplitude is only 400mV seems small to me but the processor is > working ok, is that small an amplitude ok? > > Stephen > [Non-text portions of this message have been removed] |
|
Motorola made it a little tricky to figure out how to get the clock externally while in Normal single-chip mode. After a lot of reading, I was able to get it working perfectly for my project. The best information is from the Motorola Documentation, in the description of NECLK in the PEAR register. As the others have told you, you must set both the PEAR and the MODE very carefully to get ECLK on PE4 (and 'ECLK on PE7 if you want) in single chip mode. I have PEAR=$01, which enables ECLK and 'ECLK on PE4/PE7 respectively, and MODE=$80, which keeps the chip in normal single mode while allowing a free-running ECLK -- this specific setting for MODE is not described in the documentation, the factory Normal Single Chip mode described in the docs. does not allow a free-running ECLK. From Docs; =============================================== NECLK - No External E Clock Normal single chip: write once; special single chip: write anytime; all other modes: write never. Read anytime. In peripheral mode, E is an input and in all other modes, E is an output. 0 = PE4 is the external E-clock pin subject to the following limitation: In single-chip modes, to get an E clock output signal, it is necessary to have ESTR = 0 in addition to NECLK = 0. 1 = PE4 is a general-purpose I/O pin. =============================================== ----- Original Message ----- From: Stephen Mac Neil To: Sent: Thursday, September 12, 2002 9:50 AM Subject: [68HC12] D60A ECLK output Hello all I am trying to hook up my logic analyzer to a debug port in my project, I want to use my eclk as my external clock for my logic analyzer. I have one problem I cannot get a clock signal off my elck (PE4). Any idea what's going on? I am using a external crystal 16Mhz so I should see 8Mhz on the ECLK right? One more thing I measured the Clock signal into the D60A and it is 16Mhz but the amplitude is only 400mV seems small to me but the processor is working ok, is that small an amplitude ok? Stephen [Non-text portions of this message have been removed] Yahoo! Groups Sponsor ADVERTISEMENT -------------------------------------------------------- To unsubscribe from this group, send an email to: To learn more about Motorola Microcontrollers, please visit http://www.motorola.com/mcu Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service. |