What timers and other hardware are fully availabe using peeksfr, pokesfr etc?

Morganl

Senior Member
I want to have full control of a timer that can do pulse width measurement.
Such as the timer 1/3/5 in 28X2 / 40X2
See http://ww1.microchip.com/downloads/en/DeviceDoc/41412F.pdf
page 163 : " 12.0 TIMER1/3/5 MODULE WITH GATE CONTROL "

I guess PICAXE timer 3 is PIC timer 3, right?

Is any other PICAXE functionality dependant on timer3?

Generally it would be interesting to know what timers are available!
There are 3 more timers in PIC used for 28X2 and 40X2 than in 20x2.
So i guess timer 4,5,6 are not used by PICAXE.
Can i freely set them up or are they blocked by something?

Is there some other hardware in 28X2, 40X2 not controlled by PICAXE that we can utilise if needed?
I am guessing CAPTURE/COMPARE/PWM MODULES for timer 3 and 5 ?

Anything else?
There are quite a lot onboard the PICs - let us use it :)

(Trying to use PICAXE for a lot of projects hoping not needing to switch language)



______ What I want to do right now:
Decode a standard radio control pulse stream;
One long pulse for sync, then eight pulses one for each servo 1..2 ms long, with a quarter ms or so between, total cycle time about 20ms.

Given: The PIC chips timer 1/3/5 have hardware to measure pulsewidth standalone :)
I hope PICAXE do not get in the way.

Requirement: I want to use a PICAXE 40X2, and at the same time have servo outputs enabled thus timer 1 is reserved for servo.
I already have a program framework (in development) to execute a bunch of small routines in round robin coopreative multitasking loops of different speed and priority.

Idea, course algorithm:
1) Configure timer, stop it, clear.
2) wait *a) for low level *c), then enables timer to count while input is high.
3) wait *a) for timer to stop *c) (TMR3GIF bit)
4) read timer, evaluate *b),
go to 1

*a) some frequently executed task, or loop in place, or PICAXE interrupt
*b) is it within range? is it a sync pulse?
*c) optionally also check sanity against a timeout timer to detect noise and missing signal conditions
 

Technical

Technical Support
Staff member
All the timers are used within the PICAXE firmware for various different commands.

As general examples timer 1/2 is used for maintaining servo commands, timers 2,4,6 are used within PWMout and timer0 is used as a general purpose 'timeout' device in various commands.

Timer1 and timer3 are the only ones we recommended are used for general purpose, via the specific BASIC commands that are already provided to use them.

In theory, if not using a command that uses a particular timer, you could use it yourself via pokesfrs's. But we don't recommend/support this - so only do it if you are happy to study the PIC datasheets in detail yourself!
 

Morganl

Senior Member
@srnet:
Grabbing head movement signals from FatShark video glasses, for operator to control cameras on a machine to see the tool and object some meters from him where he can not be. Can not say more unfortunately. The output is a such pulse train, compatible with some RC controls.

Yes i know it would be much easier (at lest for me) to use a couple CMOS 4000 cirquits and RC servos, or solve this using assembly which i used on PIC 15 yeras ago... but i have already decided to have a 40X2 in the panel for other purposes and integrating is more beautiful...

@technical:
a) you did not mention timer 5 ?
b) timer 4, 5 and 6 do not exist on 20X2 hardware. Are you really ever using them in PICAXE?
 

Morganl

Senior Member
Related: manual 2, page 269: It say 28X2 have 4 pwmout channels, but 40X2 only 2. Is that correct?

I found it strange as you link the PIC18(L)F2X/4XK22 datasheet to both,
so the 40 pin have same silicon and should have same pins but more connected than the 28 pin device.
Maybe the manual is not updated since some chip change?
 

Technical

Technical Support
Staff member
Related: manual 2, page 269: It say 28X2 have 4 pwmout channels, but 40X2 only 2. Is that correct?
I found it strange as you link the PIC18(L)F2X/4XK22 datasheet to both,
On early 40X2 chips, yes.
Tip for you - when reading Microchip datasheets make sure you read the (separate) errata datasheets carefully as well. Twice at least. Saves lots of headaches.

Different chips have different timers and allow for different possibilities. For instance 20M2 can have different PWMout ratios on different pins, 20X2 can not. This is because of the extra timers.
 

Morganl

Senior Member
( Sorry for being such a PITA, but i really hate when not knowing what strikes later ;) )

Do you mean early X2 can do 4 pwm out, and the current 4 pwm, and the current use timer 2,4,6 for that?

Then what chip is 20X2, the data sheet you link say it do not have timer 4 nor 6.

Please, when updating manual 2, could you in that section indicate which chip is used for which PICAXE?
And also make sure http://www.picaxe.com/What-is-PICAXE/PICAXE-Chip-Labels/ is correct.

Yes, i will read the errata before fiddling with the registers:)
Before spending much time with the chip docs i just wanted to make sure if at least timer 5 is free to use (or in what cases i can not use it), and i still have not recieved a clear answer...?

So far i have not seen any mention by you nor a manual that timer 5 is used for anything. Correct?
I understand it shares some configuration with other hardware so i intend to set up everything i should use with PIXACE inbuilt commands first using the PICAXE configuration commands, then change just the relevant bits i need to change.

One thing i like about Microchip is the errata documents. The other the detailed data sheets. Third is the long production and support time.
Despite that we also stumbled on a nondocumented error in an early PIC14000, and a nasty half known second level interrupt in an PIC18F variant.
But Microchip is better to talk to then than others just denying it (Maxim MAX110 entering uninterruptable unducumented self test, Linear LTC2400 early revision shifting out wrong data in certain cases) such things really can break deadlines!

While speaking of Errata,
How can we tell which PIC chip revision a PICAXE is?
I guess 40X2 is PIC18F45K22 at latest revision, A5.
And i guess you implement workarounds for any defects (i.e sync serial bug in this A5 chip), or else tell us?


BTW, in "Appendix 4 - Possible Conflicting Commands"
timers 1,2,3 are mentioned, no other timer.

Oh and the PICAXE timer interrupt flag toflag, is it generated with timer3?
See manual 2 page 14. Should be specified.

Sincerely
/Morgan
 

Technical

Technical Support
Staff member
As you have already seen, the raw chip features vary, even within a series, e.g. a 20X2 does not have same features as a 40X2. So we can't say 'timerX is used for' because, quite simply, it varies considerably between each PICAXE part. However all timers are all used as available.

PICAXE is designed to avoid all this information by providing simpler BASIC commands. The technicalities behind the scenes are hidden, quite deliberately.

As already stated, if you want to peek and poke any of the timers you are completely on your own - it is not recommended as you may disrupt PICAXE firmware operation.

readsilicon and readfirmware tell you about the 40X2. The silicon version will be based upon what Microchip supplies, this may not be the latest documented, there is often several months between silicon revisions and when they actually hit the streets. If a particular silicon version has an issue there is generally very little that can be done about it.

You can see the PICAXE firmware revisions on the product page e.g.
http://www.picaxe.com/Hardware/PICAXE-Chips/PICAXE-40X2-microcontroller/

toflag operation is documented here
http://www.picaxe.com/BASIC-Commands/Advanced-PICAXE-Configuration/settimer/
http://www.picaxe.com/BASIC-Commands/Interrupts-and-Multi-Tasking/setintflags/
 

Morganl

Senior Member
Thanks for the info. Great :)
Yes i know the idea is to simplify, and you do a good job at it, really :)

However there are really capable peripherals on the chip and they can automatically in hardware do many things you do not provide commands for, but is very good documented by Microchip.

I see no reason not to extend the Manual 2 chapter "Appendix 4 - Possible Conflicting Commands"
with some info about what peripherals are available to control directly depending on what PICAXE commands are used.
(Right now it only say it ever use Timer1, 2, 3, and some other hardware, not a mention on any other timer, so i just assumed 4,5,6 was "free")

That really would extend the application field of your products :)
both as a learning tool to begin fiddling with hardware directly,
and for real products.

Getting less general, and now specific:
If i on 28X2 or 40X2 in PIXAXE basic use servo and timer3 functions, they use timer 1, 2, 3.
No PWM or other timer commands. Then all microchip timer blocks 4,5,6 are free?
 

srnet

Senior Member
I see no reason not to extend the Manual 2 chapter "Appendix 4 - Possible Conflicting Commands"
with some info about what peripherals are available to control directly depending on what PICAXE commands are used.
Could get complicated, especially having to take account for the hardware differences between different PICAXEs.

Maybe Rev Ed just dont want to end up supporting the (advanced) programming of the native PIC ?
 

Goeytex

Senior Member
The Picaxe platform was designed to eliminate the need for setting up registers and directly using timers or other peripherals. Even though there is access to certain SFRs, via peeksfr & pokesfr, I think it is somewhat unreasonable to expect the folks at Rev_ED to support this beyond a minimal level.

It seems to me that you just need to get a few different Picaxe chips and start poking around. In any case you will still have to deal with the added processor overhead of On-Chip Interpreted Basic when using a Picaxe.

With Picaxe / Picaxe Basic, you will never get remotely close to the 125ns instruction cycle of a native PIC using compiled code. While internally the PIC is executing instructions at full speed, each Picaxe command must be interpreted first. This takes on the order of 30us - 250us depending upon the Picaxe and the processor speed. So, for example, when the Picaxe Basic program pointer gets to <Poke reg,val> it will take at least 30us (@ 64Mhz Clock) before the register is actually written and any change takes effect. Same with any Picaxe Basic command. For example, let a = b + c will take ~ 25us before a result is returned, and this is with a X2 Picaxe that can operate at 64MHz. Also, floating point math is not supported, only unsigned 16 bit integers. Will this be acceptable with your intended application?

With your application requirements and seemingly apparent knowledge of PICs, I wonder why you aren't programming in C or even in Assembler with a native PIC. Why a Picaxe with interpreted BASIC?
 

Technical

Technical Support
Staff member
It is not about supporting.
Just tell what parts are not used in some circumstances.
You seem to have missed our earlier replies:

In theory, if not using a command that uses a particular timer, you could use it yourself via pokesfrs's. But we don't recommend/support this - so only do it if you are happy to study the PIC datasheets in detail yourself!
As already stated, if you want to peek and poke any of the timers you are completely on your own - it is not recommended as you may disrupt PICAXE firmware operation.
 

Morganl

Senior Member
My point is that having known access to the hardware makes PICAXE feasible in more applications.
IMO RevEd should be interested in reaching wider application, teachers taking studens a step further, enhusiasts to be able to make more use of a device they already know, and people like me who must do many other technologies than just programming and cirquitry save time by not needing to learn another tool.

In this case speed of PICAXE is more than enough, *if i just can capture the pulse lengths*, and that the hardware timer 1/3/5 can do by itself, i just need to set it up then occasionally poll a bit flag.

On a personal level it was yeras since i wrote a PIC assembly program. Sure i can do it again. I* wish to learn to combine it with C, pracitse more C, learn Python, more PLC languages... But time is limited... At the moment it is quicker to just set some bits in some registers.
Also, I am educating my son, and sometimes i work as a teacher, and Basic is a good standard language usable on low cost PICAXE, high end PLCs, DOS, Linux, Windows, Android...
 

Morganl

Senior Member
You seem to have missed our earlier replies:
I have no problem to control the hardware myself. Microchip documentation is very good.

The part "you may disrupt PICAXE firmware operation." is about missing information in YOUR documentation.

So users know where not to fiddle.

But either you do not want to tell, or dont understand me.
 

lbenson

Senior Member
Personally, I would rather see Rev-Ed spend its time developing improvements for the broad picaxe community than in documenting behind-the-scenes implementation details that vary from chip to chip for the benefit of very few users.
 

Morganl

Senior Member
Yes, maybe the implementation is very convoluted.

When i started the thread i actually thought it could just take techincal a couple minutes to say something like "if you do not set up PWM, timer 5 is not used"

Measuring pulse width or frequencies is far from uncommon, and as the hardware is present i see no reason not to give way to use it.

I have seen threads in the forum where users struggle to do things than can be better used by the already provided hardware.

And i do believe many users can find use for it, and easily, if the *existing* documentation of what commands cannot be used simultaneously, was just *a bit more detailed* to also include when more hardware is not used.

Well, i will take a shot at the application i described in my first post later, and if i get something working i will post back.
 

RexLan

Senior Member
I have no problem to control the hardware myself. Microchip documentation is very good.

The part "you may disrupt PICAXE firmware operation." is about missing information in YOUR documentation.

So users know where not to fiddle.

But either you do not want to tell, or dont understand me.
Perhaps you are looking in the wrong place and should find a
"Microchip" site to implement your dream project instead of trying to back-door a Picaxe to fit ??

Just a thought
 

srnet

Senior Member
And i do believe many users can find use for it, and easily, if the *existing* documentation of what commands cannot be used simultaneously, was just *a bit more detailed* to also include when more hardware is not used.
I suspect that Rev Ed want to have the freedom, when writing firmware, to be able to use the various parts of the native PIC as they see fit without having to check compatibility against a list of 'its safe to use' stuff, so they dont print it.
 

Morganl

Senior Member
I suspect that Rev Ed want to have the freedom, when writing firmware, to be able to use the various parts of the native PIC as they see fit without having to check compatibility against a list of 'its safe to use' stuff, so they dont print it.
That is a valid concern, although i think it could be easy to have a plan, (but i do not know huw the system looks like)
And to update related info when new functions are implemented.

I think they will never need 6 timers to do a couple timing tasks.


Rethinking, i could do without using PICAXE timer3 commands, and as per documentation timer 3 is never colliding with anything, so i presume i can use it freely?
 

srnet

Senior Member
That is a valid concern, although i think it could be easy to have a plan, (but i do not know huw the system looks like)
And to update related info when new functions are implemented
Well, I would assume Rev Ed understand the firmware far better that we do, so if they are not saying, its either not easy or there is a compelling reason for not going down that route .....
 

Morganl

Senior Member
Rethinking, i could do without using PICAXE timer3 commands, and as per documentation timer 3 is never colliding with anything, so i presume i can use it freely?
Spinning further on that idea and trying to get constructive; making improvement to both worlds:

If RevEd implement a timer5 function working like a copy of the current timer3
(possibly not much work, much reuse of code and documentation)
Also update what they are compatible with, and which chip supports it.

Then

1) basic-only users have more functionality

2) when not using them or their respecitvely incompatible in PIXACE basic, they are presumably free to control by SFR
 

Morganl

Senior Member
Gotta hand it to you, Morganl. You don't give up easy.
:)
Actually i am just following RevEds own suggestion, in manual 2, about peeksfr:
"The peeksfr command is for experienced users to study the internal microcontroller SFR"
And about pokesfr:
"The pokesfr command is for experienced users to adjust the internal
microcontroller SFR (special function registers).
Only SFRs associated with peripherals (e.g. ADC or timers) may be accessed."


So you suggest to use it for i.e timers, which is what I do intend.
A very natural requirement in order to learn from such experiments it to also know what are used by the system already, what we should not touch.

Sidenote: For full use some functionality need to atomically set or clear a single bit.
Example: i wish to clear the timer5 overflow flag, but it is in same byte as the overflow flags for timers 4 and 6.
If i do it like read byte to variable, clear bit in the variable, write back, i wil overwrite any changes in the bits i shoud not touch.

So for better control of peripherals I would add two simple commands to a wish list:
setbitsfr, clearbitsfr


And/or the user in this case need to know when system use timer 4 and 6.

So if not much work, why do you think they have not already done it ?
Maybe they did not think of it this way.
Other people make good suggestions to improvements of my designs too.
 
Top