
[ 2 comments ] ( 12 views ) | [ 0 trackbacks ] | permalink | related link
/* Time 2 base configuration 10ms */
TIM_TimeBaseStructure.TIM_Period = 9999;
TIM_TimeBaseStructure.TIM_Prescaler = 72;
TIM_TimeBaseStructure.TIM_ClockDivision =TIM_CKD_DIV1;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
Period calculation:
72MHz / 72 = 1MHz or 1µs period unit.
1µs + 9999 x (1µs) = 10ms
http://guyvo-cortex.blogspot.cz/2009/04 ... imers.html
void TIM4_Configuration(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
// TIM_TimeBaseStructure.TIM_Prescaler = (800 * 2) - 1; // 8 MHz clock source, 8000 for 2 ms, 800 for 0.2 ms ticks
TIM_TimeBaseStructure.TIM_Prescaler = (7200 * 2) - 1; // 72 MHz clock source, 0.2 ms ticks
TIM_TimeBaseStructure.TIM_Period = 50000 - 1; // 0.2 ms units, 10 second update
TIM_TimeBaseStructure.TIM_ClockDivision = 1;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);
// TIM4 enable counter
TIM_Cmd(TIM4, ENABLE);
// Clear pending update interrupt
TIM_ClearITPendingBit(TIM4, TIM_IT_Update);
// Enable interrupt on update
TIM_ITConfig(TIM4, TIM_IT_Update, ENABLE);
}
https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=https%3a%2f%2fmy.st.com%2fpublic%2fSTe2ecommunities%2fmcu%2fLists%2fcortex_mx_stm32%2fProblem%20with%20Timing&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B¤tviews=1913
[ 6803 comments ] ( 92150 views ) | [ 0 trackbacks ] | permalink | related link
The purpose of this lab is to introduce you to the STMicroelectronics Cortex™-M4 processor using the ARM Keil™ MDK toolkit featuring the IDE μVision. We will use the Serial Wire Viewer (SWV) and the on-board ST-Link V2 Debug Adapter. At the end of this tutorial, you will be able to confidently work with these processors and Keil MDK. See www.keil.com/st.
[ add comment ] ( 3 views ) | [ 0 trackbacks ] | permalink | related link
Example: to configure Systick - SysTick_Config(SystemCoreClock / IT_PER_SEC) - for having interrupt an specific frequency divide the base clock frequency by required frequency.
ie.: 100 Hz we need
168 Mhz is the chip
168 000 000 / 100 = 1 680 000
it means every 1 680 000 cpu cycles the SysTick interrupt is generated.
for audio, try to generate interrupt for a C8 notewhich is 4186.009Hz.
ie.: 4186.009 * 2 = 8372,018; interrupt is generated for each change in the cycle, there are two changes, from HIGH to LOW or LOW to HIGH.
168 000 000 / 8372 = ~20067
each 20067 cycles the cycle toggle is invoked.
what would be the most optimal irq frequency up to C9 which is 8372, resp. 16744? the count for this note is 10033 cyces the interrupt is invoked. what is the optimal count of cycles between the interrupt, taking into account the interupt routine also takes cycles?
rough quess: arm does single ol half of the instruction per cycle. cpu needs to run the user program as well at least for the same as it spends with the intr. also we need some spare time to make sure we will not be missing an interrupt.
1000 * x = 168 000 000
x = 168 000
168 000 times per second we will generate the interrupt. for that number the uint16_t type for the counter var is too small, uint32_t with 4,294,967,295 is enough.
168 000 / 16 744 = 10.003
but the glitch is, the higher frequency we generate, the more it will be inaccurate because of division error. that's why Juno 106 has 1 Mhz / 1 000 000 timer. such precision we can't reach that way.
to have 1 000 000 interrupts (better would be 2 000 000) per sec we wil need the interrupt to be generated each 168 (better 84) cycles. irq routine then has to be cleared out in 84 (42) cycles which obviously will not until rewritten in asm.
a better way how to solve this is to use the independent irq with pulse modulation on a chip.
some reading:
http://www-micrel.deis.unibo.it/LABARCH ... 2/lab4.pdf
http://amarkham.com/?p=29
https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2Fcortex_mx_stm32%2FWhat%20difference%20between%20setting%20TIM_TimeBaseStructure.TIM_Prescaler%20and%20%20TIM_PrescalerConfig&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B¤tviews=256
http://visualgdb.com/tutorials/arm/stm32/timers/
http://myembeddedtutorial.blogspot.cz/2 ... imers.html
http://code.google.com/p/andrei-develop ... ain.c?r=34
[ add comment ] ( 4 views ) | [ 0 trackbacks ] | permalink | related link
- clock to peripherials, of course
- peripherial structures can be set to default values prior to fill them with custom values
- clock for USARTx/UARTs must be configured
- IRQ handler has to clear the IRQ flags
- NVIC must be configured
- USART_ITConfig must be configured accordingly to allow trigger intr
in this code
- no lame putchar redirection, but the function which behaves like printf
- buffer created each time for a line written (uneffective, but the irq wont erase the previous unprinted message)
* implement buffer, no ring, but specific array-pointer with buffer full functionality, use dma for input and output, play with priorities to maintain the smooth systick.
#include <misc.h>
#define PRINT_BUFFER_SIZE 64
/*******************************************************************
* USART/UARTx: usart_simple_print( USART_TypeDef *usart, const char *str )
* usart_printf( USART_TypeDef *usart, const char *format, ... )
*******************************************************************/
void usart_simple_print( USART_TypeDef *usart, const char *str )
{
while( *str ) {
while( USART_GetFlagStatus( usart, USART_FLAG_TXE) == RESET );
USART_SendData( usart, *str );
str++;
}
}
void usart_printf( USART_TypeDef *usart, const char *format, ... )
{
va_list args;
char *buf = ( char *) malloc( PRINT_BUFFER_SIZE * sizeof( char ) );
if( buf != 0 )
{
va_start( args, format );
if( vsnprintf( buf, PRINT_BUFFER_SIZE * sizeof( char ), format, args ) > 0 )
{
usart_simple_print( usart, buf );
} else
{
usart_simple_print( usart, buf );
usart_simple_print( usart, "usart_printf: maxlen \
character limit was reached or some other error, \
such as an invalid format specification\n" );
}
va_end( args );
free( buf );
} else
{
usart_simple_print( usart, "usart_printf: not enough memory\n" );
}
}
/*******************************************************************
* usart init
*
*******************************************************************/
void USART_my_init( uint32_t baud )
{
// define structure(s)
GPIO_InitTypeDef GPIO_InitStruct_Rx;
GPIO_InitTypeDef GPIO_InitStruct_Tx;
USART_ClockInitTypeDef USART_ClockInitStruct;
USART_InitTypeDef USART_InitStruct;
NVIC_InitTypeDef NVIC_InitStruct;
//
// -----------------------------usart-Rx-pin-B7
// enable clock to peripherial
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
// init (clear to default) this structure
GPIO_StructInit( &GPIO_InitStruct_Rx );
// fill in params
GPIO_InitStruct_Rx.GPIO_Pin = GPIO_Pin_7;
GPIO_InitStruct_Rx.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct_Rx.GPIO_Mode = GPIO_Mode_AF;
//GPIO_InitStruct_Rx.GPIO_Mode = IN_FLOATING;
// make it written
GPIO_Init(GPIOB, &GPIO_InitStruct_Rx);
// assign alternate function to a pin
GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_USART1);
//
// -----------------------------usart-Tx-pin-B6
// enable clock to peripherial
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
// init (clear to default) this structure
GPIO_StructInit( &GPIO_InitStruct_Tx );
// fill in params
GPIO_InitStruct_Tx.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStruct_Tx.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct_Tx.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStruct_Tx.GPIO_OType = GPIO_OType_PP;
GPIO_InitStruct_Tx.GPIO_PuPd = GPIO_PuPd_UP;
// make it written
GPIO_Init(GPIOB, &GPIO_InitStruct_Tx);
// assign alternate function to a pin
GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_USART1);
//
// ---------------------------------usart-clock
// init (clear to default) this structure
USART_ClockStructInit(&USART_ClockInitStruct);
// fill in params
USART_ClockInitStruct.USART_Clock = USART_Clock_Disable;
USART_ClockInitStruct.USART_CPOL = USART_CPOL_High;
USART_ClockInitStruct.USART_LastBit = USART_LastBit_Disable;
USART_ClockInitStruct.USART_CPHA = USART_CPHA_1Edge;
// make it written
USART_ClockInit( USART1, &USART_ClockInitStruct );
//
// ----------------------------usart-parameters
// enable clock to peripherial
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
// init (clear to default) this structure
USART_StructInit( &USART_InitStruct );
// fill in params
// Clock, CPOL_LOW, CPHA_2Edge, LastBit_Disable added
//
// USART synchronous mode:
// CPOL - bit allows the user to select
// the clock polarity
// CPHA - bit allows the user to select the
// phase of the external clock
//
USART_InitStruct.USART_BaudRate = baud;
USART_InitStruct.USART_WordLength = USART_WordLength_8b;
USART_InitStruct.USART_StopBits = USART_StopBits_1;
USART_InitStruct.USART_Parity = USART_Parity_No;
USART_InitStruct.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStruct.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; /*send a idle frame,cause TXE=1 interupt*/
// make it written
USART_Init(USART1, &USART_InitStruct);
// enable device
USART_Cmd(USART1, ENABLE);
//
// ----------------------------usart-interrupts
// fill in params
NVIC_InitStruct.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStruct.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
// make it written
NVIC_Init(&NVIC_InitStruct);
// Enable Transmit intr, transmit data register is empty
USART_ITConfig(USART1, USART_IT_TXE, DISABLE);
// Enable Receive intr, data register is not empty
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
// konec inicializace
usart_printf( USART1, "usart1 inicializace dokoncena\n" );
}
//
// ----------------------------irq-usart-routine
void USART1_IRQHandler(void)
{
unsigned char recdata, temphead;
// usart_printf( USART1, "IN INTERRUPT\n" );
// is USART_IT_ORE_ER (overrun)
//
if(USART_GetITStatus(USART1, USART_IT_ORE_ER) != RESET)
{
usart_printf( USART1, "ErI - overrun error\n" );
}
// is USART_IT_RXNE intr (the shift register is transferred
// to the RDR - data can be read
//
if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)
{
USART_ClearITPendingBit(USART1, USART_IT_RXNE);
recdata = USART_ReceiveData( USART1 ) & 0xFF;
// echo recived character
usart_printf( USART1, "%c", recdata );
}
// is USART_IT_TXE intr, send data out
//
if(USART_GetITStatus(USART1, USART_IT_TXE) != RESET)
{
USART_ClearITPendingBit(USART1, USART_IT_TXE);
// do we have some data to send
usart_printf( USART1, "TxI\n" );
}
}
/*******************************************************************
* configure LEDs on board
*
*******************************************************************/
void GPIO_my_init() {
GPIO_InitTypeDef GPIO_InitStruct;
//
// ------------------------pin-D15-D14-D13-D12
// enable clock to peripherial
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
// init (clear to default) this structure
GPIO_StructInit( &GPIO_InitStruct );
// fill in params
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_15 | GPIO_Pin_14 | GPIO_Pin_13 | GPIO_Pin_12;
// we want to configure all LED GPIO pins
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT; // we want the pins to be an output
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz; // this sets the GPIO modules clock speed
GPIO_InitStruct.GPIO_OType = GPIO_OType_PP; // this sets the pin type to push / pull (as opposed to open drain)
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL; // this sets the pullup / pulldown resistors to be inactive
// make it written
GPIO_Init(GPIOD, &GPIO_InitStruct); // this finally passes all the values to the GPIO_Init function which takes care of setting the corresponding bits.
}
[ add comment ] ( 4 views ) | [ 0 trackbacks ] | permalink
This one I want...
This guy I can afford :)
http://www.gme.cz/osciloskop-dvoukanalo ... t-p720-113
[ add comment ] ( 3 views ) | [ 0 trackbacks ] | permalink
If the windows update service is run, or the updates are invoked with ms explorer throuhg update page, cpu load goes high.
you may get rid of the problem by installing updaes manually. get usefull utility which allows you to donwload updates by hand and. Grab the list of updates from the same page (after downoading double click on icon). Then run the utility and let it download the updates.
After all is downloaded, then sort the updates by date and start with the manual running each single one. You probably wont have to run all of them, because after some of aupdates are installed, the native autoupdater finally wakes upa and shows the shield icon in the tray without the svchost locking the cupu.
[ add comment ] ( 3 views ) | [ 0 trackbacks ] | permalink | related link
Msconfig.exe runs on reboot by inserting an entry named MSConfig under the registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run. To prevent the dialog box from showing up, you can manually delete the MSConfig entry, use the Console Registry Tool (reg.exe) to delete it, or use a batch file to delete it.
reg delete HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run /v msconfig /f
[ add comment ] ( 3 views ) | [ 0 trackbacks ] | permalink | related link

Emcraft Systems provides a Linux (uClinux) software distribution and a starter kit for the STMicroelectronics STM32F2/F4 microcontrollers.
[ add comment ] ( 3 views ) | [ 0 trackbacks ] | permalink | related link
http://neuron.feld.cvut.cz/micro/stm32/index-en.html
[ add comment ] ( 4 views ) | [ 0 trackbacks ] | permalink