Timing very confused!

Tesla

Member
Also very confused!

Hi there

This is my first post on Timers, but after the bet possible option for taking timings in ms, is this possible in a simple way?

Also could someone enlighten me how to start a new thread on this and my apologies for posting in the wrong place if I am.

I have read the site and come across many different way of timing, Timer, settimer, Timer 3, external crystals, ect. .

I have the 28x2 5V modules.

I am not a complete beginner with picaxe as I have has a play around with remote control driving radio modules and everything worked like a dream after a lot of trial and errors.

What I am after is to take timings in ms over a max period of 6 seconds for a project I am working on.

I wish the timings to be consecutive

so example
PIN high. .. ..start timing and toggle pin back
T1=2123ms ' max timing for any timings I will be taking is 6000ms
Pin high again, stop T1, start T2
T2=1343ms
Pin high again, stop T2, start T3
T3=3421ms
Pin high again, Stop T3

Then I wish to do some maths operations on the variables T1,T2,T3

After I wish to generate some pulses of a predetermined length in ms

I believe that this is extremely simple using the pause statement. The length of the pulses would be between 100 to 1200 ms

so if I use for example
PAUSE 1285
then PIN5 high
pause 10
PIN5 Low

I would have a time period of 1.285 seconds, then a pulse for 10ms , am I correct?

If so, then why could the pause statement if so accurate be used as a timer for counting?

you know

do a=a+1
pause 1 ' would this not time 1ms
until pin 5 high ' press pin 5
debug pin5

for example?

I am totally confused as to why its so difficult to make a ms second timer?

any enlightening information would be much appreciated, and I have trawled the site and come across many different options and many different problems.

I know about the Major and Minor ticks, is this the best option?

So my parameters again or to take consec timings in ms no more than 6000 max
do some maths ( I can deal with that bit)
then pulse out a set pulse no more than 1200 ms say 3 times.

I don't expect anyone to do this for me, but after several months going over the board, and the documentation I am either thick and its staring me in the face, or its more complicated that i first assumed.

In return anyone wanting help with the infra red or radio modules linked to 08m, i have some code that works and links to modules that work.

I think that the Picaxes are amazing and really cool, programed only in basic before and C.

Regards

Marc

Als
 

hippy

Ex-Staff (retired)
Welcome to the PICAXE forum.

You can indeed do a simple timing loop like you suggest ...

Do
Pause 1
Inc counter
Loop Until pin5 = 1

The question is, how accurate do you need your timing ? As well as the nominal 1ms pause there will be the time taken to increment the counter, test pin5 and go round the loop as required. This means that you will end up measuring slightly short of the time things actually took.
 

Tesla

Member
Thanks Hippy

Thats much appreciated, I guess I would love to time as accurate as possible, but I guess I could use this method and maybe use a correction factor to bring it as close to real time as possible.

For what I want, I think this will give me some ground to work on, as I need a mathematical relationship of the data harvested, perform some calcs and spit out a pulse associated with the data.

It would be a perfect world if time taken would mimic pulse out, REAL WORLD TIME IS NOT AS IMPORTANT HERE, but the output values should be close to input values.
So pause 150
should be close to
Do
Pause 1
Inc counter
Loop Until Counter=150 ' for example.... ' pin5 = 1



I will report back with any interesting findings . I love the forum and the people that contribute, for me its like been in a sweet shop and everything is free!
Keep up the good work!:D
 
Last edited:

lbenson

Senior Member
The code you show is likely to take about twice as long as "pause 150" because of the time it takes to execute each picaxe statement. This is something on the order of 250 microseconds per instruction (at 4mHz), so the code for the loop may well take a millisecond in addition to the one millisecond pause you have.

In addition, depending on the accuracy you need, you may not be able to find a compensation factor which will work in all your operating conditions, since execution time varies with temperature.

If you need a high degree of accuracy, then a timed external interrupt may be needed. What degree of real-world accuracy are you looking for?
 

boriz

Senior Member
You want to measure three time intervals. Each delimited by a logic transition (event)?

1. You need to determine if the timer begins with a low-to-high transition or a high-to-low transition. EG: Start timer when 1 becomes 0, or start timer when 0 becomes 1. (start event)

2. Determine when the timer stops. Stop on a low-to-high transition or a high-to-low transition? (stop event)

3. Determine what it the minimum and maximum possible time between transitions. (event duration)

This information is crucial to constructing the software.
 

Tesla

Member
Thanks for the info guys, much appreciated

OK, Here goes for the EXACT requirements, as I was a bit vague before.

This is practically what I want, to time to around 1ms second accuracy, by

'parameters count in ms, max 6000ms for all values of timings'
' i know i would have probably toggle pin if using same pin after every key press, or use and interrupt method?
DATA GATHERING MODULE
pressing a button once> Start Timer T1
Press again> Start Timer T2 / Stop Timer T1 'assign to a variable'
Press again> Start Timer T3 / Stop Timer T2
Press again> Start Timer T4 / Stop Timer T3
Press again> Start Timer T5 / Stop Timer T4
Press again> Start Timer T6 / Stop Timer T5
Press again> Start Timer T7 / Stop Timer T6
Press again> Start Timer T8 / Stop Timer T7

DATA COMPUTATIONAL MODULE ; can do this bit myself!

Not sure of how many timings I need to start with, but 8 would be very good!

Then I do some maths operations on the data, I can do this, even though could do with floating point, will get round it no problem given enough time on it!:rolleyes:
//////////////////////////////////////////////////////////////////

USE MODULE, need help again on this!

So, on USE mode, I only need to take one timing, then kick out some pulses.

Press button> Start Timer T14 ' same sort of method as above!
Press button> Stop Timer T14
Then the program preforms the following>

I then need to do a computational operation and introduce this T14 into an equation and spit out a Time interval that would not exceed 2000ms
the Picaxe would then pulse out a high for say 3ms to 4 ms every 2000ms, or every 1340ms, whatever the answer is to the computational module.


Then I press the button again and the chip pulses out repeatedly just 8 times using a value that is computed from the Time interval T14.
so we have for example

T15= 1423 for example NOTE I would first take away pin high time, say 3ms
So T15 now becomes 1420

so we would have
Button press
pause 1420
pin 3 high ' so totals 1423ms original T15 timing
pause 1420
pin 3 high
Button press
pause 1420
pin 3 high ' so totals 1423ms original T15 timing
pause 1420
pin 3 high
Button press
pause 1420
pin 3 high ' so totals 1423ms original T15 timing
pause 1420
pin 3 high
Button press
pause 1420
pin 3 high ' so totals 1423ms original T15 timing
pause 1420
pin 3 high
Goto USE MODULE


THE END!

Other Criteria that is very important , is that the pulse out equates to the gathered data to within 1% accuracy would suffice.

I am just dumbfounded why PAUSE works to ms and is user friendly, simple to use, yet to do the opposite is really difficult it seems.

I suppose i have got lost in the myriad of different methods of taking timings and counting?

Could not the people that wrote The Pause statement write one for counting in Milliseconds that is simple to use.:rolleyes: PLEASE:)

also, I have played about with some of the code on this site, Ticks, major and minor, the other thing i did not get is that the simulator runs slower, as i watch the minor ticks, they cycle through to 255, if they cycled through to 100, it would be much simpler to play with, am I missing the obvious again here?

Thanks for all the input on this guys, its very much appreciated and hopefully in the future i can help others on this exact subject.

My apologies to Hippy, if i did not quite explain in details what I wanted.

Look forward to all your replies.

Also, a suggestion, would it be good to have a sample code section on different topics that showed several different methods for each problem, say for example with Timers. I have looked at the manual, but a complete bit of code would be useful for each method say stating accuracy of timing method etc. I know its a work in motion so to speak and thank everyone who writes at this forum, but taking the knowledge from the forum that is useful, say the conclusion to a thread, its probably been suggested before:p

Boriz, I mentioned above to toggle the pin back that i am using ..so its a good point you made, I noticed that I can reverse the state of a pin, and I guess after reading further for several hours that I timing interupt that Ibenson mentions would be the best option with external Crystal, say 1000 Mhz?

If any of you can shed any light how to go about this, it would be much appreciated.
 
Last edited:

Tesla

Member
digging deep

Ok guys

Found Timer 3 info, but go to run it, I assume that there is an error in the simulator, as it states first bit is incorrect. Does this need updating the programming editor?

Here is the code someone posted
#picaxe 28x2

main:
high b.7
tmr3setup %10000001 'timer3 on, 1:1

Do
if pinc.7 =1 then goto shutoff
Loop

Shutoff:
tmr3setup %10000000 'disable timer
low b.7 'turn off led
w0= timer3/31 'get int of time
'We need to convert time into single numbers for serial LED
if w0>10 then
w1= w0/10
w2 = w0 % 10
else
w1 = 0
w2=w0
end if
w3= timer3 % 31
if w3>10 then
w4= w3/10
w5 = w3 % 10
else
w4 = 0
w5=w3
end if

SerTxd( #w1,#w2,".",#w4,#w5, CR, LF ) 'Send out the numbers. Will convert to 7 segment serial LED string later

This looks like what I am after and can be built on ..

Regards
Marc
 

Radarman2

Member
Tesla, I've been trying to do a similar thing for a timing system I'm creating.
I went through the manual and calculated the timings and what the difference was between timer3 and settimer. Attached is the PDF I created.

Think the code is showing an error because you've stated the PICAXE is a 28X2, so the code should be:
tmr3setup %00000011 'Timer3 on, 1:1 prescaler
Think the first bit is set as 1 for the 28X2-5V. (see Manual 2 page 242 - the example code shows it on page 243)
As you'll see from the PDF, if you set the chip to 64MHz clock speed (don't think this is possible in the simulator) then the major tick will occur every 4.096mS.
For my purposes that isn't soon enough, I want 1mS or better. I've been testing SetTimer in external mode by PWMout on a 28X2 and feeding it back into itself, via a current limiter, to pin C.0 (timer clk).
By using:

pwmout pwmdiv16, PWMOutPin, 124, 1
Settimer count 65535 'Chip speed 32MHz

the 'Timer' variable increments at 1mS intervals (I've added ADC to the cct to be able to calibrate the PWM period). You obviously need to reset 'Timer' every time it counts to 1, but if you did a pause 1000 and then read 'Timer' you should see a count of 1000, pause 1500 then read 'Timer' should show 1500 and so on.

HTH a bit and if anyone sees any errors in my calculations please point them out (I know you will anyway :D )
 

Attachments

hippy

Ex-Staff (retired)
I've been testing SetTimer in external mode by PWMout on a 28X2 and feeding it back into itself
That's a good technique. You can clock the counters at a rate which means the counters give a directly useful value which correlates with a natural time period, or they can be clocked at any arbitrary rate and actual time calculated from the elapsed count.

It's probably worthwhile taking a look at the relevant PICmicro datasheets to get a feel for the timer hardware in-chip - they are really just free-running counters which increment every clock pulse, the PICAXE firmware sees the 16-bit count roll-over and increments the 'timer' variable. If you aren't particularly interested in using the 'timer' variable or having interrupt on 'timer' variable overflow you can PEEKSFR the two counter register bytes to see how much time has elapsed since the last reading. That's been the basis of all the high-speed or accurate timing things I've done.

For measuring a sequence of elapsed times, the best way I reckon is to set a timer / counter running, sample ( PEEKSFR, 'timer' or whatever ) and note the reading when whatever the action is occurs. Then go through the list of samples and determine 'this minus last' to find the time between each action. That's much easier and more accurate than starting and stopping the timer.
 

Tesla

Member
Thanks Radarman, I already came across your attachment actually and saved it, found it very useful and I had already got some similar data to yourself!

sound like we both require something similar!Hope we find it!:rolleyes:

And again thanks Hippy for your input on this, I had contemplated writing my own timing program by reverse engineering against a real clock and then adjusting as appropriate. NOT so easy without floating point maths I don't think. .

Well I feel a little less stupid anyway, I thought I was missing something obvious after spending so much time on here!

I did like your very accurate Timer Hippy that you did for the 20x2, a lot of code:eek:

I just hope I find a solution or create a solution soon. .

Any other input from anyone regards a simple timer that can count in ms to to 6000ms is appreciated ..

I might try another chip to do this, but like a challenge!:)
 

Tesla

Member
Hi Radarman

Radarman, you wrote>
For my purposes that isn't soon enough, I want 1mS or better. I've been testing SetTimer in external mode by PWMout on a 28X2 and feeding it back into itself, via a current limiter, to pin C.0 (timer clk).
By using:

pwmout pwmdiv16, PWMOutPin, 124, 1
Settimer count 65535 'Chip speed 32MHz

the 'Timer' variable increments at 1mS intervals (I've added ADC to the cct to be able to calibrate the PWM period). You obviously need to reset 'Timer' every time it counts to 1, but if you did a pause 1000 and then read 'Timer' you should see a count of 1000, pause 1500 then read 'Timer' should show 1500 and so on.
So , looking at what you have just written, means that you have a counter that can count to 1 millisecond accuracy? WOW! So you are feeding the PWM back into the chip?

So how would I utilize your hardware setup, any pics or info would be appreciated.

Now this sounds interesting .. .:D

Marc

Also, how would I measure a timed period and pass this on to a variable?
 

Radarman2

Member
Tesla,
when I get a chance, i.e. the rampaging tornado that is an 11month old who is learning to walk is having a nap I'll try and upload a simple diagram and some code.
 

Tesla

Member
:p

If anyone is going to achieve and do something in life, they will more than likely do it before they have children or after they have left home at 18!
(author- George Bernard Strutt)

My Grandfather!!! :D

So I know where you are coming from Radarman, speaking from experience lol!

Fantastic age though for kids, enjoy whilst it lasts, they grow up quick!!

When ever you get time Radarman, no worries, thanks for your input on this!!!! Much appreciated! hopefully one day I will be able to return the favor!

Marc
 

Radarman2

Member
Tesla,
winds have died down, so safe to come out of the Andrews shelter lol.

Simple diagram attached. Essentially PWM out of 1 pin, through a current limiting resistor (330 Ohm) and feed into the Timer Clk pin C.0 of the same 28X2.
The beauty of it is pwmout runs continuously in the background until another pwmout command is sent. You can use this attribute to set it at the beginning and then adjust by sending another pwmout with a new value (the variable resistor is used in this capacity to alter the PWM frequency setting).
Alternatively use the Programming Editor wizard to get the frequency you want, bear in mind that an increase in chip frequency alters the desired PWM frequency (if I remember rightly doubling the running frequency of a 28X2 to 16MHz and wanting a 1KHz output means selecting 2KHz as the desired pwm frequency in the wizard to ensure you get the 1KHz out, i.e. pulse every 1mS)

Anyway, onto the code (I've deleted chunks as you don't need it to see what's going on, the way I've done things may also not make sense, but again there's huge chunks of code missing):


Code:
#picaxe 28x2
#no_data
#no_table
Initialise:       
symbol PWMOutPin = C.1
symbol DispOutPin = B.1                                         'Output pin for the 16x2 LCD Display
symbol CalibratePin = A.0
symbol PWMSetting = b7
symbol Baud = N2400

PWMSetting = 124                                                 'Default to mid-range initially
let adcsetup = %0000000000000001                         'ADC0 set up for pot

Calibrate:
pwmout pwmdiv16, PWMOutPin, PWMSetting, 1           'pwmdiv16 for chip running at 64MHz
serout DispOutPin,Baud,(254,1)
pause 30
serout DispOutPin,Baud,(254,128,"Calibrating 1Sec")
readadc CalibratePin, PWMSetting
SetTimer count 65535                                             'Timer variable set to max, so next increment sets it to zero
pause 1000                                                           'After 1000mS the Timer variable should hold the value 1000
CalibTime = Timer
serout DispOutPin,Baud,(254,192,"Reading… ",CalibTime)
Instead of serout to a display, you could obviously change this to a debug or sertxd so you could see the value in Prog editor terminal window.
One thing to consider is that if the code begins the count just after a pulse has occurred then your count can be out by 1mS. A way of reducing this would be to increase the pwm period to a factor of 1mS, eg 500uS, 250uS, 125uS or adjust your code to start pwmout just before settimer command. Personally I'm working towards making the pwm period as small as possible so that the error will be reduced that way. All you would need to do is work out from the pwm frequency what your count would be for the 6000mS you require. As 'Timer' can be from 0 to 65535 and you want to count in multiples of 6000mS you could easily lessen the pwm period:
1mS pulses, timer count of 6000
500uS pulses, timer count of 12000
250uS pulses, timer count of 24000
125uS pulses, timer count of 48000
That's really your limit, but a quarter of 1mS is not bad accuracy (still need to factor in the time taken for each line of code to run though)
As for what you could do with it, 'Timer' is a word variable, so possibly split it into its components:

Code:
symbol Thousandths = b0
symbol Hundredths = b1
symbol Tenths = b2
symbol Units = b3
symbol Tens = b4
symbol TimeTotal = w10                               'word variable required

Let Thousandths = TimeTotal Dig 0 + “0”         'returns ASCII value
Let Hundredths = TimeTotal Dig 1 + “0”
Let Tenths = TimeTotal Dig 2 + “0”
Let Units = TimeTotal Dig 3 + “0”
Let Tens = TimeTotal Dig 4 + “0”
See manual 2 page 24 for DIG command, but it says:
DIG
The DIG (digit) command returns the decimal value of a specified digit (0-4,
right to left) of a 16 bit number. Therefore digit 0 of ‘67890’ is 0 and digit 3 is ‘7’.
To return the ASCII value of the digit simply add string “0” to the digit value e.g.
let b1 = b2 DIG 0 + “0”
See also the BINTOASCII and BCDTOASCII commands.
Bit late writing all of this, so there might be the odd error, but feel free to experiment with it
 

Attachments

Tesla

Member
Hey Radarman

You are a scholar and a gentleman!

That's very much appreciated, got a few teething problems running the code, but hopefully will be able to sort it out as you rightly state, its only part of a larger program.

I did think of using this way as well, but thought maybe I am missing the obvious and did not know quite how to achieve it anyway, so the code will give me a good solid grounding how to implement this. The diagram speaks a million words too, thanks!

I owe you one!

Have a good week :)
 

Tesla

Member
Hi Again Radarman
could you please check your diagram you posted in this thread when you have the time, I was a little confused as the pins are different to my module, then I realized i have the the modules, not the chips?:rolleyes:

it should still work though, I just have to alter the hardware pins to suit.

I managed to get the software running, but realized it would not run in the old editor, the pwmdiv16 showed as a fault, but ran in the new editor!

Will carry on playing around, the cats love the smoke from the chips, but i think its not good for their lungs! LOL :D

Many thanks. . .. You have saved me a lot of time and opened my eyes:eek:
 

Tesla

Member
A Little more help please...

Purchased picaxe microcontrollers for the evil genius, som e good stuff in there also purchased some O8M2 and the 28X2 3V toys!

Next question, several days later, tried to run this program on a 28x2 module submitted with schematics in this thread, not the 28x2, IS THERE ANY EXTRA CODE i NEED? Really puzzled, because the Program downloads, but problems understanding which pins I use, C1, C0 , ect are are different pins , I know where they are suppose to be after reading the documentation.

When I simulate running the program , this happens

CONSTANTS

symbol PWMOutPin =9 declared as C.1 in code
symbol DispOutPin =1 declared as B.1 in code 'Output pin for the 16x2 LCD Display
symbol CalibratePin =16 declared AS A.0 in code
symbol bAUD =5

Pin 9 on the 28x2 module is C.4 if you look at page 36 in the manual? yes the code states that it should be C.1 ?????

Again trawled through the docs, but again think I am missing something. .

Can I not just run a 28x2 program on a 28x2 module 5V 200 model, not the 201 , pin mis-configuration?

I have not declared something?

Any help, so close, yet so far, but "picing" up other info along the way!

Regards
Marc
Oh and one more thing, is there any one that undertakes programming some of these challenges on these devices for payment, I think that it would be possibly a much faster learning curve with say monetary reward? Maybe courses held in the UK? I wish to learn myself, but if someone shows how, then I can digest how they have achieved this.

And Radarman, if you are interested, I have a programming board and some BX24 which support floating point arithmatic and some LCD units, brand new if they are any use to you for your help so far.
 
Last edited:

westaust55

Moderator
The PICAXE programming work with logical pins not physical pins (also offer called "legs" to try and avoid confusion).
The parameters B.0, B.1, C.1 etc are programming editor pre-defined symbols for the logical identifier for the pins as shown by the same descriptor in Manual 1.

Some early Picaxe such as the 28x1 and 40x1 use portB as outputs so it was ' for Rev Ed to Assign B.0 as 0 (zero), B.1 as 1, B.7 as 7.
Then portC follows on with C.0 = 9 to C.7 = 15 etc.

In the above manner pin assignments will work on portB and notwithstanding the Rev Ed defined pin designation format,
HIGH 1 and HIGH B.1 will perform the same on an X1 and X2 part (plus others) when the pin is used as an output.

Accordingly there is no link between the logical value assigned to a pin within a program and the physical pin/leg.
 

Tesla

Member
Thanks for the info WestAust55

Much appreciated., but the dilemma that is still not clear to me, is that in the programming editor simming the program for a 28x2 should be DIFFERENT for the 28x2 Module? The allocated Variables C.0, B.0 etc are on different legs.

Simply put, the question is in the diagram that Radarman kindly attached in this thread with the code is for a 28x2, not a 28x2 module

What would be the wiring diagram for the 28x2 module ( it has a onboard power reg chip, socket etc, crystal etc., as I have tried wiring this up and the program downloads, but I do not see anything on the output showing the value for 1 second, pause 1000 in the code should show a count of 1000?

I will try and get some pics and examples before you reply, my apologies

Am I over looking the obvious here?
Regards
Marc
 

Tesla

Member
Hi WESTAUST55, think I follow you now, thanks mate, after much digesting;), so will place on hold posting anymore in this thread until I have a working sample fo code and some pictures of the hardware!!!

Regards
Marc
 

eclectic

Moderator
snipped

What would be the wiring diagram for the 28x2 module ( it has a onboard power reg chip, socket etc, crystal etc., as I have tried wiring this up and the program downloads, but I do not see anything on the output showing the value for 1 second, pause 1000 in the code should show a count of 1000?

snip
Do you mean the diagram on
page 36 Manual 1?
(Latest version 7.5)

e
 

Radarman2

Member
Tesla,
Do you mean you have the 28X2 shield base AXE401 or the AXE201?
If you have the AXE201 28X2 module then pin5 is the timer clk (C.0) and pin6 is pwmout (C.1). Link these with a 330Ohm resistor and my code should (hopefully) work.
I'll try to upload a cutdown version of the code that I've got working when I can get on the net.
Away from home for 6 weeks on a course, so can't respond often - deepest, darkest Norfolk seems to be a black hole for internet signal!
 

Radarman2

Member
Tesla,
try this - basic code with no embellishments. Outputs timer value to the terminal window in Programming Editor.

Code:
#picaxe 28x2
#no_data
#no_table

Main:
pwmout c.1, 124,1
settimer count 65535
pause 1000
sertxd (#timer,LF)
timer = 0
goto main
And as has been mentioned previously, connect 330Ohm between C.0 and C.1 (pins 5&6 of a 28X2 module AXE201)

If you check the terminal window (keep programmming cable connected) it will give you a count around 1000. Adjust pwmout setting (set as 124 in code above) to set for closest to 1000.
You could also chuck in a "setfreq m16" before "Main:" to set the chip to 16MHz speed. You would then need to adjust pwmsetting again to get close to 1000. I've only mentioned 1000 here as it forms the delay in "Pause 1000". If you use a different pause value then adjust for that number. Higher value should be more accurate.

HTH a bit more, RM2
 

hippy

Ex-Staff (retired)
the dilemma that is still not clear to me, is that in the programming editor simming the program for a 28x2 should be DIFFERENT for the 28x2 Module? The allocated Variables C.0, B.0 etc are on different legs.
By default the simulator simulates the PICAXE chip, not the module or board which it is fitted to, hence the pins are labelled with the pin names not leg numbers.

Thus "HIGH C.0" will show the pin for C.0 as an output and 'lit' whether a raw 28X2 chip or a 28X2 chip fitted to an AXE200/AXE201 module.

To find which leg of a chip or module C.0 actually is you need to look at the pinout and module diagrams in PICAXE Manual 1 ( Page 36 for the AXE200/AXE201 modules as eclectic kindly noted ).
 

Tesla

Member
Hi Everyone, thanks for the input!

OK, now just 2 posts above, referring to the AXE201

Radarman2 writes
"And as has been mentioned previously, connect 330Ohm between C.0 and C.1 (pins 5&6 of a 28X2 module AXE201)"

My reply

So the values of C.0 and C.1 do indeed correspond to the pins 5 & 6 of that particular chip 28x2 module as Radarman rightly states???

BUT on a standard 28x2 , the C.0 and the C.1 are pins 11 and Pin 12, as shown in RADARMANS wiring diagram. .

I have no problem knowing that different pins could correspond to different inputs and outputs, like clock out etc.

Now everyone, I have read the manual, printed it out and compared the 28x2 Module and the 28x2 chip.

I have not got a Project board yet, but any advice as which one to use would be appreciated , but the one I have made will suffice for now.
I was totally dumbfounded as to WHY when running the program, in the editor in the box that shows the constants, variables etc, other PINS been mentioned, that was and still is the main confusion that throws me. They do not correspond to the chip, or do they?

Which I have made my own board( PAGE 35 for a 28x2 3V) with min requirements to make it program as to Specs listed in the manual, double checked everything, can download program, but cannot see Timer operating, which eludes me still, could be hardware issues, but checked the board i have made in detail, it appears fine!

So, Questions gentleman are the following:

1) when I run program with the chip connected to the computer, Should it show the Timer value from the chip, or the program , probably a dumb question, but want to make sure, I know the program is downloading ok, because a box comes up to say so showing how many bytes have downloaded etc.

2) The box when I run the program supplied by Radarman( Many thanks again to the input you have put into this and anyone else that has helped) that shows Constants, Variables etc, states PINs relating to the values I have declared. Now, wether i use the 28x2 chip, or the 28x2 Module, these are exactly the same pins that relate to the values, BUT NOT THE PINS that radarmans diagram refers to???? For example, Pin 16 is mentioned ???

So, the little window to the right of the Main code box has the following data in it if you run the code listed by Radarman

Constants
PWMOutPin =9
DispOutPin =1
CalibratePin =16
Baud =5


So, the confusion is are the numbers above representing the pins on the chips, this is the puzzle, if not, what do they represent?
Because they do not correspond to the pins in the manual, either for the 28x2 or the 28x2 Module!
Is there a manual for the editor to explain all these things?

so, because I cannot see the Timer value increase, I started to worry that i have overlooked, misunderstood something.

Hope that helps you guys understand my dilemma, , ,

BUT something funny . .

Hippy, I have a couple of times fell into a hypnotic mistaken Identity of the Values in the editor and quite rightly, I was thinking these were pins, i will lay off the magic mushrooms. . .

Anyway, to lighten the load, what does a blond say after having sex?
Thanks Lads . . .

Thanks again gents . . .

Radarman, now trying the new code you sent, and thanks a million!
How would I implement the same code using a switch, I would like to capture the time period when a pin goes high for a length of time, then give this value to a variable?

I have spent every day reading the manuals and googling stuff, but think I am overloading myself, started dreaming about code, very worrying! Back to the Mushrooms . . Button variety On toast!
 
Last edited:

Tesla

Member
Ok Radarman

I am now using a 28x2 chip 3V, not the module, so I have connected the resistor 330 to pin 11 and 12!
I have then disconnected the power of the chip 3V, then reconnected, on the terminal window I got some weird characters, but after changing the baud rate, I got a "0" sort of every second?

Is this correct what i am seeing .?

I have a 100K pot on pin 2 as well, as you had in your original schematic. .

Now i have tried your orginal program also with the 28x2 chip, Not the module, and reading the terminal window
i see Calibrating and Time =, but no value?

This is the code I am using>

#picaxe 28x2
#no_data
#no_table
Initialise:
symbol PWMOutPin = C.1
symbol DispOutPin = B.1 'Output pin for the 16x2 LCD Display
symbol CalibratePin = A.0
symbol PWMSetting = b7
symbol Baud = N2400
symbol CalibTime = Timer

PWMSetting = 124 'Default to mid-range initially
let adcsetup = %0000000000000001 'ADC0 set up for pot

Calibrate:
pwmout pwmdiv16, PWMOutPin, PWMSetting, 1 'pwmdiv16 for chip running at 64MHz

pause 30

sertxd ("calibrating sec")
readadc CalibratePin, PWMSetting
SetTimer count 65535 'Timer variable set to max, so next increment sets it to zero
pause 1000 'After 1000mS the Timer variable should hold the value 1000
CalibTime = Timer
sertxd (" time = ",Timer)

NOTE I have tried to putput CalibTime and Timer, but no value appears?

I will try the Modules again with this new program. ..

Regards

Marc
 
Last edited:

Tesla

Member
RELAX!!!!

Hi Everyone, GOT IT WORKING!!!! The original program! Sort of:rolleyes:

The Original program that Radarman sent, firstly, I did not have an # in front Of Timer. Sorry folks!

Also, wiring, Tut Tut, I had broke the tracks connecting pin 11 when I had a pot there and forgot to reconnect it! tHIS STOPPED THE SIGNAL pwm RETURNING BACK TO THE CHIP, SO IT WAS READING NOTHING, HENCE WHY I GOT zEROS!

Also, faulty battery pack 3V, springs on neg of AAA battery to wide to connect coorectly, had this prob before, sorted this too!

MANY MANY thanks gentleman, I feel like I am getting some where now!

Now, one little niggling problem, pause is 1000
But I am getting a timing half that value, of around 506, no matter where the 100K pot is positioned. so value might need to be changed. This is on the 3v 28x2, do I need to change the freq?
This is pretty amazing though, Well done Radarman, this is a useful bit of code that I can use for all sorts of things!

Still would like to know what the little window that shows the variables, constants with numbers at the side in the editor represents, pins perhaps?

And how would I capture a time using a pin using this software, just remove the pause 1000 statement and replace with this around the main code?
if PIN 3 = 1 then

do code


endif

or is there a better way?

Also , what is the LF mean in this line ?sertxd (#timer,LF)

Again I cannot thank you all enough, everything that everyone of you have said in this thread has made sense, but it has took me a steep learning curve to grasp it all, so my apologies if I have seen a little slow gents. .

MARC
 
Last edited:

Tesla

Member
OK, used the wizzard, generated the correct code for generating 1000 Hrtz

I am getting 1020ms for pause statement , but if you tweak the PWMSetting to 254, you obtain 1000ms exactly for 1 second!
PAUSE 1000
Terminal spits out 1020
, but this is good enough for now!
#picaxe 28x2
#no_data
#no_table
Initialise:
symbol PWMOutPin = C.1
symbol DispOutPin = B.1 'Output pin for the 16x2 LCD Display
symbol CalibratePin = A.0
symbol PWMSetting = b7
symbol Baud = N2400
symbol CalibTime = Timer ' declare this, otherwise does not run. .
PWMSetting = 249 'Default to mid-range initially
let adcsetup = %0000000000000001 'ADC0 set up for pot

Calibrate:
pwmout pwmdiv16, PWMOutPin, PWMSetting, 500 'used wizard ! pwmdiv16 for chip running at 64MHz
readadc CalibratePin, PWMSetting
SetTimer count 65535 'Timer variable set to max, so next increment sets it to zero
pause 1000 'After 1000mS the Timer variable should hold the value 1000
CalibTime = Timer
sertxd ( " Time = ", #Timer ) 'Remember the # !

'Also, power up chip after downloading program, click on pixaxe in the menu, then the
' terminal, then view output, should be 1020ms for one second!
Now going to make the chip capture a time frame with the use of a pin. .:rolleyes:

Could this code be used on the new O8M2 ?
 
Last edited:

Tesla

Member
just a little bit more help here please. . .

Been playing around with trying to capture the time when a pin is pressed, what is the most efficient method using this code to start the timing when a switch is pressed, then to stop when its released.

I have tried >
readadc CalibratePin, PWMSetting
'if PinC.3 =1 then
SetTimer count 65535 'Timer variable set to max, so next increment sets it to zero
pause 1000 'After 1000mS the Timer variable should hold the value 1000
CalibTime = Timer
sertxd ( " Time = ", #Timer ) 'Remember the # !
'else Goto Calibrate:
endif
Loop
Having a few problems here, wish to have the program waiting until a key is pressed and whislt ever pin is high, then the pulses are counted . .

PinC.3 is on Pin 14 ...

Next project after this is to have sound out, or text to speech, and also write a maths rountine for X / + - that will support floating point calcs hopefully ...just banged my head . .:rolleyes:

Thanks again guys, at least I feel i am travelling the right direction, Especially a big thanks to Radarman!

Marc:cool:
 

inglewoodpete

Senior Member
You need to take a step back and look at a whole solution to the whole problem.

I suspect you are doing more than just time a button press.

The simple solution is to use PulsIn.

Otherwise you will need some code like the following pseudocode:
Code:
If Timer is running Then
   If PinC.3 = 0 Then   'Switch has just been released
      Read the timer
      Stop the timer
   EndIf
Else
   If PinC.3 = 1 Then   'Switch has just been pressed: start the timer
      Timer = 
      SetTimer....
   EndIf
EndIf
PinC.3 is on Pin 14 ...
No, PinC.3 is on Leg 14 ... (in PICAXE speak)
 

Tesla

Member
Thanks inglewoodpete

Thanks for the info and code, much appreciated, I will try to remember to always call the chip legs, legs, not pins!:rolleyes:

You mention the pulsin, but as there is already a pulse going into the chip on leg 6, could you use the same input and use the pulsin on that "LEG"? I have checked the manual and you can monitor C.3 etc, but how would you monitor the Serial In ?

I suppose you would connect the PWM to another pin " oops, LEG" and read from that Leg?

Marc
 

inglewoodpete

Senior Member
You mention the pulsin, but as there is already a pulse going into the chip on leg 6, could you use the same input and use the pulsin on that "LEG"? I have checked the manual and you can monitor C.3 etc, but how would you monitor the Serial In ?

I suppose you would connect the PWM to another pin " oops, LEG" and read from that Leg?
I have to plead guilty to not following every post on this thread so I seems I have missed some of your design criteria. I am a coward and have never even tried to use the Serial In pin for anything other than programming.:eek:

Once you have become familiar with the PICAXE pin/leg relationship, I think you will just also call the PICAXE i/o channels as 'pins'. 'Pins' are a label or virtual port that are directly tied to a physical connection that is called a 'leg'. The pin-to-leg relationship varies from one model to another and helps make software portable between models.

The term 'leg' is generally only used when necessary with PICAXEs when clarifying the convention with newbees.:cool:
 

Tesla

Member
No worries Inglewoodpete, every bit of help is useful and I have taken on board what you have said!

Now, Before the board goes down, could someone technical just help me on one issue.

I have the program working where it counts a pause statement and works very well, BUT

For the hell I cannot get the code to operate effectively from a LEg going high?

I have tried if, Else, While, and I can see the terminal screen . I noticed that if i try and do this conventionally, then I get bounce, that is I have to use pause statements on the code to stop the terminal spitting out to many values?

surely, there is a way to capture the serial In and measure the length the pulse operates for, just I just use another leg?

Tried the method of PeekSRF of the Timer, but again I had to set the debouce with pause statements of 60 either side to capture data, which means i am out by 120 ms then? So the method works Hippy, but not accurately without debounce. ..unless I am missing something because i don't know enough?

now on my zillionth code, keyboard letters are just eligible, my two typing fingers are like Bruce Lees!

Once I get over this one hurdle, then i am plain sailing!!!

So any help before the board goes down would be appreciated. .

The cool thing is that RADARMANS code works very welll!

Not to capture it with a pin going high??

marc. .
 

Tesla

Member
Code so far!!

#picaxe 28x2
#no_table
Initialise:
symbol PWMOutPin = C.1
symbol DispOutPin = B.1 'Output pin for the 16x2 LCD Display
symbol CalibratePin = A.0
symbol PWMSetting = b7
symbol Baud = N2400
symbol CalibTime = Timer


Main:
do
PWMSetting = 254 'Default to mid-range initially, tweak this
'wizzard gave 249, changed it to 254, then outputs 1000ms
let adcsetup = %0000000000000001 'ADC0 set up for pot
if PinC.3 =1 then
Calibrate:
pwmout pwmdiv16, PWMOutPin, PWMSetting, 500 'used wizard ! pwmdiv16 for chip running at 64MHz
readadc CalibratePin, PWMSetting
SetTimer count 65535 'Timer variable set to max, so next increment sets it to zero

'After 1000mS the Timer variable should hold the value 1000
CalibTime = Timer
sertxd ( " Time = " , #CalibTime ) 'Remember the # !
else PinC.1 = 0
'else Goto Calibrate:!
Timer = 0
PWMOUT C.1, OFF
Endif
Loop

This will count and display on screen when PINC.3 high
When I release, it resets to Zero. .
BUT

it now does not count, if held down for a count of 1000, comparing with stop watch, it runs half as slow, as though the screen in the terminal is slowing things down ..

Just a bit puzzled?
 

Tesla

Member
Rearranged, now the captured Time is good!

I have now placed the Sertxd when pin is Low, so when the pin is high, its not slowing down the count going to terminal . . .

Now its pretty accurate. .. .

So the terminal displays Time=0 over and over again

Press to make C.3 high and hold

When I release, the Terminal displays the Captured Time .;) BINGO!!!

I realize that the PWM is going all the time too . .in the background unless you switch it off. ..

#picaxe 28x2
#no_table
Initialise:
symbol PWMOutPin = C.1
symbol DispOutPin = B.1 'Output pin for the 16x2 LCD Display
symbol CalibratePin = A.0
symbol PWMSetting = b7
symbol Baud = N2400
symbol CalibTime = Timer


Main:
do
PWMSetting = 254 'Default to mid-range initially, tweak this
'wizzard gave 249, changed it to 254, then outputs 1000ms
let adcsetup = %0000000000000001 'ADC0 set up for pot
if PinC.3 =1 then
Calibrate:
pwmout pwmdiv16, PWMOutPin, PWMSetting, 500 'used wizard ! pwmdiv16 for chip running at 64MHz
readadc CalibratePin, PWMSetting
SetTimer count 65535 'Timer variable set to max, so next increment sets it to zero

'After 1000mS the Timer variable should hold the value 1000
CalibTime = Timer
'sertxd ( " Time = " , #CalibTime ) 'Remember the # !
else PinC.1 = 0
'else Goto Calibrate:!
sertxd ( " Time = " , #CalibTime ) 'Remember the # !
Timer = 0
CalibTime = 0
PWMOUT C.1, OFF
Endif
Loop
 

Tesla

Member
Just a quick thank you for everyone that helped me on this project!
I ended up writing my own simple timer for doing calcs which works brlliantly for my needs! I basically used a count and reversed engineered the count to seconds using some simple maths!
Everything works, so now I am happy as a pig in muck!
Regards
Marc
 
Top