BasicMicroUK - Forums

www.basicmicro.co.uk
It is currently Sun Apr 22, 2018 5:19 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: trouble with "capture" command
PostPosted: Fri Apr 01, 2011 6:02 pm 
Offline
New User

Joined: Tue Feb 22, 2011 11:10 pm
Posts: 2
sorry, i forgot the subject.
'Hello. I'm new to this forum. I hope that I have picked the right one for this question.
'I want to capture two pulses using the basic atom 28's hardware rather than doing it with software.
'they are standard rc servo pulses, 1.5 ms every 20 ms. they occur one right after the other.
'below is my attempt at this, but I am not a programmer and so this does not work.
'any help would be greatly appreciated. thanks for your help.
'the reference manual i used is BasicATOM syntax Manual ver 3.0.0.2


'capture.test. A test program to learn how to use the Basic Atom 28 hardware to
'capture a pulse width
' By John Miller
' Date 2/15/2011
' Updated 3/30/2011
' compiler: studio 2.0.0.5

' ==========
' Variables
' ==========
width var word
clear
'======================================
' Initialization
'======================================

' ==============================================
' Flexor_Internal interupt setup using timer 2.
'===============================================
settmr2 tmr2pre16post16,256 'sets Tmr2 to preset 16 and postset 16 and countdown of 256 giving a delay of 13.1 ms.
'these instructions set delay to 13 mS
oninterrupt TMR2INT, pulse 'jumps to "pulse" ISR
enable TMR2INT 'enables timer 2 interupt
setcapture 0,CAPTURE1L2H 'Capture: (P10)
' Waits for an event (high to low or low to high transition)
' on P9 or P10 and "captures" the 16 bit Timer1 value
' when the event occurs.
serout s_out,i9600,[0,13] ' clears term screen
serout s_out,i9600,["pulsewidth",13] 'sends "pulse width" label to term screen

'===========================
' Main program loop
'===========================

main: 'just an infinite loop, doing nothing, waiting for next interrupt.
goto main

'===========================================================================================
' ISR to read pulse width on p10 and send it to terminal 1
'===========================================================================================

disable TMR2INT 'disables "extint" interrupt
pulse:
high 4 'sets pin 4 high then low to measure time to execute the inbetween code
Getcapture 0, width 'captures pulse on pin 10
serout s_out,i9600,[dec width,13] 'sends value of pulse to term 1
enable TMR2INT
low 4
resume

end


Top
 Profile  
 
 Post subject: Re: trouble with "capture" command
PostPosted: Mon Apr 04, 2011 8:42 pm 
Offline
Site Admin
User avatar

Joined: Thu Mar 01, 2001 7:00 pm
Posts: 1316
Location: Temecula, CA
Ok, so what is the problem/question? Are you getting a specific error message or is something not working as you expected? how so? More details please.

_________________
Tech Support
Basic Micro - Robotic Technology Evolved


Top
 Profile  
 
 Post subject: Re: trouble with "capture" command
PostPosted: Mon Apr 04, 2011 9:51 pm 
Offline
Master

Joined: Tue Nov 21, 2006 5:34 pm
Posts: 662
Hi Nathan,

I am having a hard time remembering the earlier Atom IDE, but did it have some commands associated around the Atom Interrupts and timers that Studio does not support? Things like maybe: settmr2 or Getcapture ...

At least that is what I read into this message...

Kurt


Top
 Profile  
 
 Post subject: Re: trouble with "capture" command
PostPosted: Mon Apr 04, 2011 10:30 pm 
Offline
Master

Joined: Tue Jun 22, 2010 9:15 pm
Posts: 228
serout inside of an interrupt handler can't be good.

Alan KM6VV

_________________
Visit:
http://groups.yahoo.com/group/SherlineCNC/
http://tech.groups.yahoo.com/group/HexapodRobotIK/


Top
 Profile  
 
 Post subject: Re: trouble with "capture" command
PostPosted: Tue Apr 05, 2011 10:39 pm 
Offline
New User

Joined: Tue Feb 22, 2011 11:10 pm
Posts: 2
Nathan, thanks for your help on this problem. to answer your request I went back to my setupand here is the output from term 1.

pulsewidth
32763
32763
32763
32763
32763
32763
32763
32763
32763
32763
32763
32763
this was with a 4.88 ms pulse applied to p10. the output s/b around 9760. (4.88ms times 0.5 micro sec.) also I noticed that the output was the same when no pulse was applied to p10. So what do I have to do to fix this? I think that I'm enabling the wrong interrupt. thanks again for your help. john.


Top
 Profile  
 
 Post subject: Re: trouble with "capture" command
PostPosted: Tue Apr 05, 2011 10:55 pm 
Offline
Site Admin
User avatar

Joined: Thu Mar 01, 2001 7:00 pm
Posts: 1316
Location: Temecula, CA
First, we don't support Basic interrupts on Atom/Nano modules as of Studio 2.0s release, only ASM interrupts via the ISRASM{} block are garunteed to continue to function. This thread is exactly why we stop supporting Basic interrupts. :) Sorry. To use the hardware capture function on the Nano or Atom modules you should setup the PIC hardware directly. Then use an israsm{} interrupt handler, which I've documented in atleast a couple other posts, to process the value captured. Also as Alan said you should never do anything as long as a Serial command in an interrupt handler. This isn't a problem when using israsm since you can't use basic commands in an israsm handler. :)

_________________
Tech Support
Basic Micro - Robotic Technology Evolved


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 0 guests


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