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.
Should the INTIO1 be INTIO2 tho?

7. INTIO1 Internal Oscillator with FOSC/4
output on RA6 and I/O on RA7
8. INTIO2 Internal Oscillator with I/O on RA6
and RA7

Also i edited code but still some issue gonna try something brb
Code:
;May2008 Atomsoft
;Polling Accelerometer X and Y axis, using PORTA.7 and PORTA.6
;Timer1 holds the count equal to the time A.7 or A.6 are high
;The count is then transferred to XaxisH/L and YaxisH/L
;No LCD display on this version, so delays in the program.

	list    p=18F1320
	include	<p18F1320.inc>
	CONFIG	OSC = INTIO2, WDT = OFF, LVP = OFF, DEBUG = ON
	

XaxisH EQU 0x14
XaxisL EQU 0x15
YaxisH EQU 0x16
YaxisL EQU 0x17

				
	org	0x00
	goto	Init	;go to start of main code

	ORG	0x0008	;High priority interrupt vector
	retfie
	ORG	0x0018	;low priority interrupts
	retfie

Init:
	movlw	0x72	; 8MHz clock select
    	movwf	OSCCON
	clrf	TRISB	;PORTB all outs
[B]	bsf		TRISA, 6
	bsf		TRISA, 7[/B]
	
	movlw 0x10	;prescaler 1:2, 8MHz xtal, so 1uSec clock
	movwf T1CON	;stop TMR1

Main:
	Call Read_X
	Call Read_Y
	nop
	;LCD subr goes here

	goto Main

Read_X: 	;if PORTA.7 already High, then wait for low
	btfsc 	PORTA,7
	return
WaitA7_Hi:	;wait for PORTA.7 to go high
	btfss 	PORTA,7
	goto	WaitA7_Hi
	bsf 	T1CON,TMR1ON	;start TMR1
WaitA7_Lo:
	btfsc 	PORTA,7
	goto	WaitA7_Lo

	bcf 	T1CON,TMR1ON	;stop TMR1
	;
	movf 	TMR1H,W		;read TMR1 and save count
	movwf 	XaxisH
        movf 	TMR1L,W
	movwf 	XaxisL
	clrf 	TMR1H
	clrf 	TMR1L
	return


Read_Y:		;if PORTA.6 already High, then wait for low
	btfsc 	PORTA,6
	return
WaitA6_Hi:	;wait for PORTA.6 to go high
	btfss 	PORTA,6
	goto	WaitA6_Hi
	bsf 	T1CON,TMR1ON
WaitA6_Lo:
	btfsc 	PORTA,6
	goto	WaitA6_Lo

	bcf 	T1CON,TMR1ON
	;
	movf 	TMR1H,W
	movwf 	YaxisH
        movf 	TMR1L,W
	movwf 	YaxisL
	clrf 	TMR1H
	clrf 	TMR1L
	return


	End

For some reason my watch window doesnt let me put the variable in it...
 
Last edited:
i does in fact get a much steady result maybe like 3a-3e result jumps which is awesome .. Will post some extra code when done making it
 
Last edited:
Actually varies about digits so 1-8 tops per digit tho like on meter its

2.49v reads
L:0x84-0x8A
H:0x13

2.50v
L:0x98-0x9C
H:0x13

2.51v reads
L:0xA7-0xAE
H:0x13

code:
Code:
;May2008 Atomsoft
;Polling Accelerometer X and Y axis, using PORTA.7 and PORTA.6
;Timer1 holds the count equal to the time A.7 or A.6 are high
;The count is then transferred to XaxisH/L and YaxisH/L
;No LCD display on this version, so delays in the program.

	list    p=18F1320
	include	<p18F1320.inc>

	CONFIG	OSC = INTIO2, WDT = OFF, LVP = OFF, DEBUG = ON
	

XaxisH EQU 0x14
XaxisL EQU 0x15
YaxisH EQU 0x16
YaxisL EQU 0x17

				
	org	0x00
	goto	Init	;go to start of main code

	ORG	0x0008	;High priority interrupt vector
	retfie
	ORG	0x0018	;low priority interrupts
	retfie

Init:
	movlw	0x72	; 8MHz clock select
    movwf	OSCCON
	clrf	TRISB	;PORTB all outs
	bsf		TRISA, 6
	bsf		TRISA, 7
	
	movlw 0x10	;prescaler 1:2, 8MHz xtal, so 1uSec clock
	movwf T1CON	;stop TMR1

Main:
	Call Read_X
    Call Read_Y
	nop

	goto Main

Read_X: 	;if PORTA.7 already High, then wait for low
	btfsc 	PORTA,7
	return
WaitA7_Hi:	;wait for PORTA.7 to go high
	btfss 	PORTA,7
	goto	WaitA7_Hi
	bsf 	T1CON,TMR1ON	;start TMR1
WaitA7_Lo:
	btfsc 	PORTA,7
	goto	WaitA7_Lo
	bcf 	T1CON,TMR1ON	;stop TMR1
	movf 	TMR1H,W		;read TMR1 and save count
	movwf 	XaxisH
    movf 	TMR1L,W
	movwf 	XaxisL
	clrf 	TMR1H
	clrf 	TMR1L
	return


Read_Y:		;if PORTA.6 already High, then wait for low
	btfsc 	PORTA,6
	return
WaitA6_Hi:	;wait for PORTA.6 to go high
	btfss 	PORTA,6
	goto	WaitA6_Hi
	bsf 	T1CON,TMR1ON
WaitA6_Lo:
	btfsc 	PORTA,6
	goto	WaitA6_Lo
	bcf 	T1CON,TMR1ON
	movf 	TMR1H,W
	movwf 	YaxisH
    movf 	TMR1L,W
	movwf 	YaxisL
	clrf 	TMR1H
	clrf 	TMR1L
	return


	End
 
Last edited:
Use the Add Symbol button to add a watch variable.

LOL i know that lol but its greyed out... 8.10 MPLAB has so many bugs



Futz forgot to tell you thanks and i love your site... (all the info and layout and all!)

Ill be making a site pretty soon also. I know some HTML, PHP, MYSQL and stuff// so shouldnt be to hard :D
 
hi atomsoft,
Attached AccPoll3_1.asm

This version now tested physically in a programmed PIC18F1320 works OK.
Uses a LCD 2line, HD44780 to display X and Y axis counts, refresh rate set for 250mSec interval.

Checked over 1mS pulse [1000 cnts] thru to 50mSec [50,000 cnts] on PORTA.7 and PORTA.6, all OK.

Sorry about the loss of some of the source text formatting, the MPLAB IDE decided to trash it..? No changes to the 'properties'.??

Delete the previous AccPoll3.asm.
 
Last edited:
wow thanks will check it out.. The only thing is my last 2x16 lCD broke so i might have to order a new one .. but for now i will see what i can do in debug mode... Thanks
 
Futz forgot to tell you thanks and i love your site... (all the info and layout and all!)
Thanks Atom.

Ill be making a site pretty soon also. I know some HTML, PHP, MYSQL and stuff// so shouldn't be too hard :D
I used to hard code all my sites. But then making changes and updates was kind of a pain so they tended to never get done. So this time I went with a CMS (Content Management System). Joomla 1.5. It's a bit buggy, but you soon discover what the bugs are and learn to work around them (not a big deal - just some editor quirks). It's free. Building templates for it is a chore, but luckily I like the stock one fine. Joomla makes updates and changes easy as it's built for blogging and that style of site.
 
Oh ya! Got my gyro yesterday. Only had a little spare time last night so I only got pins soldered onto it and did a bit of datasheet reading. Tonight I plan to try to get it doing something. Maybe get that evil little balancer to actually balance. :D

my last 2x16 lCD broke so i might have to order a new one
How do you break an LCD? :p
 
Last edited:
Not sure how but doesnt work so not going to kill myself checking it

EDIT:
Good luck with the balancer. Cant wait to see the results.
 
Last edited:
Not sure how but doesnt work so not going to kill myself checking it

EDIT:
Good luck with the balancer. Cant wait to see the results.

hi atomsoft,
In order to access the UART's TX/RX, CCP1 and T0CK1 pins for future development of your project I have modified the LCD pin connections.

LCD data[4] are on A0 thru A3 and the LCD control[3] are on B5 thru B7.

The program has been tested in a 18F1320, also a PIC pin out drawing is available.. If you are interested, just ask and I will post.:)
 
I bought a memsic 2125 and connect to my 18f2550. I get a value of 6200 with a 20 MHZ OSC, but with a multimeter 2.5V on a glad surface. I think i make a mistake, but where ?

xtilt var word
PULSIN PORTB.1,1,xtilt
 
The value which I read on PIC is 4.8 time more then value which should be. My OSc is 20 MHZ i know, how can it react like a 96MHZ ? I have problems also with serial comm. despite I write DEFINE OSC 20...

Can someone help me ?
 
Last edited:
The value which I read on PIC is 4.8 time more then value which should be. My OSc is 20 MHZ i know, how can it react like a 96MHZ ? I have problems also with serial comm. despite I write DEFINE OSC 20...

Can someone help me ?

Hi,
I would suggest you start your own new thread, you will get more help.:)
 
It is normal for the multimeter to read 2.5V bacause the output of the Mx2125 is 5V PWM that has 50% duty cycle on a level surface. It is also normal to get different values even if not moving, i think due to its sensitivity to vibration. Yes you can add capacitors near the supply pin.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top