Sign in

username:

password:



Not a member?

Search 68hc12



Search tips

Subscribe to 68hc12



68hc12 by Keywords

68HC1 | 812A4 | 9S12DP256 | Bootloader | CodeWarrior | D60A | Debugger | DP256 | ECT | EEPROM | EVB | Flash | HC1 | HCS12 | I2C | IAR | ICC1 | Interrupts | LCD | M68KIT912DP256 | MC9S12DP256 | MC9S12DP256B | Metrowerks | Motor | MSCAN | Multilink | PLL | Quadrature | SDI | SPI | Transceiver | XFC

Ads

Discussion Groups

Discussion Groups | 68HC12 | Re: Request for help with clock-cycle calculation

Join our technical discussions about Freescale Microcontrollers: M68HC12. (Freescale Semiconductor is a Subsidiary of Motorola).

Request for help with clock-cycle calculation - jambotronic - Jul 31 4:19:34 2008

I am a newcomer to the board and I would like to ask for some
assistance on the following:

I have a 16 MHz Elektronikladen 68HC12 Compact collecting data from
all 8 of its onboard analogue channels and have set
ATDCTL4 = 0x01 (2 MHz AD clock, 18 cycles per conversion, 8 bit
mode).

The Serial Link connecting the controller to the host PC is
operating at a baud rate of 19200 bps and I am outputting ASCI to
the terminal window with the value of 6 (tabulated) of the 8 AD
channels.

I am graphing the result in time and I would like to calculate how
many times each analogue channel is updated to the screen per
second. My problem is that I do not know which specifications of the
microcontroller to base the calculations on, and if one of the
aforementioned frequencies is a limiting factor (by that I mean, are
the comms fast enough to report EVERY ADC reading, etc). Also, I
realise that the execution times of the other instructions within my
code will be a factor, but the loop is extremely simple; the ADC
port is being polled in a continuous loop:
|
v
---------
^ |
| v
^ check condition of data collect bit on another port (assume to
| always be set to "ADC-data collect")
| |
| v
^ Write 6 of the 8 ADC bit vaules to variables
| |
| v
^ Output these values to the terminal window with a Tab character
| between each
| |
| v
--<--<--<

Many thanks in advance and I appreciate any advice offered.
Sandy
------------------------------------



(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )


Re: Request for help with clock-cycle calculation - Edward Karpicz - Jul 31 5:26:45 2008

"jambotronic" wrote:

>I am a newcomer to the board and I would like to ask for some
> assistance on the following:
>
> I have a 16 MHz Elektronikladen 68HC12 Compact collecting data from

what part is it?

> all 8 of its onboard analogue channels and have set
> ATDCTL4 = 0x01 (2 MHz AD clock, 18 cycles per conversion, 8 bit
> mode).
>

2MHz AD clock AD prescaller setting is correct, assuming bus clock is 8MHz.
You are not using PLL, right?
But 18 AD cycles per conversion? Are you talking about old pre S12 part? If
so then that's right, 9us single channel conversion.
> The Serial Link connecting the controller to the host PC is
> operating at a baud rate of 19200 bps and I am outputting ASCI to
> the terminal window with the value of 6 (tabulated) of the 8 AD
> channels.
>
> I am graphing the result in time and I would like to calculate how
> many times each analogue channel is updated to the screen per
> second. My problem is that I do not know which specifications of the
> microcontroller to base the calculations on, and if one of the
> aforementioned frequencies is a limiting factor (by that I mean, are
> the comms fast enough to report EVERY ADC reading, etc). Also, I
> realise that the execution times of the other instructions within my
> code will be a factor, but the loop is extremely simple; the ADC
> port is being polled in a continuous loop:
>

Of course serial link speed is a limiting factor. In normal 8-N-1 mode one
byte takes ten 1/19200 periods. 8 data bits, one start bit and one stop bit.
That's 521us /byte.

>
> 1. Check condition of data collect bit on another port (assume to
> always be set to "ADC-data collect")
>
> 2. Write 6 of the 8 ADC bit vaules to variables
>
> 3. Output these values to the terminal window with a Tab character
> between each

Tab character? It looks like you are converting your readings to strings
first. This may take some time, especially if you are using some kind of
printf. Converting byte to string may give 1 to 3 characters. Plus Tab and
you have 2 to 4 characters per AD channel. That's 4*521us =~2ms to send one
channel over SCI. Sending all 8 channels takes about 16ms refresh period or
about 62Hz refresh rate.
Edward

>
> 4. Goto 1
> Many thanks in advance and I appreciate any advice offered.
> Sandy
> ------------------------------------
>
------------------------------------



(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )

Re: Request for help with clock-cycle calculation - jambotronic - Jul 31 9:43:28 2008

Hi Edward and thank you for the reply.

> what part is it?

> 2MHz AD clock AD prescaller setting is correct, assuming bus clock
is 8MHz. You are not using PLL, right? But 18 AD cycles per
conversion? Are you talking about old pre S12 part? If
so then that's right, 9us single channel conversion.

No, no PLL and it is the older 68HC12A4.

> Of course serial link speed is a limiting factor. In normal 8-N-1
mode one byte takes ten 1/19200 periods. 8 data bits, one start bit
and one stop bit. That's 521us /byte.

Yes, this is the mode I am using.

> Tab character? It looks like you are converting your readings to
strings first. This may take some time, especially if you are using
some kind of printf. Converting byte to string may give 1 to 3
characters. Plus Tab and you have 2 to 4 characters per AD channel.
That's 4*521us =~2ms to send one channel over SCI. Sending all 8
channels takes about 16ms refresh period or about 62Hz refresh rate.

No strings, I am just using numerous printfs...

==========================
printf("%d",reading);
printf("\t");
==========================

..which repeats for all of the 6 readings (2 of the ADC readings are
not used for now)

This is probably very clunky and horrifically innefficient but my
programming knowledge is great!

> Edward
Might I ask how the figure of 9us for a single channel conversion
was calculated? I do not understand.

I seriously appreciate the time you have taken to reply.

Kind regards,
Sandy
------------------------------------



(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )

Re: Re: Request for help with clock-cycle calculation - Edward Karpicz - Jul 31 13:25:02 2008

Hi Sandy

>> 2MHz AD clock AD prescaller setting is correct, assuming bus clock
> is 8MHz. You are not using PLL, right? But 18 AD cycles per
> conversion? Are you talking about old pre S12 part? If
> so then that's right, 9us single channel conversion.
>
> No, no PLL and it is the older 68HC12A4.
To answer what from are those 9us. Your AD clock is 2MHz. Single channel
conversion takes in your case 18 AD clock cycles. That's 9us
>> Of course serial link speed is a limiting factor. In normal 8-N-1
> mode one byte takes ten 1/19200 periods. 8 data bits, one start bit
> and one stop bit. That's 521us /byte.
>
> Yes, this is the mode I am using.
>
>> Tab character? It looks like you are converting your readings to
> strings first. This may take some time, especially if you are using
> some kind of printf. Converting byte to string may give 1 to 3
> characters. Plus Tab and you have 2 to 4 characters per AD channel.
> That's 4*521us =~2ms to send one channel over SCI. Sending all 8
> channels takes about 16ms refresh period or about 62Hz refresh rate.
>
> No strings, I am just using numerous printfs...
>
> ==========================
> printf("%d",reading);
> printf("\t");
> ==========================
Not no but yes. Printf %d converts reading to string of chars(bytes) and
sends them. 8bit unsigned reading ranges from 0 to 255. That's up to 3 ASCII
chars. Plus '\t' and you have up to four bytes to send over SCI.

>
> ..which repeats for all of the 6 readings (2 of the ADC readings are
> not used for now)
>

So worst case 4chars*6readings*521us = ~12.5ms, ~80Hz.
If you need it faster then 1) try using 38400bps. 2) send samples as hex
numbers (2 to 3 chars instead of 2 to 4) 3) try switching to binary
protocol. In ASCII mode you send 2-4 bytes instead of one data byte. In
binary mode you send just a data byte. Of course there's a question how to
synchronize binary stream. Some kind of communication protocol like SLIP may
be required. Of course comms protocol would drag some overhead bytes to
send, but most likely it will be still more compact than just ascii strings.

Edward

> This is probably very clunky and horrifically innefficient but my
> programming knowledge is great!
>> Edward
> Might I ask how the figure of 9us for a single channel conversion
> was calculated? I do not understand.
>
> I seriously appreciate the time you have taken to reply.
>
> Kind regards,
> Sandy
> ------------------------------------



(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )

Re: Request for help with clock-cycle calculation - jambotronic - Jul 31 17:09:56 2008

Edward, sincerely, I appreciate your time and patience and thank you
for giving the help you have; you have provided me with exactly what I
was looking for.

Kind regards,

Sandy
------------------------------------



(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )