CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Get ticks

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
MJ



Joined: 25 Aug 2024
Posts: 5

View user's profile Send private message

Get ticks
PostPosted: Wed Oct 16, 2024 4:44 pm     Reply with quote

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: 19538

View user's profile Send private message

PostPosted: Thu Oct 17, 2024 2:12 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Oct 17, 2024 7:48 am     Reply with quote

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: 1354

View user's profile Send private message

PostPosted: Thu Oct 17, 2024 10:48 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Nov 22, 2024 2:36 am     Reply with quote

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: 19538

View user's profile Send private message

PostPosted: Fri Nov 22, 2024 2:54 am     Reply with quote

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.

Very Happy
MJ



Joined: 25 Aug 2024
Posts: 5

View user's profile Send private message

PostPosted: Fri Nov 22, 2024 3:32 am     Reply with quote

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: 9243
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Nov 22, 2024 10:31 am     Reply with quote

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: 1354

View user's profile Send private message

PostPosted: Sat Nov 23, 2024 7:40 pm     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group