| Author |
Message |
GoldServe
Joined: 29 Jun 2005 Posts: 31
|
29 Jun 2005 3:11 PIC: Simple circuit but something wrong? |
|
|
|
|
Hi, I'm new to PIC programming but this circuit and program is too simple but it doesn't work. Below is the circuit I'm working with:
http://img200.echo.cx/my.php?image=popschematics9dr.png
And code:
| Code: |
#include <12F675.h>
#device adc=8
#use delay(clock=4000000)
#fuses NOWDT,INTRC_IO, NOCPD, NOPROTECT, NOMCLR, PUT, BROWNOUT
#rom 0x3FF = {0x3480}
// Global Variables
int16 w_millisecond = 0;
boolean flag_done1000ms = FALSE;
#int_TIMER0
TIMER0_isr()
{
if (++w_millisecond == 1000)
{
w_millisecond = 0;
flag_done1000ms = true;
}
}
void main()
{
int8 led1 = 0;
// Disable ADC and set digital ports
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
// Setup timer 0 - 1000000 / 4 / 256 = 1ms
setup_counters(RTCC_INTERNAL,RTCC_DIV_4);
setup_timer_1(T1_DISABLED);
// Disable comparator and set digital ports
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
// Enable interrupts
clear_interrupt(INT_TIMER0);
enable_interrupts(INT_TIMER0);
enable_interrupts(GLOBAL);
// Set all pins output and output to 0
#use fast_io(a)
set_tris_a(0x0a); //GPIO3 as input, GPIO1 as input
output_a(0x00);
while(1)
{
if (flag_done1000ms)
{
flag_done1000ms = false; // Clear second timer
led1 = led1 ^ 1;
output_bit(PIN_A2, led1);
output_bit(PIN_A5, led1);
}
} // End while(1)
}
|
The behaviour I am seeing is that after ~2-3sec, the votage and the output of the LDO drivers (TPS73601) goes to 3V as expected, but does not drop back down to 0V after 1sec as programmed.
The circuit simulates fine, with the output toggling ever 1 second but voltages aren't toggling.
The only other thing I can think of is that I'm programming the chip with everything connected but no power is supplied to the other components so it shouldn't affect anything right? The programmer says it is programming fine.
I'm soooooo lost so any help would be grateful! Thanks.
Last edited by GoldServe on 29 Jun 2005 14:19; edited 2 times in total |
|
| Back to top |
|
 |
petarpav
Joined: 25 Mar 2002 Posts: 557 Helped: 8
|
29 Jun 2005 8:25 PIC: Simple circuit but something wrong? |
|
|
|
|
Hi. I thing you don't have to clear timer interrupt ( clear_interrupt(INT_TIMER0); - CCS clear if need it)
And try to turn off Brounout.(#fuses NOWDT,INTRC_IO, NOCPD, NOPROTECT, NOMCLR, PUT, NOBROWNOUT).
Best Regards.
|
|
| Back to top |
|
 |
C-Man
Joined: 19 Jul 2001 Posts: 1235 Helped: 73
|
29 Jun 2005 8:50 Re: PIC: Simple circuit but something wrong? |
|
|
|
|
Try replacing
#rom 0x3FF = {0x3400}
by
#rom 0x3FF = {0x3480}
This is the calibration value of the internal oscillator maybe it makes a difference and the value you are using (0x00) is one of the two extreme values.
And yes you have to clear the timer0 interrupt flag this is NOT cleared by hardware ...
Also note that your toggling frequency should be around 1000000/256/1000 -> 3.905Hz and not 1Hz as you are expecting ...
best regards
Last edited by C-Man on 29 Jun 2005 10:09; edited 1 time in total |
|
| Back to top |
|
 |
Google AdSense

|
29 Jun 2005 8:50 Ads |
|
|
|
|
|
|
| Back to top |
|
 |
simce
Joined: 09 Jan 2004 Posts: 195
|
29 Jun 2005 8:57 Re: PIC: Simple circuit but something wrong? |
|
|
|
|
What is the purpose of serial MOSFET?
In sw there are few mistakes:
1. All pins are configured as outputs, but GP1 ascts as input! I'm not sure if this pin can force its state in logic 0, but you must make it as input [set_tris_a(0b00000010)].
2. You are toggling only one EN pins of LDO. Both GP4 and GP5 has to be toggled in the same time.
3. Turn off BROWNOUT as said before.
|
|
| Back to top |
|
 |
GoldServe
Joined: 29 Jun 2005 Posts: 31
|
29 Jun 2005 14:13 Re: PIC: Simple circuit but something wrong? |
|
|
|
|
In CCS, the interrupt is cleared for you automatically as exit code of the interrupt. I can confirm this by
004E: BCF 0B.2
004F: BCF 0A.3
I will try not setting brownout.
Why is it division by 1000000/256/100? The option prescaler is 001 which is 4 for timer0 and 2 for WDT.
The mosfet is there to protect the user from putting thte battery in reverse.
I will toggle both pins. But what's keeping me from shutting off one LDO and turning on another?
Thanks for all the help!
|
|
| Back to top |
|
 |
simce
Joined: 09 Jan 2004 Posts: 195
|
30 Jun 2005 11:53 Re: PIC: Simple circuit but something wrong? |
|
|
|
|
| Quote: |
The mosfet is there to protect the user from putting thte battery in reverse.
|
Instead of using mosfet, put LDO regulator or 78L05, BAT85 for protection of inverse battery connection and 9V battery .
| Quote: |
I will toggle both pins. But what's keeping me from shutting off one LDO and turning on another?
|
First of all what is the purpose of using two instead of one LDO? You can also remove one LDO.
I have not studied datasheet for used LDO's, but i suppose that when LDO is in disabled state its output is not in high-z state.
|
|
| Back to top |
|
 |
GoldServe
Joined: 29 Jun 2005 Posts: 31
|
30 Jun 2005 14:06 Re: PIC: Simple circuit but something wrong? |
|
|
|
|
| The battery protection should work with the mosfet. It is a low RDSON mosfet so it should be pretty good. I need two LDOs because I am lighting a LED and I want different brightnesses. One LDO will output 400ma and the other, 600ma. When they are both turned on, the LED should draw max power.
|
|
| Back to top |
|
 |
simce
Joined: 09 Jan 2004 Posts: 195
|
30 Jun 2005 14:31 Re: PIC: Simple circuit but something wrong? |
|
|
|
|
| What is the voltage of battery? Pic can work within 4.5-5.5V and when LDO for LED draws power from battery, it is most expected that voltage on battery will drop and make unexpected situation with PIC registers. Anyhow, you should use LDO instead of MOSFET in order to have regulated power on PIC.
|
|
| Back to top |
|
 |
GoldServe
Joined: 29 Jun 2005 Posts: 31
|
30 Jun 2005 15:25 Re: PIC: Simple circuit but something wrong? |
|
|
|
|
| The volatge on the battery is a li-on battery at 3.7V. This circuit was working with the original code in it (not my code). I do not have access to the code so i'm re-programming this thing from the start. I'm sure this circuit was working before. Thanks.
|
|
| Back to top |
|
 |