View previous topic :: View next topic |
Author |
Message |
tesla80
Joined: 23 May 2007 Posts: 81
|
TSL1406R and 18F252 |
Posted: Thu May 31, 2007 10:23 am |
|
|
Hi All,
if any body know some think about this sensor please help me.
I read datasheet and wrote a routine but doesn,t work correctly
I,m appling Fclock about 4-5 MHz
but signal SO2 is coming early and I see 1 or 2 counted pixels.
This have to be 768 pixels.
Here is a routine for to count pixels;
Code: | void cp() {
PixelCount=0;
CK=1;SI=1;CK=0;SI=0;
while(!SO) {
CK=1;restart_wdt();
CK=0;
PixelCount++;
}
printf("Pixel: %lu\n",PixelCount);
return;
} |
|
|
|
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
Posted: Thu May 31, 2007 11:48 am |
|
|
In order for a pin to be driven high you can't simply write a statement like 'CK=1'. You need to use input() or output() commands to change the state of an I/O.
Try:
Code: | void cp() {
PixelCount=0;
output_high(CK);
output_high(SI);
output_low(CK);
output_low(SI);
while(!SO) {
output_high(CK);
restart_wdt();
output_low(CK);
PixelCount++;
}
printf("Pixel: %lu\n",PixelCount);
return;
} |
I don't know anything about this sensor so I can't say this will talk to it properly. This is the proper way to manipulate an I/O unless you are using fast_io but that's another can of worms for somebody that's not very experienced.
Ronald |
|
|
tesla80
Joined: 23 May 2007 Posts: 81
|
|
Posted: Thu May 31, 2007 1:47 pm |
|
|
Code: | #byte PORTC = 0xF82
#byte PORTB = 0xF81
#byte PORTA = 0xF80
#bit DI = PORTA.1
#bit SO = PORTB.2
#bit SI = PORTB.1
#bit CK = PORTB.0
.
.
.
SET_TRIS_A(0b00111111);
SET_TRIS_B(0b00000100); // SO pin is input
SET_TRIS_C(0b10000000); // RX pin is input
PORTA = 0;
PORTB = 0;
PORTC = 0; |
|
|
|
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
Posted: Thu May 31, 2007 4:42 pm |
|
|
You must also add the following if you want to use the set_tris option:
#use fast_io(a)
#use fast_io(b)
#use fast_io(c)
Ronald |
|
|
tesla80
Joined: 23 May 2007 Posts: 81
|
|
Posted: Sat Jun 02, 2007 3:54 pm |
|
|
ok, but it still doesn't work.
Last edited by tesla80 on Thu Jun 10, 2010 3:29 pm; edited 1 time in total |
|
|
merakliev Guest
|
|
Posted: Mon Jun 04, 2007 11:41 am |
|
|
a solution? |
|
|
|