stm8s003 timer1 channel2 capture doesn't work

Thread Starter

john137

Joined Oct 25, 2023
1
this doesn't work:

TIM1_CCMR2 = 0b01; //its default input channel
TIM1_IER = 0b100; //channel 2 capture interrupt
TIM1_CCER2 = 0b1; //channel 2 capture
TIM1_CR1 = 0b1; //start counter

and yet this works with no problem (on channel 1)

TIM1_CCMR1 = 0b10; //remap channel 1 on input 2 where ch2 is supposed to be by default
TIM1_IER = 0b10; //capture channel 1 interrupt
TIM1_CCER1 = 0b1; //enable channel 1 capture
TIM1_CR1 = 0b1; //start counter

also, if I remap channel one on ti 1 (pin 16) it still works (on channel one pin) but if I remap channel 2 on ti 1 it won't.
I need to get them both to work.
 

jeffl_2

Joined Sep 17, 2013
73
Are you programming this from a "complete" datasheet? I went on Digikey to look at the one they linked and at 103 pages it was pitifully small for a microcomputer datasheet, compare that to a Microchip PIC16F series at 400-500 pages. Naturally this meant they didn't have room to "spell out" the definitions AND uses/interactions of all of the 32 bytes/256 bits in the section dealing with TIM1, now I suspect the bits of the CAPCOM section are "kind of" similar to some of the aforementioned Microchip devices but I wouldn't guarantee anything. Unless you both know how ALL these bits are defined/used AND how they default at powerup (which ones HAVE TO be set/cleared before use in a certain mode) you aren't going to get anywhere. If you do have a link to the more complete version of this datasheet and post it we might be able to help you, but as is I suspect something isn't being initialized correctly for your use (and unlike Microchip designs there are some combinations of option/AFRs that are actually INCOMPATIBLE with each other so you have to watch out for that as well). Sorry I can't help you more at this time.
 

MrChips

Joined Oct 2, 2009
30,458
Are you programming this from a "complete" datasheet? I went on Digikey to look at the one they linked and at 103 pages it was pitifully small for a microcomputer datasheet, compare that to a Microchip PIC16F series at 400-500 pages. Naturally this meant they didn't have room to "spell out" the definitions AND uses/interactions of all of the 32 bytes/256 bits in the section dealing with TIM1, now I suspect the bits of the CAPCOM section are "kind of" similar to some of the aforementioned Microchip devices but I wouldn't guarantee anything. Unless you both know how ALL these bits are defined/used AND how they default at powerup (which ones HAVE TO be set/cleared before use in a certain mode) you aren't going to get anywhere. If you do have a link to the more complete version of this datasheet and post it we might be able to help you, but as is I suspect something isn't being initialized correctly for your use (and unlike Microchip designs there are some combinations of option/AFRs that are actually INCOMPATIBLE with each other so you have to watch out for that as well). Sorry I can't help you more at this time.
You looked at the datasheet, not the RM0016 Reference Manual which is 467 pages.
 

MrChips

Joined Oct 2, 2009
30,458
this doesn't work:

TIM1_CCMR2 = 0b01; //its default input channel
TIM1_IER = 0b100; //channel 2 capture interrupt
TIM1_CCER2 = 0b1; //channel 2 capture
TIM1_CR1 = 0b1; //start counter

and yet this works with no problem (on channel 1)

TIM1_CCMR1 = 0b10; //remap channel 1 on input 2 where ch2 is supposed to be by default
TIM1_IER = 0b10; //capture channel 1 interrupt
TIM1_CCER1 = 0b1; //enable channel 1 capture
TIM1_CR1 = 0b1; //start counter

also, if I remap channel one on ti 1 (pin 16) it still works (on channel one pin) but if I remap channel 2 on ti 1 it won't.
I need to get them both to work.
This part is wrong.
TIM1_CCER2 = 0b1; //channel 2 capture

TIM1_CCER1 is for channels 1 and 2.
TIM1_CCER2 is for channels 3 and 4.

What you need is this:
TIM1_CCER1 = 0b00010001; //channels 1 and 2 capture enable

Here is the link to the Reference Manual:
https://www.st.com/resource/en/refe...-8bit-microcontrollers-stmicroelectronics.pdf
 

jeffl_2

Joined Sep 17, 2013
73
You looked at the datasheet, not the RM0016 Reference Manual which is 467 pages.
You're right, because that's what Microchip (what I'm used to) links to on Digikey. But even a "dumbed-down" datasheet OUGHT to include sufficient detail to show all the relevant control bits, just maybe leave off the space-hungry diagrams and descriptions. Maybe that's why ST parts aren't nearly as popular, they don't make it as easy to find all the needed info.
 
Top