Part Number Hot Search : 
OP300 ZTTCS PMT8230 AN114 DU150WHF DS182107 440FS KRC118M
Product Description
Full Text Search
 

To Download AN1254 Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  1/6 AN1254 application note how to measure the period of an external signal with st52x420 authors: v. marino ? 1. introduction this application note shows an example of how to measure the period of an external signal, by using timer0, one of the three on-chip pwm timers available on st52x420. this application can be used in fields like motor speed control, encoder pulse width measurement. in order to obtain such a measure, you have to configure the timer0 with external start/stop and internal reset. the clock can be internal or external, in our application it is internal. in figure1 is shown the timing of the interested signal. figure 1. external signal timing 2. timer0 configuration timer0 has two different working modes: timer mode and pwm mode. these can be selected by setting the correspondent t0mode bit of reg_5. in this applications, the peripheral pwm/timer0 works in timer mode. in order to configure the timer0, you have to set three configuration registers: reg_conf5, reg_conf6 and reg_conf7, how is shown in the following figure. start stop start stop timer start/stop timer clock timer reset timer count 0 1 2345 0 1 2345 0 february 2000
AN1254 - application note 2/6 the pwm/timer0 gives an interrupt on counter stop, and the external start_stop is active on edge, in order to have, on the first rising edge of the signal which you want to measure the period, the start of the timer, and, at the next rising edge, the stop. note that, if the lsb of reg_conf5 is 1, the timer is not reset, if it is 0 is reset; after the counter stop, signalled by the interrupt of the peripheral, you have to read the timer_count_0 value, that constitutes the measure of the period, and to reset the timer, putting to 0 the lsb of reg_conf5, as you can see in the assembler code, particularly in the timer0 interrupt routine. figure 2. timer0 configuration register 5 figure 3. timer0 configuration register 6 d7 d6 d5 d4 d3 d2 d1 d0 tirst0: timer 0 internal reset disabled terst: timer 0 external reset on level tistr0: timer 0 internal stop testr: timer 0 external start on edge inte0: not used intsl0: timer0 interrupt on counter stop t0mode: timer 0 timer mode 00111001 d7 d6 d5 d4 d3 d2 d1 d0 00100110 presc0: timer 0 clock = clkm/64 tmrw0: timer0out waveform equal to square wave not used
AN1254 - application note 3/6 by setting the bits b4-b0 of reg_conf6 it is possible to select the prescaler in order to obtain the timer_clock, by dividing the clock master or the external clock provided on the t0clk pin. all of this allows to have a great flexibility to measure signals to different frequencies. if you use the clock master, for example 20mhz, by the configuration given in the example, the timer_clock obtained is 20mhz/64=312.5khz, correspondent to a period of 3.2 l s. in this way you can measure a period in the range 3.2 l s-3.2 l s*255=816 l s. figure 4. timer0 configuration register 7 naturally you have to select the prescaler (or eventually to use an external clock), in reason for the range of frequency in which the signal that you have to measure can vary. the configuration register 7 allows to select the source signal for the st52x420 timer0 peripheral. by setting to 00 the last significative bits of reg_conf7, you can reset the timer counter internally while by setting to 01 the bits 3 and 2 you have the start and the stop of the timer on the rising edge of the external signal. finally, by setting to 0 the bit 4 you select the internal clock (but you can also select the external clock putting it to 1). for more details on the timers functions and configurations please refer to st52x420 data sheet. d7 d6 d5 d4 d3 d2 d1 d0 00000100 t0rst: timer0 reset internal t0str: timer0 start external t0clk: timer clock internal t0msk: timer0 reset synchronization mask timer0 reset enabled t2msk: timer2 reset synchronization mask timer2 reset enabled t1msk: timer1 reset synchronization mask timer1 reset enabled
AN1254 - application note 4/6 appendix 1 in this appendix is shown the source program written in assembler language generated with fuzzystudio tm 4.0, the software development tool to program and quickly develop applications with all the st52 family of fuzzy microcontrollers. ;*********************************************************** ; purpose: test timer0 ; date: 16/02/2000 ; ;********************************************************** ; start/stop external (on edge), clock and reset internal ;*********************************************************** irq 0 ad_int irq 1 tim0 irq 2 tim1 irq 3 tim2 irq 4 ext_int ;******** peripherals and chip configurations ******** ldrc 0 00000000b ; interrupt mask configuration ldcr 0 0 ; all interrupts masked ldrc 0 00111001b ; interrupt priority configuration ldcr 1 0 ; from the top: pwm0, pwm1, pwm2, adc ldrc 0 00110001b ; port a configuration ldcr 4 0 ; pa5, pa4, pa0 input ldrc 0 00111000b ; pwm-timer 0 configuration ldcr 5 0 ; interrupt on counter stop, ext. start on edge ldrc 0 00100110b ; pwm-timer 0 configuration ldcr 6 0 ; prescaler 00110 (clkm/64=20mhz/64=312,5khz) ldrc 0 00000100b ; pwm-timer 0 configuration ldcr 7 0 ;internal reset, external start, internal clock ldrc 0 00000001b ; port a mode configuration ldcr 12 0 ;por t a 7 bits, pin22-pa3, pin23-pa2, pin24-t0out\ ldrc 0 00000000b ; port b direction configuration ldcr 13 0 ; pb7-pb0 output ldrc 0 00000000b ; port b mode configuration
AN1254 - application note 5/6 ldcr 14 0 ; pb7-pb0 digital ldrc 0 00000000b ; port c direction configuration ldcr 15 0 ; pc3-pc0 output ldrc 0 00000110b ; port c mode configuration ldcr 16 0 ; pin8-pc3, pin7-pc2, pin6-t0out ;*********************************************************** start: ldrc 0 255 ldpr 3 0 ; pwm_0_count=255 (255 x 3.2us=816us) ldrc 0 00111001b ; pwm-timer 0 configuration ldcr 5 0 ; internal reset disabled ldrc 0 00000100b ; interrupt mask configuration ldcr 0 0 ; tm0 not masked loop: jp loop ;**** ints subroutines ********* ext_int: reti ad_int: reti tim0: ldri 20 12 ; read timer0_count and send it in ram20 ldpr 1 20 ; send ram20 into portb ldrc 0 00111000b ; pwm-timer 0 configuration ldcr 5 0 ; internal reset enabled ldrc 0 00111001b ; pwm-timer 0 configuration ldcr 5 0 ; internal reset disabled reti tim1: reti tim2: reti ;**************************************************************************
AN1254 - application note 6/6 information furnished is believed to be accurate and reliable. however, stmicroelectronics assumes no responsibility for the conse- quences of use of such information nor for any infringement of patents or other rights of third parties which may result from its use. no li- cense is granted by implication or otherwise under any patent or patent rights of stmicroelectronics. specification mentioned in this publi- cation are subject to change without notice. this publication supersedes and replaces all information previously supplied. stmicroelectronics products are not authorized for use as critical components in life support devices or systems without express written approval of stmicroelectronics. the st logo is a trademark of stmicroelectronics ? 2000 stmicroelectronics C printed in italy C all rights reserved fuzzystudio tm is a registered trademark of stmicroelectronics stmicroelectronics group of companies http://www.st.com australia - brazil - china - finland - france - germany - hong kong india - italy - japan - malaysia - malta - morocco - singapore - spain - sweden - switzerland - united kingdom - u.s.a.


▲Up To Search▲   

 
Price & Availability of AN1254

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X