|
|
View previous topic :: View next topic |
Author |
Message |
g60luke
Joined: 04 May 2011 Posts: 3
|
Problem reading inputs |
Posted: Wed Jun 15, 2011 2:17 am |
|
|
Hi,
I am trying to read inputs on a 18f4550 PIC, whilst toggling the outputs.
For some reason I am getting erroneous reads, and the chip seems to latch in a wrong read state until another state change on the pins.
The inputs are on the USB pins (RC4/RC5) but are set up to be digital inputs.
I have a guaranteed input state generator that spends equal times for states i.e. 00 , 01 , 10 , 11 and then return.
I have an array called read[4], so expect when I run my code I expect an even distribution of values in read[0]/read[1]/read[2]/read[3].
However this is not the case, unless I remark the calls to output_a/b/c/d/e out. Then it works correctly.
It seems like the chip has a problem reading the input pins while driving outputs?!
This is my code:
Code: |
void main()
{
int count = 0;
int data[4] = {0,0,0,0};
int read;
phase_animation = 0xFF;
port_b_pullups(FALSE);
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_16|RTCC_8_bit);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DIV_BY_1,249,10);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
enable_interrupts(INT_RTCC);
enable_interrupts(INT_TIMER2);
enable_interrupts(GLOBAL);
setup_low_volt_detect(FALSE);
setup_oscillator(False);
disable_interrupts(GLOBAL);
set_tris_a(0x00);
set_tris_b(0x00);
set_tris_c(0x30);
set_tris_d(0x00);
set_tris_e(0x00);
//Make the USB inputs just digital IO
UCON = 0x00;
UCFG = 0x08;
for(;;)
{
delay_ms(1);
output_a(val);
output_b(val);
output_c(val);
output_d(val);
output_e(val);
read = input_c();
read >>= 4;
read &= 0x3;
data[read]++;
if(count == 250)
{
if(val) val = 0;
else val = 0xFF;
count = 0;
}
count++;
}
} |
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19506
|
|
Posted: Wed Jun 15, 2011 3:36 am |
|
|
Have you got #use fast_io(c)?.
If not, your TRIS will be being overridden, when you perform output_c(val), with the pins being switched to output....
What you actually then 'see', will depend on the capacitance on the bus, and how quickly the line then returns to the value coming from your external source.
Best Wishes |
|
|
g60luke
Joined: 04 May 2011 Posts: 3
|
|
Posted: Wed Jun 15, 2011 9:56 am |
|
|
I have tried all the #IO directives and it still does not work.
It is fine if I move to the RB6/RB7 pins, but the RC4/RC5 which are the USB pins configured as digital inputs are the problem?!
I have even stopped using the output_x and input_x functions and use my own register mapped calls, and still the same.
It looks like a fault with the USB port and it latching in a wrong state until the next state change |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Jun 15, 2011 5:02 pm |
|
|
1. Post the #include, #fuses, #use delay(), and any other #use
statements, and #byte statements, etc., so the program can be
compiled. They need to be the exact lines that you're using.
2. Post a description of any external circuits that are connected to
pins C4 and C5. Post the Vdd voltage of the PIC and any other
applicable details.
3. Post your compiler version.
4. Post how you are testing this. I don't see any printf statements to
show values. Are you stepping through this code in a debugger ?
What debugger ? Are you using breakpoints and a Watch window ?
Describe how you are testing it.
If you can do all that, I'll test it tomorrow in hardware. |
|
|
g60luke
Joined: 04 May 2011 Posts: 3
|
|
Posted: Thu Jun 16, 2011 5:48 am |
|
|
Fixed now!!!
VUSB Cap not fitted, so internal regulator for transceiver not decoupled correctly
Thanks for all the replies ;)
Cheers
Luke |
|
|
|
|
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
|