2018-03-05 09:23 AM
I am using STM8S003F3U. This MCU is being used with a SPIRIT1 transceiver. Using OOK modulation, the SPIRIT1's raw data is being sent to pin PC3 on the MCU. Because my transmitter's data rate is inconsistent, I need to be able to measure the pulse HIGH time of the data coming across. To do this, it is my belief that the following needs to be done:
1) Configure PC3 to its alternative pin function (TIM1_CHANNEL_1_N). I do not know how to do this. Can someone provide a code example?
2) Configure the TIM1 capture channel with two ISRs (one for rising edges and one for falling edges), so that the pulse time can be measured. There is some rudimentary code from ST, but it is unclear how to do this. Can someone provide a code example?
Once these two steps are complete, I can derive the bit rate and decode messages. Any help that can be provided is much appreciated!
Thank you,
Noah
#stm8s003f3u #alternate #spirit1 #pwm-input-capture #alternate-function-selection2018-03-05 09:28 AM
Are you sure the Negated pin can be used as an Input? I know it can't on the STM32 designs, not sure of the STM8.
The Data Sheet should provide details of the Alternate Function pin mapping options.
2018-03-06 06:56 AM
Clive,
Are you a ST employee? I ask because if you are, I am extremely disappointed in being asked a question that ST should know far better than I. This response is useless and in no way assists in solving this issue.
The datasheets, application notes and example designs have been thoroughly searched. Quit frankly, we are on the verge a selecting another MCU due to the lack of support that ST provides. If anyone can help, then perhaps it makes sense to continue to use ST's parts.
2018-03-06 07:54 AM
Clive,
I thought this was a forum for writing ST technical support professionals, actual employees of ST. I am sorry for venting to you, if you too are a developer and not formally associated ST. This is quite literally the 10th time I have contacted ST on this or a related issue, and there has been no response.
Now, thank you for sharing the information that you have. Regardless of the pin that has been selected - this can be changed quite easily - there is still the need to measuring the PWM pulse time. If, for example, pin PC5 (TIM2_Channel1) were used and the PWMI Init function were used (see below), how would one extract the pulse time and mange the timer. If there were any example code for this, it would be useful.
/**
* @brief Configures the TIM2 peripheral in PWM Input Mode according to the specified parameters. * @param TIM2_Channel specifies the Input Capture Channel from @ref TIM2_Channel_TypeDef. * @param TIM2_ICPolarity specifies the Input Capture Polarity from @ref TIM2_ICPolarity_TypeDef. * @param TIM2_ICSelection specifies the Input Capture Selection from @ref TIM2_ICSelection_TypeDef. * @param TIM2_ICPrescaler specifies the Input Capture Prescaler from @ref TIM2_ICPSC_TypeDef. * @param TIM2_ICFilter specifies the Input Capture Filter value (value can be an integer from 0x00 to 0x0F). * @retval None */void TIM2_PWMIConfig(TIM2_Channel_TypeDef TIM2_Channel, TIM2_ICPolarity_TypeDef TIM2_ICPolarity, TIM2_ICSelection_TypeDef TIM2_ICSelection, TIM2_ICPSC_TypeDef TIM2_ICPrescaler, uint8_t TIM2_ICFilter){ uint8_t icpolarity = (uint8_t)TIM2_ICPOLARITY_RISING; uint8_t icselection = (uint8_t)TIM2_ICSELECTION_DIRECTTI;/* Check the parameters */
assert_param(IS_TIM2_PWMI_CHANNEL_OK(TIM2_Channel)); assert_param(IS_TIM2_IC_POLARITY_OK(TIM2_ICPolarity)); assert_param(IS_TIM2_IC_SELECTION_OK(TIM2_ICSelection)); assert_param(IS_TIM2_IC_PRESCALER_OK(TIM2_ICPrescaler));/* Select the Opposite Input Polarity */
if (TIM2_ICPolarity != TIM2_ICPOLARITY_FALLING) { icpolarity = (uint8_t)TIM2_ICPOLARITY_FALLING; } else { icpolarity = (uint8_t)TIM2_ICPOLARITY_RISING; }/* Select the Opposite Input */
if (TIM2_ICSelection == TIM2_ICSELECTION_DIRECTTI) { icselection = (uint8_t)TIM2_ICSELECTION_INDIRECTTI; } else { icselection = (uint8_t)TIM2_ICSELECTION_DIRECTTI; }if (TIM2_Channel == TIM2_CHANNEL_1)
{ /* TI1 Configuration */ TI1_Config((uint8_t)TIM2_ICPolarity, (uint8_t)TIM2_ICSelection, (uint8_t)TIM2_ICFilter);/* Set the Input Capture Prescaler value */
TIM2_SetIC1Prescaler(TIM2_ICPrescaler);/* TI2 Configuration */
TI2_Config(icpolarity, icselection, TIM2_ICFilter);/* Set the Input Capture Prescaler value */
TIM2_SetIC2Prescaler(TIM2_ICPrescaler); } else { /* TI2 Configuration */ TI2_Config((uint8_t)TIM2_ICPolarity, (uint8_t)TIM2_ICSelection, (uint8_t)TIM2_ICFilter);/* Set the Input Capture Prescaler value */
TIM2_SetIC2Prescaler(TIM2_ICPrescaler);/* TI1 Configuration */
TI1_Config((uint8_t)icpolarity, icselection, (uint8_t)TIM2_ICFilter);/* Set the Input Capture Prescaler value */
TIM2_SetIC1Prescaler(TIM2_ICPrescaler); }}2018-03-06 08:21 AM
Clive is right about the need to read and understand the data sheet. People responding to your post is trying to help - as they have the option to remain silent. The fact that they spent their time and effort to help should be appreciated.
As to your questions.
1. Possible to write code, or to change the option bytes.
2. May not be possible to write to isrs to processed the two edges individually but certainly doable to write one isr to process both.
2018-03-06 08:23 AM
I think my profile is abundantly clear on that.
2018-03-06 08:39 AM
For a senior engineer you seem to have an attitude problem, and in ability to process information/suggestions provided to you. If you have a problem with ST take that up with the FAE assigned to your account and sales engineers you're working with.
Can an output only pin on the TIM be used as an input? Generally not.
2018-03-06 10:55 AM
Don't worry about the actual implementation. Instead, think about your approach and then figure out a way to implement it.
Two basic ways to do what you want.
1.use the external pulse train to gate an faster clock. Many ways to do that, for example. The simplest would be to use an interrupt on the input pin to trigger a timer.
This approach can use any pin that's interrupt capable. But it has jitters. Better suited for low speed pulses.
2. Use the capture function of the timer. It is the most accurate, no jitter, but can only be done on certain pins. Great for high speed signals.
You just need to figure out which works better for your application.