|
|
View previous topic :: View next topic |
Author |
Message |
skeinath
Joined: 05 Aug 2019 Posts: 1
|
PIC18F2585 using Accelerometer Interrupts |
Posted: Mon Sep 30, 2019 2:04 pm |
|
|
I have a custom board with PIC18F2585, an RGB LED, and an lis3dh accelerometer.
I am trying to use the accelerometer as an interrupt to wake up the PIC.
Can someone create a simple sample project that sets the accelerometer to wake up the PIC when the board is moved?... and ideally, it would put the PIC back to sleep if it hasn't moved in N number of seconds (30)? While the PIC is awake, turn on the green LED (on = output_low).
I've read the datasheets, tried a few times, and am still lost. Sorry... I am still a beginner to embedded, especially interrupts.
R - RC0 (11)
G - RC1 (12)
B - RC2 (13)
SCL - RC3 (14)
SDA - RC4 (15)
ACCL Int 1 - RB1/INT1/AN8 (22)
ACCL Int 2 - RB2/INT2 (23)
Thank you so much in advance,
Steve |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Sep 30, 2019 4:49 pm |
|
|
See this post by newguy. He uses the accelerometer interrupt to set a
flag, which tells his main loop to clear the flag, read the accelerometer,
do some calculations, and then display the results on an lcd.
http://www.ccsinfo.com/forum/viewtopic.php?t=51309&start=1 |
|
|
benoitstjean
Joined: 30 Oct 2007 Posts: 566 Location: Ottawa, Ontario, Canada
|
|
Posted: Mon Sep 30, 2019 7:46 pm |
|
|
Hi Steve,
First, whatever you posted in your message is not useful at all. You also haven't posted any code nor your compiler version etc.
Second, if I was you I would make the simplest of all circuits using only an LED and a pushbutton.
In a while loop, just read the pushbutton and everytime it is high, turn-on the LED and when low, turn it off.
When that works, next step is to test with the interrupts.
Configure the PIC so that the input for the pushbutton is set to run as an external interrupt and when you push that button, then the LED turns-on, wait 2 seconds then turn-off.
I am using the ADXL345 accelerometer from Analog Devices and I'm using it like you are in a sense that after so many minutes, the entire circuit shuts-down and if I tap the circuit, then the circuit wakes-up.
However, considering you specified you are a beginner in embedded and whatever you posted does not provide any value for anyone to help you, there's not much we can do here and what you want to accomplish is not as simple as it sounds especially if you're a beginner.
You have to be realistic. The accelerometer has a bunch of registers that need to be configured over I2C (or SPI) therefore the learning curve might be somewhat of a challenge if you've never programmed with the PIC before and can't get a simple interrupt to work.
Interrupts are easy, it's just a matter of enabling the interrupt like this:
Code: |
#define INT_EXT1 PIN_x where 'x' is the pin ID (e.g. PIN_D5) -- Check the PIC datasheet
#define LED PIN_y where 'y' is another PIN ID like above |
Then you need the interrupt function like below:
Code: |
#INT_EXT1
void INT_EXT_INPUT1( void )
{
output_pin( LED, 1 ); // Turn-on the LED
delay_ms( 2000 ); // Wait 2 seconds
output_pin( LED, 0 ); // Turn-off the LED
}
main()
{
enable_interrupts( INT_EXT1 ); // Enable external interrupt 1
ext_int_edge( 1, H_TO_L ); // Set the interrupt to trigger on a High-to-Low transition
enable_interrupts( GLOBAL ); // Enable global interrupts
while( 1 );
}
|
Note that the code above is just to show the most basic steps... there's a LOT more to the above that is required such as fuse configuration, oscillator configuration etc.
Anyhow, start with the LED and pushbutton and when you get that to work, you will then need to figure-out how to talk to the accelerometer over I2C/SPI and when that works, then you will be able to do more.
You also need to know electronics and how to interface between the PIC and accelerometer because they may not be at the same voltages. You may also not want to drive the LED directly from the PIC output either.
Bottom line: go baby steps, one thing at a time. When one step works, proceed to the next.
That accelerometer has two interrupt outputs, one that goes high when motion is detected and one that goes high when the detected motion has stopped. It can probably do a million other things.
You will also need to provide a bit of meat to show the work you have done on your side.
Good luck.
Ben |
|
|
|
|
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 vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|