|
|
View previous topic :: View next topic |
Author |
Message |
potato
Joined: 23 Mar 2014 Posts: 16
|
no output voltage? :S |
Posted: Wed May 07, 2014 3:58 am |
|
|
Hi again!
I'm using PIC18F4550 and I have a problem:
I have some leds and buttons connected to the PIC, this way:
-led1: pin a4
-led2: pin a5
-led3: pin c6
-led4: pin c7
(originally, leds 1 and 2 were connected to pins c4 and c5, but later on I realised they were only INPUT pins...)
-button1: pin b0
-button2: pin b1
-button3: pin b2
-button4: pin b3
The idea is that, when you press a button, the corresponding led has to illuminate for 2 seconds (to simplify).
I think I have a hardware problem, because led3 is working fine, and I have a sub-routine that makes the led blink - the same for all of the leds! I have declared the input/output ports correctly, I think. Here they are:
Code: | set_tris_a(0x00);
set_tris_b(0xFF);
set_tris_c(0b0000111); //declared this way because there are only 7 pins
set_tris_d(0x00);
set_tris_e(0x00); |
The problem is that, whereas led3 is wonderful and receives tension from the PIC, leds 1 and 2 don't receive any tension, but the logic state is changed in the PIC (Because I also have a LCD screen that shows the colour of the pressed button). On the other hand, led4 does nothing -neither receiving tension nor changing its logical state.
Any ideas about why could it be?
Thanks for your time |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Wed May 07, 2014 5:23 am |
|
|
Normally you have to disable any/all peripherals that are on any I/O pin you use for simple 'on/off' use. Things like ADC, comp,PWM, etc.
Now you say the LEDs are OK...so it's just the 'buttons' that don't work ? If so what steps have you taken to eliminate 'debounce'? Unless you're using SS switches,debounce will be a huge problem.
We'll have to see your test program to see what else it might be.....
hth
jay |
|
|
potato
Joined: 23 Mar 2014 Posts: 16
|
|
Posted: Wed May 07, 2014 5:50 am |
|
|
Hi temtronic, thanks for your reply. I have a couple of doubts about your answer:
temtronic wrote: | Normally you have to disable any/all peripherals that are on any I/O pin you use for simple 'on/off' use. Things like ADC, comp,PWM, etc. |
Do you mean on the main code? Is it necessary to write that "default" configuration, that states no adc config and so on? I always delete it because I think that if I'm not using it.. is it an error? what automatically appears to me after creating a project with the wizard is:
Code: | setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE); |
(well, in my program I need timers, so I enable them)
I've added them to my project, but still...
I have done a test program and, guess what? Everything works fine there! The four leds illuminate and there's no problem with the buttons... But when I copy EXACTLY the same code into the general program... problems appear again!
I use a 50 ms delay to avoid debouncing, but in the test program I don't use it and it works fine - these buttons are quite reliable! So I don't think there's a problem with that...
By the way, more funny things with the test program:
When I tried only (output_high) it worked fine. Now I've added a 2 s delay, and the leds won't go off.
Code: | #include "D:\.....h"
void main()
{
//to start with all the leds off
output_low(pin_a4);
output_low(pin_a5);
output_low(pin_c6);
output_low(pin_c7);
while (1)
{
if ((input(PIN_b4))==0) //if the button is pressed
{
output_high(pin_a4); //illuminate the led
delay_ms(2000); //for 2 seconds
output_low(pin_a4);
}
if (((input(PIN_b5))==0))
{
output_high(pin_a5);
delay_ms(2000);
output_low(pin_a5);
}
if ((input(PIN_b6))==0)
{
output_high(pin_c6);
delay_ms(2000);
output_low(pin_c6);
}
if (((input(PIN_b7))==0))
{
output_high(pin_c7);
delay_ms(2000);
output_low(pin_c7);
}
}
} |
Why? |
|
|
gpsmikey
Joined: 16 Nov 2010 Posts: 588 Location: Kirkland, WA
|
|
Posted: Wed May 07, 2014 8:50 am |
|
|
While this is probably not your problem, you don't mention series current limit resistors for the LED's - you should have a 330 - 470 ohm resistor in series with each led to limit the current - making the processor limit the current is asking for problems (either heat or blowing an output bit).
mikey _________________ mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3 |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Wed May 07, 2014 9:57 am |
|
|
re: defaults
The 'problem' with defaults is WHO decides what the defaults are !
The 'wizard' might assume you use a,b,c and not d...
The compiler might assume you use a and d but not b and c...
The 'newer' version of either might decide that was all nuts and change the 'defaults' again !!!
Reality is you need something else......
When YOU specify the defaults you KNOW what they are and can concentrate on code issues NOT defaults that are wrong for your application.
Same thing holds true for 'fuses'. Modern PICs have more fuses than instructions!! Once I get a set of fuses that works, I save them as a file, then 'include' it in future projects.that way I start off with a KNOWN set of fuses.
hth
jay |
|
|
|
|
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
|