BasicMicro - Forums

www.basicmicro.com
It is currently Mon May 21, 2012 8:12 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 21 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Long limited to 65,535?
PostPosted: Tue May 17, 2011 10:05 pm 
Offline
Guru

Joined: Sun Dec 20, 2009 10:52 pm
Posts: 76
Hi,

It seems that my long are limited to 65,535.
Here is my code below :

Code:
tens                  var            long
tensMax         var      long
tenscur         var      long
Mesurcourant:
   tensmax=0
   FOR n=0 TO 6
      adin16 p3,tens
      tens = tens>>2
      tensmax=tensmax+tens
   NEXT
   tenscur=(tensmax/7-8192)*6875
return


I only get 33000 when I should get 220000?

Thanks for your help

Chris


Top
 Profile  
 
 Post subject: Re: Long limited to 65,535?
PostPosted: Wed May 18, 2011 12:20 am 
Offline
Master

Joined: Sun Aug 17, 2008 5:26 pm
Posts: 798
Location: CA bay Area
Your Longs aren't limited to 65K, but the ADIN readings are 10-bit readings, so never go over 1023. I suppose if you took enough readings you might get over 65K. Seven readings isn't going to get you much, especially since you do a right shift x 2, which is dividing by four. Then you do some math which reduces the value even more?
Take care.

_________________
kenjj
http://blog.basicmicro.com/
http://kjennejohn.wordpress.com/


Top
 Profile  
 
 Post subject: Re: Long limited to 65,535?
PostPosted: Wed May 18, 2011 2:38 am 
Offline
Guru

Joined: Sun Dec 20, 2009 10:52 pm
Posts: 76
Hi Kenjj,

It's not ADIN but ADIN16 with a right shift which lead to 8224. At first my for next was for n=0 to 20 but I realised I could'nt go over 65k, it's why I reduced it to 7. To keep going 8224-8192 leave 32x6875, I should get 220000 but I only 33K ?


Top
 Profile  
 
 Post subject: Re: Long limited to 65,535?
PostPosted: Wed May 18, 2011 6:33 am 
Offline
Master

Joined: Tue Nov 21, 2006 9:34 am
Posts: 528
Hi Chris,

If it were me, I would have probably do several debug outputs, to verify the values that I was expecting I did get and/or localize where the issue is.

For example: I would probably print out tens and tensmax in the loop so we can see if the adin16 values are as expected and the sumation looks good.

From what I deduced here your description, your value divided by 7 = 8224?
Example I just run this on the Mad Hatter card:
Code:
tenscur var long
tensmax var long

   sethserial1 h38400
   pause 250
   tensmax = 8224 * 7 + 3
   tenscur=(tensmax/7-8192)*6875
   hserout ["Mad Hatter is Alive", 13]
   hserout ["TM: ", dec tensmax, " TM/7: ", dec tensmax/7, " TC: ", dec tenscur, 13]

I received the following output:
Code:
Mad Hatter is Alive
TM: 57571 TM/7: 8224 TC: 220000


So I did get the value you expected. Also which chip are you trying this on?

Kurt


Top
 Profile  
 
 Post subject: Re: Long limited to 65,535?
PostPosted: Wed May 18, 2011 10:48 am 
Offline
Master

Joined: Tue Jun 22, 2010 1:15 pm
Posts: 203
Doesn't ADIN16 already over-sample? 64 conversions? why do any more? gives 16 bit sum of conversions.

Gives 12-bit result.

Alan KM6VV

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


Top
 Profile  
 
 Post subject: Re: Long limited to 65,535?
PostPosted: Wed May 18, 2011 10:04 pm 
Offline
Guru

Joined: Sun Dec 20, 2009 10:52 pm
Posts: 76
I am using BAP24M and I don't get 220000. I get everything else but not the 220000 just as if the long couldn't go over 65K.
You are right Alan I could just use the adin16 alone but it's not the point, I would like to understand why the long doesn't behave as a long?

Thanks


Top
 Profile  
 
 Post subject: Re: Long limited to 65,535?
PostPosted: Thu May 19, 2011 9:41 am 
Offline
Site Admin
User avatar

Joined: Thu Mar 01, 2001 11:00 am
Posts: 903
Location: Temecula, CA
Then you are going to have to post your whole program because its obviously something else causing the problem. :(

_________________
Tech Support
Basic Micro - Robotic Technology Evolved


Top
 Profile  
 
 Post subject: Re: Long limited to 65,535?
PostPosted: Mon May 23, 2011 3:22 am 
Offline
Guru

Joined: Sun Dec 20, 2009 10:52 pm
Posts: 76
Hi,

Sorry I have been away for a few days.

Here is the code :

Code:
curMax         con      50000   
Baud            CON     N9600      'RF
Tx              con      P4         'RF Transceiver  DATA pin
TR              con      P6         'RF

voltMax         CON      150      
voltTresh      con      100      
period          var    word
duty          var    word
dutyC          var    word
dutyC2         var      word
tens          var    long
tensMax         var      long
tenscur         var      long
n             var    word
dime          var      byte

pause 1
HIGH TR                                 'RF Set to transmit
LOW Tx                            'RF

period=977 '16300
duty=period/2
dutyc=period/14
dutyc2=period/35
hpwm P11,period,duty
goto sommeil

test:
   gosub Mesurtension   
   if tens>voltmax then goto sommeil
   SEROUT Tx, Baud, ["UU!", dec tens]
   
   gosub Mesurcourant
   if tenscur>curMax then goto sommeil
   SEROUT Tx, Baud, ["UU!", dec tenscur]
goto test

Mesurtension:
   tensmax=0
   FOR n=0 TO 19
      adin16 p0,tens   
      tens = tens>>4   
      tensmax=tensmax+tens
   NEXT
   tens=tensmax/20*586/100
return

Mesurcourant:

   adin16 p3,tens
   tens = tens>>2

   tenscur=tens*1000
return

Sommeil:
   hpwm P10,0,0
   SLEEP 2500
   hpwm P10,period,dutyc
   GOSUB Mesurtension
   hpwm P10,0,0
   if tens<volttresh then
      hpwm P10,period,dutyc
      goto test
   endif
goto Sommeil


Thanks

Chris


Top
 Profile  
 
 Post subject: Re: Long limited to 65,535?
PostPosted: Mon May 23, 2011 6:12 am 
Offline
Master

Joined: Tue Nov 21, 2006 9:34 am
Posts: 528
Hi Chris,

It looks like this version does not have any of the code you mentioned in the first post? Like the loop, like the multiply...

Kurt


Top
 Profile  
 
 Post subject: Re: Long limited to 65,535?
PostPosted: Tue May 24, 2011 5:48 am 
Offline
Guru

Joined: Sun Dec 20, 2009 10:52 pm
Posts: 76
Hi Kurt,

I am still working on the project and I am trying to increase the speed and go around my problem with the long, it's why it's changing. But I still don't get a long as a result and I still don't know why?

thanks

Chris


Top
 Profile  
 
 Post subject: Re: Long limited to 65,535?
PostPosted: Tue May 24, 2011 6:11 am 
Offline
Master

Joined: Tue Nov 21, 2006 9:34 am
Posts: 528
ChrisB wrote:
I am still working on the project and I am trying to increase the speed and go around my problem with the long, it's why it's changing. But I still don't get a long as a result and I still don't know why?

Been there!

By chance have you tried my earlier simple version of your program? If so what values did it print?

Kurt


Top
 Profile  
 
 Post subject: Re: Long limited to 65,535?
PostPosted: Tue May 24, 2011 8:08 am 
Offline
Guru

Joined: Sun Dec 20, 2009 10:52 pm
Posts: 76
Hi Kurt,

When I use your program, I do get 220000 but with mine I can't over 65k?
Maybe Nathan could tell us why, maybe it has something to do with adin16?

Thanks


Top
 Profile  
 
 Post subject: Re: Long limited to 65,535?
PostPosted: Tue May 24, 2011 8:30 am 
Offline
Master

Joined: Tue Nov 21, 2006 9:34 am
Posts: 528
Yes, I believe the simple program eliminated the multiply as the issue. So if you can get your program closer to where it was and maybe print out the values for each of the ADIN16s and for the sum, we can maybe get an idea of what is happening. Other than that, there is not much more I can help out.

Kurt


Top
 Profile  
 
 Post subject: Re: Long limited to 65,535?
PostPosted: Tue May 24, 2011 10:08 am 
Offline
Guru

Joined: Sun Dec 20, 2009 10:52 pm
Posts: 76
Here it is:

Code:
Mesurcourant:
   tensmax=0
   FOR n=0 TO 19
      adin16 p3,tens
      tens = tens>>2
      tensmax=tensmax+tens
   NEXT
   tenscur=(tensmax/20-8192)*4583
return


Results :
Tensmax=41985
Tensmax/20=8239
(tensmax/20-8192)=48
(tensmax/20-8192)*4583=18793

Thanks


Top
 Profile  
 
 Post subject: Re: Long limited to 65,535?
PostPosted: Tue May 24, 2011 11:32 am 
Offline
Master

Joined: Tue Jun 22, 2010 1:15 pm
Posts: 203
I still don't see why you're taking 20 samples of adin16. As I asked before, doesn't it already take 64 samples and give you the extra 2 bits of resolution?

Alan KM6VV

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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 21 posts ]  Go to page 1, 2  Next

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