Go to Post Wow... no duct tape? - Stormnnormn [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 03-02-2005, 11:23
Squall Squall is offline
Registered User
#1382
 
Join Date: Jan 2004
Location: Brasil- São José dos Campos
Posts: 28
Squall is an unknown quantity at this point
Some things i'm trying to understand on Kevin's Accelerometer Code

We're trying to get our accelerometer to work here with Kevin's Code, that part is easy, but we're trying to understand everything on the code so that we can make the modifications we need.

We're having a special interest on this part :

adc_result = ADRESH;
adc_result << = 8;
adc_result += ADRESL;

We've understood that it's reading the High bits of the ADC and then it'll copy it do the lower part of the adc_result variable, this part I really can't understand. Why does he do this ?? I've been trying to figure out for a while now, does anyone have a clue ?

Thanks
__________________
Girafales - TEAM #1382
  #2   Spotlight this post!  
Unread 03-02-2005, 11:47
Unsung FIRST Hero
Matt Leese Matt Leese is offline
Been-In-FIRST-Too-Long
FRC #1438 (The Aztechs)
Team Role: Engineer
 
Join Date: May 2001
Rookie Year: 1998
Location: Long Beach, CA
Posts: 937
Matt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond repute
Send a message via AIM to Matt Leese
Re: Some things i'm trying to understand on Kevin's Accelerometer Code

The ADC input comes in the form of a high byte and a low byte. In order to copy that over to an integer, you have to copy them separately. The first part has the ADC high byte copied over and then left shifted by 8 bits. This means that the value of the ADC high byte is in the high byte portion of the adc_result variable. Then, the ADC low byte is added in so that both values are there.

Matt
  #3   Spotlight this post!  
Unread 03-02-2005, 12:01
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,112
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: Some things i'm trying to understand on Kevin's Accelerometer Code

Quote:
Originally Posted by Squall
Code:
	adc_result = ADRESH;
	adc_result <<= 8;
	adc_result += ADRESL;
We've understood that it's reading the High bits of the ADC and then it'll copy it do the lower part of the adc_result variable, this part I really can't understand.
The <<= "left shift" operator moves the value toward the upper part of the variable. With that correction, you should understand the code fine now.
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Kevin Watson's Kick-off Demo Code! Mr. Lim Programming 27 22-01-2005 03:38
Updated Encoder Code Available Kevin Watson Programming 2 04-01-2005 01:00
A Centralized Code Dump? colt527 Programming 29 01-01-2005 16:07
Recovering code from the RC Orborde Programming 15 04-12-2004 20:02
Coding / Style Standards for sharing C code Joe Johnson Programming 33 01-05-2004 15:15


All times are GMT -5. The time now is 19:16.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi