BasicMicro - Forums

www.basicmicro.com
It is currently Mon May 21, 2012 1:09 am

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 13 posts ] 
Author Message
 Post subject: basicatom pro
PostPosted: Wed Jul 06, 2011 11:38 pm 
Offline
Citizen

Joined: Wed Jun 29, 2011 2:29 am
Posts: 21
I am trying to calculate the no.of cycles in a waveform using count command

cycles var word
time var word
time=1000
cycles=0
main
count p0,time,cycles
pause 100
serout s_out,i9600,["count= ", dec cycles,13]
goto main


am i using correct command? or is there any other command to calculate the no of cycles in a waveform
plz help me..


Top
 Profile  
 
 Post subject: Re: basicatom pro
PostPosted: Thu Jul 07, 2011 9:36 am 
Offline
Site Admin
User avatar

Joined: Thu Mar 01, 2001 11:00 am
Posts: 903
Location: Temecula, CA
The ammount of time COUNT counts is in clock cycles so unless you only want to count for 1000 clocks so unless you only wanted to count for 62.5us then you need to increase the count time. On an AtomPro24/28 16000000 will count for one second. On an AtomPro40 20000000 will count for 1 second.

_________________
Tech Support
Basic Micro - Robotic Technology Evolved


Top
 Profile  
 
 Post subject: Re: basicatom pro
PostPosted: Fri Jul 08, 2011 3:21 am 
Offline
Citizen

Joined: Wed Jun 29, 2011 2:29 am
Posts: 21
I am using basicatom pro 40. and I wanted to calculate the no.of cycles for 1sec. I have generated the square waveform(freq:20k and amplitude:5v) using function generator and connected that to p0 of atompro.
I loaded the count program.Here i did not use pull up resistor as w/f amp is 5v,but its count is always zero
how to get exact no.of cycles for 1sec?


and I read in the manual that it would count a low-high-low as 1
cycle.what is the minimum voltage to recognize it as low ?


Top
 Profile  
 
 Post subject: Re: basicatom pro
PostPosted: Fri Jul 08, 2011 10:43 am 
Offline
Site Admin
User avatar

Joined: Thu Mar 01, 2001 11:00 am
Posts: 903
Location: Temecula, CA
the minimum voltage is .8 of Vcc IIRC. so around 3.3v when running at 5v. Also you need to specify a time of 20000000(20 million) for the time to count to count for 1 second(eg its in clock cycles). There is another way to calculate frequency. You can get the instant frequency by using a pulsin to measure the width of one high/low/hihg or low/high/low. The nice thing about doing it this way is you don't have to wait a full second to get a frequency.

_________________
Tech Support
Basic Micro - Robotic Technology Evolved


Top
 Profile  
 
 Post subject: Re: basicatom pro
PostPosted: Tue Jul 12, 2011 3:18 am 
Offline
Citizen

Joined: Wed Jun 29, 2011 2:29 am
Posts: 21
I have given the time as 20 million as you said and it is counting pulses for 1sec.

cycles var word
time var word

Main
count p0, 20000000, cycles

serout s_out,i9600,[dec cycles,13]

goto main

But why should we give time as 20million? could you please explain the reason?
what is Tlabel, Timeout in pulsin command?
thank you..


Top
 Profile  
 
 Post subject: Re: basicatom pro
PostPosted: Tue Jul 12, 2011 6:36 am 
Offline
Master

Joined: Tue Nov 21, 2006 9:34 am
Posts: 527
This is because he decided that the time value specified in this command is in clock ticks and the BAP40 runs at 20mhz and so 20 million is one second... On Bap28 this would be 16 million...

The Tlabel/timeout for pulsin command is explained in the manual. It basically says that if the pulse is not detected in a certain amount of time (timeout), the command will abort and jump to the label (TLabel).

Kurt


Top
 Profile  
 
 Post subject: Re: basicatom pro
PostPosted: Thu Jul 14, 2011 11:12 am 
Offline
Site Admin
User avatar

Joined: Thu Mar 01, 2001 11:00 am
Posts: 903
Location: Temecula, CA
To make the count command have as high a resolution as possible I used clock cycles insteda of useconds. Using useconds would have caused the count command to have half the resolution is has currently for no real gain.

_________________
Tech Support
Basic Micro - Robotic Technology Evolved


Top
 Profile  
 
 Post subject: Re: basicatom pro
PostPosted: Tue Jul 19, 2011 3:26 am 
Offline
Citizen

Joined: Wed Jun 29, 2011 2:29 am
Posts: 21
Is it possible to measure the time between particular no.of pulses by using pulsin command?


Top
 Profile  
 
 Post subject: Re: basicatom pro
PostPosted: Tue Jul 19, 2011 10:33 am 
Offline
Site Admin
User avatar

Joined: Thu Mar 01, 2001 11:00 am
Posts: 903
Location: Temecula, CA
Thats what the pulsin command is for, but you can't use it at the same time as count. You can use one and then the other of course. Also the pulsin command has a minimum resolution as well(the manual lists it). Any pulse shorter than that will not be correctly read.

You can also use the capture/compare hardware on the AtomPro to read a pulse. You will need to read the section in the 3694 or 3687 hardware manual on using the capture compare hardware of the TImerW(atompro24/28) or TimerZ(Atompro40/ARC32) which can capture pulse widths at the highest resolutions and can be done mostly in the background.

_________________
Tech Support
Basic Micro - Robotic Technology Evolved


Top
 Profile  
 
 Post subject: Re: basicatom pro
PostPosted: Wed Jul 20, 2011 11:09 pm 
Offline
Citizen

Joined: Wed Jun 29, 2011 2:29 am
Posts: 21
Acidtech wrote:
Thats what the pulsin command is for, but you can't use it at the same time as count. You can use one and then the other of course. Also the pulsin command has a minimum resolution as well(the manual lists it). Any pulse shorter than that will not be correctly read.

You can also use the capture/compare hardware on the AtomPro to read a pulse. You will need to read the section in the 3694 or 3687 hardware manual on using the capture compare hardware of the TImerW(atompro24/28) or TimerZ(Atompro40/ARC32) which can capture pulse widths at the highest resolutions and can be done mostly in the background.



pulsin command is giving on time of the pulse not the total time period. But i need to read the total time period of the 'n' no of (not single pulse) sequential pulses. can i use capture/command hardware for this? how to get this manual?

thanks alot


Top
 Profile  
 
 Post subject: Re: basicatom pro
PostPosted: Thu Jul 21, 2011 6:57 am 
Offline
Master

Joined: Tue Nov 21, 2006 9:34 am
Posts: 527
First the easy part. As part of installing the IDE, it installs the hardware manuals for all of the different processors. Go to the Help menu of the IDE and there is a menu item for each of them.

I assume you need higher resolution than you can get from simple basic code, something like:

Setup a timer (nice to use16 bit timer TimerW(bap24-8), Timerz(Bap40/Arc32) but not if you use HSERVO... Otherwise you will probably have to deal with overflows, depending on how long a period and resolution.

Get the Timer Start time (or zero it)

Loop reading the pin until you get the number of high to low transitions (or low to high) that you want.

Grab the end time...

If you need more accuracy or the pulses happen faster than you can detect in basic, you could convert the inner loop to assembly language... Also if you can use the 16 bit timer and you can have your setup such that the pin you are interested in is connected to one of the Input capture pins than you can have the hardware capture the timer clock tic when a transition happens. Also you can set it up to have interrupts generated on these transitions...

Note: I did some/most of the above when I wrote some RC receiver code for a hacked Hitec receiver (only need one IO line)...

Kurt


Top
 Profile  
 
 Post subject: Re: basicatom pro
PostPosted: Thu Jul 21, 2011 8:01 pm 
Offline
Site Admin
User avatar

Joined: Thu Mar 01, 2001 11:00 am
Posts: 903
Location: Temecula, CA
There is no way to read N number of pulses and calculate the time in Basic. Basic would be too slow for even farely slow pulse trains. You could probably do this in hardware using asm and interrupts but this is very much non-trivial.

_________________
Tech Support
Basic Micro - Robotic Technology Evolved


Top
 Profile  
 
 Post subject: Re: basicatom pro
PostPosted: Tue Sep 13, 2011 4:30 am 
Offline
Citizen

Joined: Wed Jun 29, 2011 2:29 am
Posts: 21
how to use real time clk (RTC)?
can anyone give example using RTC..


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


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 post attachments in this forum

Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

phpBB SEO