2011-09-06 10:56 AM
I'm looking to measure 50/60Hz using TIM1 and pin PD7 as input has anyone an example of this?
Also I don't seem to be able to select the AFR4 in the STDV anyone have a clue why?2011-09-07 01:03 AM
if you have a look on the datasheet
http://www.st.com/internet/com/TECHNICAL_RESOURCES/TECHNICAL_LITERATURE/DATASHEET/CD00197787.pdf
pag.32 note 5 you can see AFR4 is available only on 44-pin package devices. You can use TIM1_CH1 instead of TIM1_CH4 i.e. brazov22011-09-07 02:27 AM
Yes ment to say I'm using a 44pin device.
Do I need to tell the programmer it's 44pin? Also when I'm using this pin as a input to the timer can I read it as a input?2011-09-07 06:19 AM
yes, you must specify exact stm8s sales type in the programmer.
You can read pin status in GPIO_IDR register @5010h. brazov22011-09-07 10:26 AM
Thanks,
Any ideas on how to set up the timer just don't want to truge through the datasheet?2011-09-08 01:06 AM
/* Private variables ---------------------------------------------------------*/
u8 TMPICH; // current CC1 input capture H & L values u8 TMPICL; u16 ICAP; // current ICAP sample in word// *** GIO INIT ***
GPIOD->CR1|= (u8)0x80; // IC1 (PD.7) settings: Input pull-up GPIOD->DDR&=~(u8)0x80;// *** TIM1 INIT ***
TIM1->CCMR1= ((15<<4) & TIM1_CCMR_ICxF) | (1 & TIM1_CCMR_CCxS); // CC1 input capture, filter to max TIM1->CCER1= TIM1_CCER1_CC1E | TIM1_CCER1_CC1P; // CC1 IC enable, falling edge TIM1->CR1|= TIM1_CR1_URS |TIM1_CR1_CEN; // enable timer // *** MAIN LOOP *** while (1) { if ((TIM1->SR1 & TIM1_SR1_CC1IF) != 0) { // input capture? TMPICH= TIM1->CCR1H; // yes - copy captured value to ICAP variable TMPICL= TIM1->CCR1L; ICAP= (u16)(((u16)(TMPICH) << 8) | (u16)(TMPICL)); TIM1->SR1&=~TIM1_SR1_CC1IF;// clear CC flag }2011-09-08 02:53 AM
Thanks save me alot of time :)
2011-09-08 04:16 AM
It looked so simple but I tried it and it didn't work set the clock prescale to 8 max time out > 10ms.
I looked at the AFR4 but even though the programmer didnt let me see the alternative function I set it anyway but again nothing worked. I assume the SWIM doesn't over ride the option bytes after you use the programmer to program them? I assume the default setting for the other timer register dont need changing? I know the pin is changing as I set an external pin when it toggles but I don't know if the timer is seeing the change on the I/O.2011-09-08 04:38 AM
example code below should be changed anyway to work..... Try to make it work with TIM1 IC1 (PC4 if i remember well) then rewrite it for TIM1 IC4 (PD7).In this case for IC1 on PC4 do the following port configuration. Also to debug it use break points in stvd
// *** GIO INIT ***
GPIOD->CR1|= (u8)0x80; // IC1 (PD.7) settings: Input pull-up
GPIOD->DDR&=~(u8)0x80;