| View previous topic :: View next topic |
| Author |
Message |
MJ
Joined: 25 Aug 2024 Posts: 5
|
| Get ticks |
Posted: Wed Oct 16, 2024 4:44 pm |
|
|
Hi chaps, I'm new to CCS and am getting congrats with the built in functions.
How does the get-ticks() and set_ticks() functions work and how is it related to the timer ticks and the size of the bits in te timer setup. Does it process overflows etc or does it simply return the relevant timer value. I've looked at the manual but am a little confused. |
|
 |
Ttelmah
Joined: 11 Mar 2010 Posts: 19962
|
|
Posted: Thu Oct 17, 2024 2:12 am |
|
|
It returns a timer count, based on the size of timer counter you have specified
in the #USE TIMER setup. This is explained in the #USE TIMER manual entry.
It is a 'ticker', based on a hardware timer, rather than the timer itself.
The default if you don't specify a BITS= value in the #USE, is a 32bit value. |
|
 |
MJ
Joined: 25 Aug 2024 Posts: 5
|
|
Posted: Thu Oct 17, 2024 7:48 am |
|
|
| Thanks, the manual still doesn't clearly explain how the function works. I tested it with the ICD and understand how it functions now. |
|
 |
jeremiah
Joined: 20 Jul 2010 Posts: 1401
|
|
Posted: Thu Oct 17, 2024 10:48 am |
|
|
| MJ wrote: | | Thanks, the manual still doesn't clearly explain how the function works. I tested it with the ICD and understand how it functions now. |
I would definitely suggest you give that feedback to CCS via their support email ( support@ccsinfo.com) so they can improve the docs. However, I would recommend you be more specific. The phrase "doesn't clearly explain how the function works" is really unclear and in-specific. Like what part wasn't clear specifically?
On my end it seemed clear. Here was my train of thought. The manual entry for get_ticks() says:
| Quote: |
Returns the current tick value of the tick timer. The size returned depends on the size of the tick timer
|
That seemed pretty straight forward to me. It returns the current tick value of the tick timer and the size is based on the size of the timer.
It then provides a link to the tick timer section (#USE TIMER) which says
| Quote: |
This directive creates a tick timer using one of the PIC's timers. The tick timer is initialized to zero at program start. This directive also creates the define TICKS_PER_SECOND as a floating point number, which specifies that number of ticks that will occur in one second.
|
This explains how the tick timer is implemented (using a PIC timer), what it is initialized to and even provides some info on predefined related values.
I guess at this point, the only unknown is what a tick timer is, but that is a general embedded programming topic and not really CCS specific, so if that is the part that is unclear, then that just comes with experience working in embedded (regardless of the compiler).
Maybe you could highlight what parts weren't explained well? It helps with improving the documentation to have specific things to target. |
|
 |
MJ
Joined: 25 Aug 2024 Posts: 5
|
|
Posted: Fri Nov 22, 2024 2:36 am |
|
|
| wow, are you normally this condescending to new users? Not everyone is a pro coder using CCS. The functions don't explain how the tick timer is incremented and updated. |
|
 |
Ttelmah
Joined: 11 Mar 2010 Posts: 19962
|
|
Posted: Fri Nov 22, 2024 2:54 am |
|
|
Actually they do.
The point is you have to read all the parts together. So #USE TiIMER, says:
This directive creates a tick timer using one of the PIC's timers. The tick
timer is initialized to zero at program start. This directive also creates the
define TICKS_PER_SECOND as a floating point number, which specifies that
number of ticks that will occur in one second.
So it is saying that this uses a PIC timer.
You then have:
TICK=xx - Sets the desired time for 1 tick. xx can be used with
ns(nanoseconds), us (microseconds), ms (milliseconds), or s (seconds). If
the desired tick time can't be achieved it will set the time to closest
achievable time and will generate a warning specifying the exact tick time.
The default value is 1us.
So it is using a PIC timer, and it sets the rate it advances as close as
possible to what you ask, or tells you what it has used.
This is common throughout coding, that you must look at the other sections
referenced by what you are looking at. The references are there for a good
reason.
Also, generally look at the examples. These are really 'part' of the manual.
 |
|
 |
MJ
Joined: 25 Aug 2024 Posts: 5
|
|
Posted: Fri Nov 22, 2024 3:32 am |
|
|
Thanks, that's a really good explanation. I know how the PIC works, I have been using them for decades in assembly and basic compilers. It doesn't specifically state how it is physically incremented by the function or how the function works; it was my understanding or confusion at the time that I struggled with. In any case, the documentation in comparison to other compilers is quite challenging to interpret, especially if you are not a C coder, but I understand that this is not a fault of the compiler and over the last few months I have learnt CCS very well, it still differs from other compilers in that it is heavily function based where the compiler does pretty much everything and this is new for me.
It was also not easy to read the examples at the time as I did not fully understand the C syntax, and the fact that CCS uses its own non-ANSI functions, etc.
I now understand how it works and have come to like the compiler libraries. As a newbie to CCS, having not used C but fully understanding the MCU architectures, it's quite a learning curve to one, learn C, and, secondly, get to grips with a new compiler that is heavily function-based rather than having to generate libraries yourself.
I was going to post two new SSD1306 libraries. One that is even more compact than the one you provided using a smaller font table and a math zoom function for font, with very little Ram using Page memory writes for speed and a second that is double buffered with bitmap, sprite manipulation for battery, wifi symbols, animation that are a breeze to create and manipulate from ROM, external memory or USB, curves, circles, lines, boxes, and text that runs at >300FPS (little overclocking as I was forced to 12M SPI from the USB HW). I don't think I'll bother now.
Appreciate the explanation |
|
 |
temtronic
Joined: 01 Jul 2010 Posts: 9587 Location: Greensville,Ontario
|
|
Posted: Fri Nov 22, 2024 10:31 am |
|
|
One of the reasons I bought PCM ( V2.453 ish..) WAS the extensive 'libraries' or 'functions'. Didn't know squat about 'C' ,so having them allowed for fast progress.
Another nice thing is that you can dump the listing and SEE all the machine code the compiler generates. In most cases it's very efficient at doing 'stuff'.
Going from Assembler to C was a challenge but using CCS's examples really helped !
Can the documentation be better ? Of course,but with 100s of functions, 1,000s of PICs, you'd have to employee a team of 10-12 JUST to keep up with the new peripherals and features today's PICs have !
I suggest you do post your programs in the 'code library'. Maybe you've got a clever bit of code others can use. |
|
 |
jeremiah
Joined: 20 Jul 2010 Posts: 1401
|
|
Posted: Sat Nov 23, 2024 7:40 pm |
|
|
| MJ wrote: | | wow, are you normally this condescending to new users? Not everyone is a pro coder using CCS. The functions don't explain how the tick timer is incremented and updated. |
Sorry, I definitely wasn't meaning to be condescending. I was trying to explain it through my own train of thought (going step by step, kind of a stream of consciousness style). Apologies that it came across so poorly. I'm not the best with words.
One of the reasons I was suggesting that you give some of this feedback to CCS directly is it really helps to get a new user perspective for their documentation. I was very serious, not trying to be snide or anything. |
|
 |
scanan
Joined: 13 Aug 2004 Posts: 82 Location: Turkey
|
|
Posted: Thu Oct 23, 2025 12:41 am |
|
|
Hi,
from the ccs help
TIMER=x - Sets the timer to use as the tick timer. x is a valid timer that the PIC has. Default value is 1 for Timer 1.
TICK=xx - Sets the desired time for 1 tick. xx can be used with ns(nanoseconds), us (microseconds), ms (milliseconds), or s (seconds). If the desired tick time can't be achieved it will set the time to closest achievable time and will generate a warning specifying the exact tick time. The default value is 1us.
BITS=x - Sets the variable size used by the get_ticks() and set_ticks() functions for returning and setting the tick time. x can be 8 for 8 bits, 16 for 16 bits or 32 for 32bits. The default is 32 for 32 bits.
ISR - Uses the timer's interrupt to increment the upper bits of the tick timer. This mode requires the the global interrupt be enabled in the main program.
NOISR - The get_ticks() function increments the upper bits of the tick timer. This requires that the get_ticks() function be called more often then the timer's overflow rate. NOISR is the default mode of operation.
STREAM=id - Associates a stream identifier with the tick timer. The identifier may be used in functions like get_ticks().
DEFINE=id - Creates a define named id which specifies the number of ticks that will occur in one second. Default define name if not specified is TICKS_PER_SECOND. Define name must start with an ASCII letter 'A' to 'Z', an ASCII letter 'a' to 'z' or an ASCII underscore ('_').
COUNTER or COUNTER=x - Sets up specified timer as a counter instead of timer. x specifies the prescallar to setup counter with, default is1 if x is not specified specified. The function get_ticks() will return the current count and the function set_ticks() can be used to set count to a specific starting value or to clear counter.
I am a bit confused with the ISr issue
can anyone explain it.
cheers _________________ Dr Suleyman CANAN
R&D Electronic Engineer
https://suleymancanan.wordpress.com
Do whatever you do with amateur spirit -
But always feel professional. |
|
 |
Ttelmah
Joined: 11 Mar 2010 Posts: 19962
|
|
Posted: Thu Oct 23, 2025 1:06 am |
|
|
The low part of the ticks value is from the hardware timer. Problem is
how do you generate the high part of the value?. Two methods:
If the tick access functions are being called frequently enough, you
can update a high value when these 'see' that the low value has wrapped.
Or you need a timer ISR, so when the timer wraps, the upper bits can be
updated. |
|
 |
asmallri
Joined: 12 Aug 2004 Posts: 1659 Location: Perth, Australia
|
|
Posted: Thu Oct 23, 2025 3:13 am |
|
|
| MJ wrote: | | wow, are you normally this condescending to new users? Not everyone is a pro coder using CCS. The functions don't explain how the tick timer is incremented and updated. |
I sniggered to myself when I saw you reply to Jeremiah. Welcome to the forum but you defintely overreacted to someone trying to help you. _________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!! |
|
 |
scanan
Joined: 13 Aug 2004 Posts: 82 Location: Turkey
|
|
Posted: Fri Oct 24, 2025 4:15 am |
|
|
| Ttelmah wrote: | The low part of the ticks value is from the hardware timer. Problem is
how do you generate the high part of the value?. Two methods:
If the tick access functions are being called frequently enough, you
can update a high value when these 'see' that the low value has wrapped.
Or you need a timer ISR, so when the timer wraps, the upper bits can be
updated. |
Would you give an example for the two methods _________________ Dr Suleyman CANAN
R&D Electronic Engineer
https://suleymancanan.wordpress.com
Do whatever you do with amateur spirit -
But always feel professional. |
|
 |
Ttelmah
Joined: 11 Mar 2010 Posts: 19962
|
|
Posted: Fri Oct 24, 2025 9:20 am |
|
|
Just use the interrupt approach. Better, safer, easier.
All you have to do is have the ISR setting in the setup, and
enable_interrupts(GLOBAL); near the start of the main code.
The polled handing is only reliable, if you are calling the tick testing
functions several times for every loop of the timer. |
|
 |
|