- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Quadrature Decoder function SetCounter() does not accept negative values (positive values are fine).
Example:
QuadDec_SetCounter(-1); //can't set counter to a negative value
sprintf(strMsg1,"counter_val=%d \r\n", QuadDec_GetCounter() );
SW_Tx_UART_PutString(strMsg1);
reading counter value in the above example returns -32767.
What I want is to limit counter values to some bounds, e.g. -100...+100.
Regards,
odissey1
QuadDec_v2_30 (16bit)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Is -1 in the compiler considered a byte, long,.......?
If you are using a 32 bit counter should it be -1L in the function argument.
I am weak here in C, but fact you are returning an int makes me wonder if -1
argument was taken as a long ?
Help.......
Regards, Dana.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
How about
QuadDec_SetCounter((int)-1);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I did not check yet if there are differences between the PSoC4 and the PSoC3/5 implementation, talking about PSoC4:
What size (width) did you specify? 16 or 32bits? I bet 32.
How is the target (you read the counter into) declared? 16 or 32bits? I'm sure 16.
On the other hand: a 32bit integer cannot be converted to string with "%d"-format that will accept (and assume) only 16bit integers.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Concerning formatiing and variadic f()'s like printf()/sprintf() -
http://www.codingunit.com/printf-format-specifiers-format-conversions-and-formatted-output
Also shows promotion/conversions being made by f().
Regards, Dana.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I do it like that (should work according to datasheet, but it doesn't):
int16 counter_val;
counter_val = -10;
QuadDec_SetCounter(counter_val); //BUG: can't set counter to negative value
odissey1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Astonishingly there seems to be something wrong with the 16bit wide QuadDecoder. As a workaround use the 32bit wide, I checked that it works on a PSoC5LP
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I tested it with 8-bit QuadDecoder before with same error (but not 32bit).
odissey1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If that is the case, it is best to post a case to Cypress support.
I might also look at the listing to see what is output of the compiler.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I already informed Cypress (yesterday) but no response yet (2:00 am PST )
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In continuation of the dicussion, QuadDecoder has a rollover issue (IMHO). For example 8-bit encoder counter going up like that: (maximum of 127 is not reached and counter flips to 0):
0,1,...,126 -> (rollover) -> 0, 1...
while I expected it going upto 127 and then rolling over to -128, like that:
0, 1, ..., 126, 127 -> (rollover) -> -128, -127,...,0
Similarly, 8-bit counter goes down like that:
0,-1,....,-127 ->(rollover) ->0,-1...
When it would rather expected to roll over to max positive value like that:
0,-1,...,-127, -128 -> (rollover) -> 127, 126, ...,1, 0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Current workaround setting negative vounter value
int16 counter_val;
counter_val = -10;
QuadDec_SetCounter(32768-counter_val));
odissey1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I havn't use the quarture decoder before, but would the sign of the counter in this case indicates the relative phase of A and B?
But The rollover counter value is stange and needs to be address.