BasicMicroUK - Forums

www.basicmicro.co.uk
It is currently Sun Nov 18, 2018 12:54 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: I'm baaaaaaaack ....
PostPosted: Tue Nov 09, 2010 9:47 pm 
Offline
New User
User avatar

Joined: Thu Oct 07, 2010 7:10 pm
Posts: 3
Hi all,

After some time i (old forumname pvwoerkom) fired up the old atom and am back in bussines.

Project: Monocopter single wing rotating flying device.

Hardware:

Wing, Rc Receiver, BAP24, brushless motor+controller, compass and some code.

I will post some of my experiments to show what i have been up to so far.

Simple compass routine:

Code:
SDA Con P8 ' Define Data pin
SCL Con P9 ' Define Clk pin
Compass Con 0xC0 ' Compass I2C Address
CmdReg Con 0 ' Compas Command register
BearingReg Con 2 ' Compas 1st Range register
Bearing Var Word ' 16 bit variable for Bearing
revision var byte ' revision of compass module
dbear var byte
reg4 var word
reg6 var word
reg8 var word
reg10 var word

Serout S_OUT, i9600, ["Compass start", 13]
Main

pause 300
i2cout   p8,p9,0xc0,[0x00]
i2cin   p8, p9, 0xC0, [revision, dbear, Bearing.HighByte, Bearing.LowByte, reg4.highbyte, reg4.lowbyte, reg6.highbyte, reg6.lowbyte]
bearing.bit15=0
Serout S_OUT, i9600, [hex revision,32,dec dbear,32, DEC Bearing/10, 32,real bearing/10, 32, hex reg4,32,hex reg6, 13]

goto Main


Top
 Profile  
 
 Post subject: Re: I'm baaaaaaaack ....
PostPosted: Tue Nov 09, 2010 9:53 pm 
Offline
New User
User avatar

Joined: Thu Oct 07, 2010 7:10 pm
Posts: 3
Her some weird code to measure a RC receiver pulse.

wired p10 to p0
and renerate pulses on p10
catch the falling edges on p0 and count the pulselength on P4



Code:

x var word
oldp4 var bit
ybiasteller var word
yawbias var word


enablehservo

;BAP24


low p10
for x = 0 to 1000
toggle p10
next


hpwm p10,1600,800 ; that is all there is to it. 10us

PMR5.bit0 = 1 ;1 makes p50 (P8) J27 an i/p and generates a WKP0
IEGR2.bit0 = 0 ;0 means falling edge on p50 to trigger interrupt
PUCR5.bit0 = 1 ;turn on the internal pull up resistor

oninterrupt wkpint_0, toggleLED
enable wkpint_0
Serout S_OUT, i9600, ["bias " ,dec yawbias, 13]

enable
_main

pause 500
disable wkpint_0
Serout S_OUT, i9600, ["bias " ,dec yawbias, 13]
enable wkpint_0

goto _main




disable
toggleLED:

if oldp4 = 0 and in4 = 1 then
Ybiasteller = 0
endif
if in4 = 1 and oldp4= 1 then
ybiasteller=ybiasteller+1
endif
if in4 = 0 and oldp4= 1 then
yawbias = ybiasteller
endif
oldP4 = in4
toggle p1
resume



Top
 Profile  
 
 Post subject: Re: I'm baaaaaaaack ....
PostPosted: Tue Nov 09, 2010 10:15 pm 
Offline
New User
User avatar

Joined: Thu Oct 07, 2010 7:10 pm
Posts: 3
Nice peice of code to catch an rc receiver pulse length using ASM
Hooked up P0 to receiver channel.
Started TIMERW
The pulses from the RC receiver are measured in the backgroud using allmost no overhead (edge triggered).



Code:
WKP0Handler ; Get Servo pulse width

   ; get TCNT
    mov.w  @TCNT:16,e0  ;load timerWcount
    mov.w     e0,@TWVAL_0:16   ; Save it in memory
 
 andc     #0x7F,ccr    ; re-enable ints
 bclr  #0,@IWPR:8   ; reset wkp0 int
 
   ; test why we are here (rising or falling edge)
   
 btst  #0,@IEGR2:8    'WKP0 edge = bit 0
 bne   POS_EDGE0:8    'if set we were waiting for a pos edge
 bra   NEG_EDGE0:8    'if not we were waiting for a falling edge

POS_EDGE0:   
    mov.w  @TWVAL_0:16,e0    ; get the new value
    mov.w  e0,@OLDTWVAL_0:16 ; save it for later
    bra   THE_END0:8    ; Done for now

NEG_EDGE0:
 mov.w  @OLDTWVAL_0:16,e1 ; get the old value
 mov.w  @TWVAL_0:16,e0    ; get the new value
   
 cmp.w   e1,e0   ; if new > old then (no wrap)
    beq   THE_END0:8
 bgt   VERDER10:8  ; then

    mov.w   #0Xffff,e0  ; else get max in e0
    sub.w  e1,e0   ; max - oldval to e0
    mov.w  @TWVAL_0:16,e1  ; current val to e0
    add.w  e1,e0   ; add to e0;
    bra   VERDER0:8

VERDER10:
    sub.w  e1,e0    ; calculate difference er0 holds difference

VERDER0:   
    mov.w  e0,@YAW:16   ; save difference to memory

THE_END0:
 bnot  #0,@IEGR2:8    ; SWITCH THE TRIGGER FOR WKP0   

  resume


Top
 Profile  
 
 Post subject: Re: I'm baaaaaaaack ....
PostPosted: Wed Nov 10, 2010 12:03 am 
Offline
Master

Joined: Tue Nov 21, 2006 5:34 pm
Posts: 662
Hi, looks good!

FYI - you can make your WKP handler even faster if you use ONASMINTERRUPT instead of ONINTERRUPT. You are already 95% there...
It would probably look something like:
Quote:

BEGINASMSUB
ASM {
WKP0Handler: ; Get Servo pulse width
push.w e0 ; save away any registers we use.
push.w e1

; get TCNT
mov.w @TCNT:16,e0 ;load timerWcount
mov.w e0,@TWVAL_0:16 ; Save it in memory

andc #0x7F,ccr ; re-enable ints
bclr #0,@IWPR:8 ; reset wkp0 int

; test why we are here (rising or falling edge)

btst #0,@IEGR2:8 'WKP0 edge = bit 0
bne POS_EDGE0:8 'if set we were waiting for a pos edge
bra NEG_EDGE0:8 'if not we were waiting for a falling edge

POS_EDGE0:
mov.w @TWVAL_0:16,e0 ; get the new value
mov.w e0,@OLDTWVAL_0:16 ; save it for later
bra THE_END0:8 ; Done for now

NEG_EDGE0:
mov.w @OLDTWVAL_0:16,e1 ; get the old value
mov.w @TWVAL_0:16,e0 ; get the new value

cmp.w e1,e0 ; if new > old then (no wrap)
beq THE_END0:8
bgt VERDER10:8 ; then

mov.w #0Xffff,e0 ; else get max in e0
sub.w e1,e0 ; max - oldval to e0
mov.w @TWVAL_0:16,e1 ; current val to e0
add.w e1,e0 ; add to e0;
bra VERDER0:8

VERDER10:
sub.w e1,e0 ; calculate difference er0 holds difference

VERDER0:
mov.w e0,@YAW:16 ; save difference to memory

THE_END0:
bnot #0,@IEGR2:8 ; SWITCH THE TRIGGER FOR WKP0
pop.w e1 ; restore what registers we saved away
pop.w e0
rte
}
ENDASMSUB

Warning: I did not compile and therefore did not test /debug the above code...

If you do an asm version you have to save and restore any registers you use where the basic version saves and restores all 7 32 bit registers (which takes many cycles). You have to clear the condition that caused the interrupt, which you were already doing. With WKP interrupts, you are also responsible to know which WKP interrupt had happened (All 6 are on one actual interrupt) and you must do a return from exception (RTE).

Kurt


Top
 Profile  
 
 Post subject: Re: I'm baaaaaaaack ....
PostPosted: Sun Nov 14, 2010 1:15 am 
Offline
Master

Joined: Sun Oct 05, 2008 5:40 pm
Posts: 111
Monocopters rock! I have flown done some experimentation with rocket powered monocopters. Flight time is limited as is altitude but the THWUMP...THWUMP...THWUMP sound was great.

Anymore info on the airframe? Pics?


Top
 Profile  
 
 Post subject: Re: I'm baaaaaaaack ....
PostPosted: Thu Apr 30, 2015 12:48 pm 
Offline
New User

Joined: Thu Apr 30, 2015 12:38 pm
Posts: 1
FYI - you can make your WKP handler even faster if you use ONASMINTERRUPT instead of ONINTERRUPT. You are already 95% there...


_________________________
aliiiii


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 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