 |
 |
| View previous topic :: View next topic |
| Author |
Message |
Ttelmah Guest
|
|
Posted: Sun Dec 21, 2008 3:54 pm |
|
|
Lets get this slightly clearer. Do you have an external 40MHz _oscillator module_, or are you trying to use a 40MHz _crystal_. If the latter, this is not supported by the chip. The HS _oscillator_, supports 25MHz _maximum_. Parameter 1A in table 27-6.
To make the chip run at 40MHz, you either need an exteranl module, or you need a crystal at _10MHz_, and the *4 PLL.
This is why PCM, has changed your fuses to EC_IO, which is correct for the external module.
Best Wishes |
|
 |
Izzy
Joined: 27 May 2007 Posts: 106
|
|
Posted: Sun Dec 21, 2008 4:03 pm |
|
|
Thank you so MUCH!
Finally something is working! Yeah!
Alright the problem I think was the /SYNC or slave select pin. I know I had tried it before but I didn't turn it LOW and HIGH again in the middle, before reading the data, like you did.
Also, I was thinking the /SYNC could be tied low because we dont have multiple slaves. I guess I was wrong!
I tried with ES and HS both works, so I don't know if it was a problem.
| Quote: | 5. You have changed the channel select bits from your previous code.
They are now set for channel 0. That's the AIN1 input, which is on pin 9.
Verify that your input signal are connected to this pin. |
I have 3 axis of accelerometer connected to AN1, AN2 and AN3 of the accelerometer chip.
Now I can read status register, I am pretty sure
| Code: | when I sent :
spi_write(0xE1);
spi_write(0xC1);
I read back: 61C1
when I sent :
spi_write(0xE5);
spi_write(0xC1);
I read back: 65C1
when I sent :
spi_write(0xE5);
spi_write(0xC0);
I read back: 25C0 (I dont know why it chaged the MSB) |
But I havent been able to read the ADC value. I know it worked couple of time but then I it does not work some time.
I used
I tried :
spi_write(0xE1);
spi_write(0x10);
and
spi_write(0xE5);
spi_write(0x10);
both. But still struggling. I am still working on it, if anyone finds something wrong let me know.
| Code: |
#include <18F4685.h>
#device ICD=TRUE
#fuses ES,NOLVP,NOWDT
#use delay(clock=40,000,000)
#use rs232(stream=debug, DEBUGGER)
#include <stdlib.h>
int Data_msb=0;
int Data_lsb=0;
int16 value = 0;
void main()
{
setup_spi(SPI_MASTER| SPI_H_TO_L | SPI_XMIT_L_TO_H | SPI_CLK_DIV_16);
delay_ms(250);
while(TRUE)
{
output_low(PIN_D1);
spi_write(0xE5);
spi_write(0x10);
output_high(PIN_D1);
delay_us(10);
output_low(PIN_D1);
Data_msb = spi_read(0x00);
Data_lsb = spi_read(0x00);
output_high(PIN_D1);
value = make16(Data_msb,Data_lsb);
fPrintf(debug, "Reading = %lu\n\n", value);
delay_ms(500);
}
} |
|
|
 |
Izzy
Joined: 27 May 2007 Posts: 106
|
|
Posted: Sun Dec 21, 2008 4:09 pm |
|
|
| Ttelmah wrote: | Lets get this slightly clearer. Do you have an external 40MHz _oscillator module_, or are you trying to use a 40MHz _crystal_. If the latter, this is not supported by the chip. The HS _oscillator_, supports 25MHz _maximum_. Parameter 1A in table 27-6.
To make the chip run at 40MHz, you either need an exteranl module, or you need a crystal at _10MHz_, and the *4 PLL.
This is why PCM, has changed your fuses to EC_IO, which is correct for the external module.
Best Wishes |
Hello Ttelmah,
Thanks for your reply. I am using this one,
http://www.newark.com/abracon/ach-40-000mhz-ek/oscillator/dp/13J1844
I think it is called oscillator module, right? |
|
 |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Dec 21, 2008 4:09 pm |
|
|
Disconnect the accelerometer and put a trimpot on the AIN1 pin. Set
the trimpot so it puts out a mid-range voltage, with respect to your Vref.
Change the printf to use "%LX", to show the results in hex.
Post what you get.
| Quote: | #include <18F4685.h>
#device ICD=TRUE
#fuses ES,NOLVP,NOWDT
#use delay(clock=40,000,000)
#use rs232(stream=debug, DEBUGGER)
#include <stdlib.h> |
Also, this is "typed in" code. You're not posting your real test program.
The compiler gives this error for it:
| Quote: | | Unknown keyword in #FUSES "ES" |
|
|
 |
Izzy
Joined: 27 May 2007 Posts: 106
|
|
Posted: Sun Dec 21, 2008 4:22 pm |
|
|
Sorry, that is "EC", I was trying with HS to make sure it works with HS too.
I will try with trim pot and let you know. Please note I have attached a 2.7V zener at the reference pin of the AD. The accelerometer gives 1.66V - 1.99V on the three outputs. |
|
 |
Izzy
Joined: 27 May 2007 Posts: 106
|
|
Posted: Sun Dec 21, 2008 6:44 pm |
|
|
Once again , thanks to both PCM programmer and Ttelmah!
Guys like you is what makes this forum so valuable!
After spending some hour, I think the problem is I have to reset the whole circuit from time to time to make the accelerometer working. So if I reset the power to the circuit then it will work fine, but after few compiling the program and downloading, it starts to give 0. I am sure its the AD chip. I will try to look if I have to reset the AD chip internally or something.
But once again, I am so glad It worked! |
|
 |
|
|
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
|