Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 06:17 05 May 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : IO speed, basic vs cfunction

Author Message
cwilt
Senior Member

Joined: 20/03/2012
Location: United States
Posts: 147
Posted: 08:04pm 07 Dec 2014
Copy link to clipboard 
Print this post

I just got my sample 170 chips to play with and have loaded the latest beta successfully. So far everything seems to be as expected. Today I was playing around and did a simple loop that toggled a pin on and off. The speed was not surprising but it did raise a question for me that I do not yet know how to answer. Since I have not had a chance to play with and learn the cfunctions I will ask those who do know. Has anyone created cfuntions to turn a pin on or off and measured the speed compared to the normal way?

I think 3 functions would do it. A set high, set low, and a toggle would do the trick. If you know how to write the code but don't have the means to measure. Post it and I will run the tests.

Curiosity killed the cat, but it died a wiser cat.
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5913
Posted: 08:48pm 07 Dec 2014
Copy link to clipboard 
Print this post

I think that the overheads in calling the Cfunction would make any simple toggle much the same as a normal function doing the same think.
Where Cfunctions would be of benefit would be for a stream of short, varying length pulses.

Jim
VK7JH
MMedit   MMBasic Help
 
G8JCF

Guru

Joined: 15/05/2014
Location: United Kingdom
Posts: 676
Posted: 09:01pm 07 Dec 2014
Copy link to clipboard 
Print this post

@cwilt

As part of developing MMProg32RPCII, I have to toggle a pin for a clock pulse, and according to my 'scope, without any delays between high and low, the pulse width was about 100nS (at CPU=48) wide.

Here's some test code

OPTION EXPLICIT

PIN(6) = 0

SETPIN 6,DOUT

'PulseTest NEVER returns, Cycle Power
'Scope/Counter on Pin 6 of 28 pin uMite

DIM Result%
Result%=pulsetest()

END

'
'K:\Programming\PICProgramming\Micromite\UserSupport.X\dist\ default\production\pulsetest.bas
'
'pulsetest 2014-12-08 06:50:28 CFuncGen Ver 1.0.21 by user=Peter
'
CFUNCTION pulsetest
00000000
3c03bf88 24020004 ac626138 ac626134 1000fffd 00000000
END CFUNCTION



'#define clklo *(volatile unsigned int *)0xbf886134 = (1 << 2) // pin 6 Low
'#define clkhi *(volatile unsigned int *)0xbf886138 = (1 << 2) // pin 6 High
'long long pulsetest(){
'
' //Do Forever
' for(;;){
' clkhi;
' clklo;
' }
'}



Not quite what you want, sorry I didn't read your post properly - mea culpa - I'll write what you want - but this test does show the limit on pulse generation.

Jim is quite correct, unless you need to generate a pulse train, the overhead in calling the CFunction dwarfs the C execution time.

PeterEdited by G8JCF 2014-12-09
The only Konstant is Change
 
G8JCF

Guru

Joined: 15/05/2014
Location: United Kingdom
Posts: 676
Posted: 09:28pm 07 Dec 2014
Copy link to clipboard 
Print this post

@CWilt

I think these are the functions you want, and presumably you will write some MMBasic around them. Hope these will help answer your questions.


OPTION EXPLICIT

DIM I%,J%,R%

'Scope/Counter on Pin 6 of 28 pin uMite
PIN(6) = 0

SETPIN 6,DOUT

DO

INPUT "Test to Run, 1=Set High, 2=Set Low, 3=Pulse, 4=Pulse train", I%

SELECT CASE I%
CASE 1
FOR J%=1 TO 10000
R%=PulseHi()
NEXT J%

CASE 2
FOR J%=1 TO 10000
R%=PulseLo()
NEXT J%

CASE 3
FOR J%=1 TO 100000
R%=Pulsetest()
NEXT J%

CASE 4
'PulseTest NEVER returns, Cycle Power
'Scope/Counter on Pin 6 of 28 pin uMite
PRINT "You will need to power cycle your uMite after this"
R%=pulsetrain()

END SELECT

LOOP
END


'
'K:\Programming\PICProgramming\Micromite\UserSupport.X\dist\ default\production\pulsetrain.bas
'
'pulsetrain 2014-12-08 07:18:50 CFuncGen Ver 1.0.21 by user=Peter
'
CFUNCTION pulsetrain
00000000
3c03bf88 24020004 ac626138 ac626134 1000fffd 00000000
END CFUNCTION

'
'pulseHi 2014-12-08 07:18:50 CFuncGen Ver 1.0.21 by user=Peter
'
CFUNCTION pulseHi
00000000
24030004 3c02bf88
ac436138 00001021 03e00008 00001821
END CFUNCTION

'
'pulseLo 2014-12-08 07:18:50 CFuncGen Ver 1.0.21 by user=Peter
'
CFUNCTION pulseLo
00000000
24030004 3c02bf88 ac436134 00001021
03e00008 00001821
END CFUNCTION

'
'pulseTest 2014-12-08 07:18:50 CFuncGen Ver 1.0.21 by user=Peter
'
CFUNCTION pulseTest
00000000
3c02bf88 24030004 ac436138 ac436134 00001021 03e00008
00001821
END CFUNCTION

'#define clklo *(volatile unsigned int *)0xbf886134 = (1 << 2) // pin 6 Low
'#define clkhi *(volatile unsigned int *)0xbf886138 = (1 << 2) // pin 6 High
'long long pulsetrain(){
'
' //Do Forever
' for(;;){
' clkhi;
' clklo;
' }
'}
'
'long long pulseHi(){
' clkhi;
' return(0);
'}
'
'long long pulseLo(){
' clklo;
' return(0);
'}
'
'long long pulseTest(){
' clkhi;
' clklo;
' return(0);
'


PeterEdited by G8JCF 2014-12-09
The only Konstant is Change
 
cwilt
Senior Member

Joined: 20/03/2012
Location: United States
Posts: 147
Posted: 05:28am 08 Dec 2014
Copy link to clipboard 
Print this post

  TassyJim said   I think that the overheads in calling the Cfunction would make any simple toggle much the same as a normal function doing the same think.
Where Cfunctions would be of benefit would be for a stream of short, varying length pulses.

Jim


Thats what I thought would be the case, but you never know until you ask or try yourself. Would be cool to have access to fast IO.
 
cwilt
Senior Member

Joined: 20/03/2012
Location: United States
Posts: 147
Posted: 05:34am 08 Dec 2014
Copy link to clipboard 
Print this post

  G8JCF said   @cwilt

As part of developing MMProg32RPCII, I have to toggle a pin for a clock pulse, and according to my 'scope, without any delays between high and low, the pulse width was about 100nS (at CPU=48) wide.

Thats considerably faster than standard functions.


  G8JCF said  
Not quite what you want, sorry I didn't read your post properly - mea culpa - I'll write what you want - but this test does show the limit on pulse generation.

Jim is quite correct, unless you need to generate a pulse train, the overhead in calling the CFunction dwarfs the C execution time.

Peter

Yours and Jim's opinions are more than enough for me.
 
cwilt
Senior Member

Joined: 20/03/2012
Location: United States
Posts: 147
Posted: 05:40am 08 Dec 2014
Copy link to clipboard 
Print this post

  G8JCF said   @CWilt

I think these are the functions you want, and presumably you will write some MMBasic around them. Hope these will help answer your questions.


Thanks a lot Peter. I will write some simple code and post the results in case someone else asks such a silly question.
 
G8JCF

Guru

Joined: 15/05/2014
Location: United Kingdom
Posts: 676
Posted: 06:02am 08 Dec 2014
Copy link to clipboard 
Print this post

@cwilt

It wasn't/isn't a 'silly question'. A properly characterised set of test results would be very useful to the Community.

I don't really have the proper test equipment to be able to easily carry out rigorous testing and recording of the results, (need a DSO IMHO), eg at each of the CPU speeds.

Peter
The only Konstant is Change
 
cwilt
Senior Member

Joined: 20/03/2012
Location: United States
Posts: 147
Posted: 09:09am 08 Dec 2014
Copy link to clipboard 
Print this post

  G8JCF said   @cwilt

It wasn't/isn't a 'silly question'. A properly characterised set of test results would be very useful to the Community.

I don't really have the proper test equipment to be able to easily carry out rigorous testing and recording of the results, (need a DSO IMHO), eg at each of the CPU speeds.

Peter


I recently did similar testing on a linux SoC device that I use. Typical programming of the IO's is done in C and a lot of people struggle with C, especially those new to programming in general. So I wrote the fastest possible IO control code for many different interpreted languages and compared them to compiled C. I expected them all to be very similar and I proved myself wrong.

I will proceed with the tests at each CPU speed and post the results.
 
cwilt
Senior Member

Joined: 20/03/2012
Location: United States
Posts: 147
Posted: 04:54pm 08 Dec 2014
Copy link to clipboard 
Print this post

Test results.
Basic samples first. Used a simple loop with pin on and off.

CPU=5mhz IO speed=1.2khz pulse=808us


CPU=10mhz IO speed=2.5khz pulse=392us


CPU=20mhz IO speed=5.2khz pulse=192us


CPU=30mhz IO speed=7.8khz pulse=128us


CPU=40mhz IO speed=10.4khz pulse=96us


CPU=48mhz IO speed=12.5khz pulse=80us

 
cwilt
Senior Member

Joined: 20/03/2012
Location: United States
Posts: 147
Posted: 04:59pm 08 Dec 2014
Copy link to clipboard 
Print this post

Cfunction using Peters pulsetrain. Thanks again for the code.

CPU=5mhz IO speed=1.25mhz Pulse=0.797us


CPU=10mhz IO speed=2.5mhz Pulse=0.399us


CPU=20mhz IO speed=5.0mhz Pulse=0.199us


CPU=30mhz IO speed=7.5mhz Pulse=0.133us


CPU=40mhz IO speed=10.0mhz Pulse=0.100us


CPU=48mhz IO speed=12.0mhz Pulse=0.083us

 
cwilt
Senior Member

Joined: 20/03/2012
Location: United States
Posts: 147
Posted: 05:00pm 08 Dec 2014
Copy link to clipboard 
Print this post

These images are 1/2 scale. I will upload full size if asked.
 
G8JCF

Guru

Joined: 15/05/2014
Location: United Kingdom
Posts: 676
Posted: 05:52am 09 Dec 2014
Copy link to clipboard 
Print this post

@cwilt

Thanks, that's an interesting set of observations and are a good basis for anyone planning on needing fast digital I/O.

Peter
The only Konstant is Change
 
cwilt
Senior Member

Joined: 20/03/2012
Location: United States
Posts: 147
Posted: 05:57am 09 Dec 2014
Copy link to clipboard 
Print this post

@Peter,

Yes, indeed. I think that with cpu at default speed and some timing control a nice square wave could be made at at around 5mhz.
 
G8JCF

Guru

Joined: 15/05/2014
Location: United Kingdom
Posts: 676
Posted: 06:12am 09 Dec 2014
Copy link to clipboard 
Print this post

I wonder how difficult it would be to produce a tunable quadrature (I/Q) clock from 2 pins for a low frequency SDR ?

Peter
The only Konstant is Change
 
cwilt
Senior Member

Joined: 20/03/2012
Location: United States
Posts: 147
Posted: 06:33am 09 Dec 2014
Copy link to clipboard 
Print this post

Fun idea.
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024