cancel
Showing results for 
Search instead for 
Did you mean: 

Encoder mode with LOW POWER TIMER 1

shingadaddy
Senior
Posted on June 16, 2017 at 00:32

STM32L476

I can't seem to glean the needed settings from the RM0351 rev 5 to get this to work like I thought it would.

It seems to somewhat work but I can't get any counting to happen with transitions on input 1 (PC0). Can someone

tell me if you've been there / done that with low power timer 1? I have 3 others running with the general purpose

timers but this one stumps me.

I DO see where you tell it what EDGES you want to trigger on. I DONT clearly see where you tell it you want to

trigger on both edges of either input 1 (PC0) or input 2 (PC2)... Looks like someone tripped over and spilled

the bit assignment bucket.

Any help greatly appreciated.

I also have this in as a tech support question but as yet..... Just ASSIGNED --- No bites.

Is it me or does the Lower power documentation seem a little thin?

:\

3 REPLIES 3
shingadaddy
Senior
Posted on June 16, 2017 at 16:41

0690X00000603t9QAA.jpg

Really ODDBALL results. Like this setting gets me a count change on the falling edge of PC0 ( YES input 1)  --- ONLY IF PC2 is LOW (One direction ??????)

This PCB is buried in an assembly so I cant see the top side of it at all. Think I'll try this on one that's not mounted and maybe this one has a solder blob on it in an aggravating spot....If you see a register setting that looks wrong, please don't hold back! They use the terms CLOCK, and Trigger and EXTERNAL INPUT and prescaler in so many questionable contexts that its difficult to sort out what conditions/settings are associated with what signal / pin and the encoder function itself. I figured if the thing was in ENCODER MODE (Like the register shows) then the device should be able to produce the count as shown in the RM0351.

Here I've been tinkering with BIT EFFECTS so yeah CKSEL is a 1 and the manual says in a CAUTION NOTE at the bottom of page 1156 ''CKSEL bit must

be maintained to its reset value which is equal to ?0?.

Than you have THIS:

Bit 0

CKSEL

: Clock selector

The CKSEL bit selects which clock source the LPTIM will use:

0: LPTIM is clocked by internal clock source (APB clock or any of the embedded oscillators)

1: LPTIM is clocked by an external clock source through the LPTIM external Input1    ( ? )

I assume this timer is doing some CAPTURES based on the APB ''clock'' that I have selected as its ''CLOCK'' clock.

LPTIM external Input1 ? That nounage looks like one of the encoder leg INPUTS to me.

I have yet to get it to do THIS:

0690X00000603tDQAQ.jpg

Yes I have looked (SCOPE) at this encoders output. THIS ONE is as shown in the above diagram with 1 leg change per click.

Timer 2 and 3 are happy with this same signal.

Some of the OTHER encoders I have seen will put out a full cycle of quadrature signal (  2 up- 2 downs ) on each leg per click.

THAT was a surprise....   :\

I want it to work as the diagram shows. A COUNT CHANGE on EVERY EDGE..

I have another board now. Putting things back as the manual *vaguely* suggests.

More after lunch..

shingadaddy
Senior
Posted on June 16, 2017 at 21:05

Good grief...

0690X00000603t3QAA.jpg
Posted on June 29, 2017 at 18:01

Um. Sorry meant to get back to here for results.

In the device, it was a TOO CRAMPED area causing a wire connection to be iffy. While chasing that - before I found the WIRE issue -  while flying low through the code knowing full well I WAS NOT USING THE ULTRA LOW POWER CLOCK to CLOCK the LP 'TIMER'  in encoder mode, I find this little

UltraLowPowerClock

curveball.

HAL_StatusTypeDef

HAL_LPTIM_Encoder_Start_IT(

LPTIM_HandleTypeDef

*hlptim,

uint32_t

Period)

{

HAL_StatusTypeDef

status =

HAL_OK

;

uint32_t

tmpcfgr;

/* Check the parameters */

assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));

assert_param(IS_LPTIM_PERIOD(Period));

assert_param(hlptim->Init.Clock.Source == LPTIM_CLOCKSOURCE_APBCLOCK_LPOSC);

assert_param(hlptim->Init.Clock.Prescaler == LPTIM_PRESCALER_DIV1);

assert_param(IS_LPTIM_CLOCK_POLARITY(hlptim->Init.UltraLowPowerClock.Polarity));

/* Encoder feature is only available for LPTIM1 instance */

if

(hlptim->

Instance

== LPTIM1)

{

/* Set the LPTIM state */

hlptim->

State

=

HAL_LPTIM_STATE_BUSY

;

/* Configure edge sensitivity for encoder mode */

/* Get the LPTIMx CFGR value */

tmpcfgr = hlptim->

Instance

->

CFGR

;

/* Clear CKPOL bits */

tmpcfgr &= (

uint32_t

)(~LPTIM_CFGR_CKPOL);

/* Set Input polarity */

tmpcfgr |= hlptim->

Init

.

UltraLowPowerClock

.

Polarity

;

So yeah, those

UltraLowPowerClock tidbits make for interesting (time wasting) CHASING. :\

Low power timer working in encoder mode.