Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Accelerometer issues

Status
Not open for further replies.
Hi, You need to look at the CCPR1H and CCPR1L registers. This is were the timer value is stored. Timer3 will keep incrementing even after the falling edge event happens. Also, it is a 16-bit value so you need to examine both registers.

The datasheet doesnt give the greatest info about the output signal. It says that using the PULSEIN command gives a reading from 1000-3000, with 2500 at level. Assuming that is in uS, you should get a reading of 2.5mS at level position.

Your T3CON isnt setup correctly either. You should probably use b'01111000'.
Bits 6 and 3 determine which timer is used for the CCP module. I think your config had it set to timer1. Also I would use a x8 prescale.

If you tell me what speed you are running your pic at, I could figure out what the CCPR1H and CCPR1L should be reading at level position.

-Jacob
 
8 Mhz...
CCPR1H doesnt go higher than 8 and CCPR1L jumps from 02 to ED which seems like it still isnt getting a good reading...

bit 6 Unimplemented: Read as ‘0’

**broken link removed**
 
Last edited:
I was reading the wrong datasheet for the timer3 config, sorry. Your original config looks ok. I checked the basic stamp usage of Pulsin in the example and it measures in a 10uS scale instead of 1uS like previously thought. So now the output of the accelerometer will be:

31250uS = max
25000uS = level
18750uS = min

So if your are running the pic at 8MHz, then your instruction cycle time is 0.5uS. CCPR1H and CCPR1L should look like this with a prescale of x8:

31250uS / (0.5uS * 8) = 7813 = 0x1E85

25000uS / (0.5uS * 8) = 6250 = 0x186A

18750uS / (0.5uS * 8) = 4688 = 0x1250

So a full one 'g' measures at 7813 and zero 'g' when level is measured at 6250. This means 1563 per 'g'. So when you are level is should be around 0x18 in CCPR1H and 0x6A in CCPR1L. It will most likely jitter around since changing by one is equal to 0.0641% of a 'g'.

Also, do the readings your getting change correctly with respect to how you position the accelerometer?
 
Last edited:
OMG this gets me mad.. when i run the code now without no break points it halts still!
Code:
	movlw	0x38
	movwf	T3CON

Why would it halt on that?
Code:
	list    p=18F1320
	include	<p18F1320.inc>

	CONFIG	OSC = INTIO1, WDT = OFF, LVP = OFF, DEBUG = ON
	
Axis_Port Equ PORTB				; Set Axis_Port to Equal PortB
Axis_Tris Equ TRISB				; Set Axis_Tris to Equal TrisB
X_Axis Equ 3					; Set X_Axis to Equal 3

	org	0x0000
Init
	movlw	0x72 				; 8MHz clock select
    movwf	OSCCON
	clrf	Axis_Tris
	bsf	Axis_Tris, X_Axis
[B]	movlw	0x38
	movwf	T3CON[/B]

Main
	bcf	T3CON, TMR3ON
	clrf	TMR3L
	clrf	TMR3H
	bcf	PIR1, CCP1IF

	movlw	0x45
	movwf	CCP1CON	

	bcf	PIR1, CCP1IF
Loop1
	btfss	PIR1, CCP1IF
	goto	Loop1 
	bsf	T3CON, TMR3ON
	bcf	PIR1, CCP1IF
	movlw	0x44
	movwf	CCP1CON	
Loop2
	btfss	PIR1, CCP1IF
	goto	Loop2
	bcf	T3CON, TMR3ON
	bcf	PIR1, CCP1IF
	goto	Main
	End
 
hi atom,
Its stuck in loop1.
Which PIC pin are you inputting the acc output to.?
 
Last edited:
hi,
When running in the Oshonsoft sim, if I toggle pin RB3 the program runs from loop1 thru loop2 then back to main, thru to loop1. Waiting for the next RB3 toggle.

So its trying to work..:)
 
RB3 like this:

Code:
Axis_Port Equ PORTB				; Set Axis_Port to Equal PortB
Axis_Tris Equ TRISB				; Set Axis_Tris to Equal TrisB
X_Axis Equ 3					; Set X_Axis to Equal 3
 
hi,
When running in the Oshonsoft sim, if I toggle pin RB3 the program runs from loop1 thru loop2 then back to main, thru to loop1. Waiting for the next RB3 toggle.

So its trying to work..:)

Cool! I cant believe how much trouble this little piece of tech is lol So tiny likeless that half an square inch yet such a headache lol
 
Any luck with it?

hi Jacob,
Did you determine the "2500" output of the accelerometer to be in uSecs.?

I have not got an 'acc' on the bench, so I will have to make up an external circuit, probably using a dual mono HEF4528.
 
I originally assumed that, but then looking into the basic stamp usage of PULSIN, I found that it returned values in 10uS increments. So, 2500 = 25000uS = 25mS at level position. 31.25mS max position and 18.75mS min position.
 
Last edited:
I originally assumed that, but then looking into the basic stamp usage of PULSIN, I found that it returned values in 10uS increments. So, 2500 = 25000uS = 25mS at level position. 31.25mS max position and 18.75mS min position.

Many thanks.:)
 
hi atomsoft,

Looking at the accelerometer, you require two axis.
I have written a 'polling' program using Timer1 with PORTA.7 and 6 for the high pulse inputs of X and Y, it works OK.

Timer1 prescaler is set for 1:2 so with a 8MHz xtal you get a 1uSec count cycle.
As the 'acc' resolution is in mSec, even with this port/pin polling method the accuracy is good.

Attached a jpg of the Oshonsoft simulation.
I clicked PORTA 7 and 6 pins to give a 'high'.

If you would like me to post the program, just say.:)
 
Last edited:
cool! sorry i havent been on lately just having major pc issues spent all day yesterday backing up all my important data now i have to reinstall windows xp today. So please just bare with me. Thanks for all the help and patience guy! Your all great!
 
hi atom,

Attached two programs.
AccPoll3.asm has LCD subr.

When you have reinstalled the Windows XP into your PC, get a free copy of 'hard drive clone'..
using say a spare 40gByte drive, you can make a clone of the hard drive.

For future crashes, just clone the 'backup' clone to the new drive.
If you keep the cloned backup, upto date, its just a few minutes to get back to normal
as all your working programs and data have been cloned.
 
Last edited:
hi atom,

Attached two programs.
AccPoll3.asm has LCD subr.

When you have reinstalled the Windows XP into your PC, get a free copy of 'hard drive clone'..
using say a spare 40gByte drive, you can make a clone of the hard drive.

For future crashes, just clone the 'backup' clone to the new drive.
If you keep the cloned backup, upto date, its just a few minutes to get back to normal
as all your working programs and data have been cloned.

Cool i actually have a spare 80 but my HD is 250GB and it would be a long pain to clone it but since im going to format it will only take like 7gb of space and ill clone then
 
Cool i actually have a spare 80 but my HD is 250GB and it would be a long pain to clone it but since im going to format it will only take like 7gb of space and ill clone then


Hi,
I use the Seagate HD Wizard, from their website, get the version you can save on a CD.
 
I use the Seagate HD Wizard, from their website, get the version you can save on a CD.
I plug in the nearest Linux live disk I have at hand and use dd. It's dead simple to use and does a great job. It will copy any disk of any OS, damaged or not (if disk is damaged, set ignore error option), it doesn't care. It does a raw level copy, not file level. It's free and open source.
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top