CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

External adc 1110 with pic18f4550
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
SET



Joined: 15 Nov 2005
Posts: 161
Location: Glasgow, UK

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Tue Sep 02, 2008 6:59 am     Reply with quote

Quote:
Code:

spi_write(controlo);
//delay_ms(50);  <<-- you need some delay here to let ADC convert!
RB2=spi_read(0); /*guarda os 1ºs 8 bits*/
delay_ms(25);
RB3=spi_read(0); /*guarda os 2ºs 8 bits*/ // adc recebe o byte respectivo para o pin a ler
madeiras



Joined: 12 Feb 2008
Posts: 14

View user's profile Send private message

PostPosted: Wed Sep 03, 2008 4:04 am     Reply with quote

SET wrote:
Quote:
Code:

spi_write(controlo);
//delay_ms(50);  <<-- you need some delay here to let ADC convert!
RB2=spi_read(0); /*guarda os 1ºs 8 bits*/
delay_ms(25);
RB3=spi_read(0); /*guarda os 2ºs 8 bits*/ // adc recebe o byte respectivo para o pin a ler


I´ve already tried with different delays, but still don´t work. it´s strange, i´ve already used this code and the same circuit with a ATMEL and it worked! i will try the suggestion of PCM do implement the circuit on that pdf.
in mean while, if someone see and error on my code, please say, tk´s you all!
Ttelmah
Guest







PostPosted: Wed Sep 03, 2008 4:21 am     Reply with quote

Speed.
PCM Programmer already raised this, and you told him the crystal was 20MHz. What you didn't say was that you were using the PLL, and running at 48MHz....

At 48MHz, you are trying to clock the SPI 50% faster than the chip supports.
You need to drop the SPI clock rate below 500KHz. To get this, you need to change it to using the Timer2/2 clock source, rather than the master oscillator. SPI_CLK_T2. Then set Timer2 to output a frequency not over 1Mhz. So, say the 1:1 prescaler, and division by 48:

setup_timer_2(T2_DIV_BY_1,47,1);

This then makes your SPI rate 'legal'.

Best Wishes
madeiras



Joined: 12 Feb 2008
Posts: 14

View user's profile Send private message

PostPosted: Wed Sep 03, 2008 3:54 pm     Reply with quote

Thanks to all, I finally put this to work! Thanks for the help!
It was the time of the adc, that wasn't enough to convert. Problem solved.
SET



Joined: 15 Nov 2005
Posts: 161
Location: Glasgow, UK

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Thu Sep 04, 2008 3:34 am     Reply with quote

Its not just a coding issue, its understanding what the devices actually do - thats why it jumped out at me, you were sending the ADC setup/convert command and then (a few tens of nanoseconds later) expecting the ADC result to be there Very Happy
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
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