1/3/2023 0 Comments Stm8 cosmic exampleIn our case we only need one, namely the update interrupt. This register determines which interrupts Timer2 can generate. The only important thing to note about these two registers is that TIM2_ARRH must be loaded with a value before TIM2_ARRL. The counter will then be reset using the values in these two registers. An interrupt will be generated when the counter value has been reached (for up) or zero is reached (for down). We will be loading this register with a counter value which the timer will count up to / down from. We will be using the counter as a simple up/down counter. TIM2_ARRH and TIM2_ARRL – Counter Auto-Reload Registers We will come back to this formula when we write the software in order to calculate the prescalar we will need to generate the 20Hz clock signal. TIM2_PSCR is a 4 bit number and this restricts the value of the prescalar to 1 to 32,768. Where f counter is the frequency of the signal being used as a clock source for Timer 2. The prescalar is a power of 2 and the effective frequency of the clock running Timer 2 is given by the following formula: This allows the timer to receive a slower clock signal than that running the STM8S. The prescalar divides the f master clock by the prescalar set in the TIM2_PSCR register. This in turn receives a clock from the internal clock of the STM8S (i.e. The 16-bit counter in Timer 2 receives a clock signal from the prescalar. With the exception of resetting the timer to a known state we will be using only six registers in this exercise: In fact we can set up the chip using relatively few registers. This application is simple and really only uses a fraction of the power of the STM8S timers. The Interrupt Service Routine (ISR) then has one very simple task, toggle the output port and wait for the next interrupt. Set up the output port to generate the signal.Setup the timer to generate an interrupt every 1 / 40th of a second.To do this we will make use of one of the STM8S timers, namely Timer 2 (T2). To make this project a low on processor power we will use interrupts to generate the pulse. So the project definition is simple, output a regular signal (20Hz with a 50% duty cycle) on Port D, Pin 4 (i.e. Here we will translate the post to use direct register access rather than use the STD Peripheral Library. In previous posts you may have seen an example program where we generate a 20Hz signal using the overflow interrupt on Timer 2.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |