|
|
View previous topic :: View next topic |
Author |
Message |
GoldServe
Joined: 27 Jun 2005 Posts: 10
|
Simple circuit but something wrong? |
Posted: Tue Jun 28, 2005 9:36 am |
|
|
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:
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 Wed Jun 29, 2005 6:31 am; edited 3 times in total |
|
|
rwyoung
Joined: 12 Nov 2003 Posts: 563 Location: Lawrence, KS USA
|
|
Posted: Tue Jun 28, 2005 3:45 pm |
|
|
May not fix your problem but you shouldn't need to manually clear the timer 0 interrupt. The CCS ISR exit code should do that for you. Check the LST file. _________________ Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month! |
|
|
GoldServe
Joined: 27 Jun 2005 Posts: 10
|
|
Posted: Tue Jun 28, 2005 4:08 pm |
|
|
Thanks for any help you can give me. I simulated the circuit using a simulator and the pin is toggling every 1 second so that seems to work. The problem I might be having is something to do with the circuit hooked onto the PIC.
It should be very simple, driving the enable pin low to disable LDO and high to enable LDO.
????? |
|
|
Ttelmah Guest
|
|
Posted: Wed Jun 29, 2005 3:01 am |
|
|
First comment: Well done, on posting readable code!. Far better than most questioners. :-)
What are the components to the right of the PIC?. The top right pin is labelled apparently as some form of output, and is connecting back to a pin on the PIC that you have configured as an output. However also note that you have not specified #use fast_io for the PIC port, so the compiler will still be generating it's own TRIS control.
Remember that since you have set the pins as 'output', and the GPIO output register will be 'undefined' on boot up, the other pins may be high or low. Personally, if I was setting the TRIS register, I'd ensure that I set the output register to a 'known' state at the same point.
Realistically, it sounds as if there is a hardware fault of some sort in the circuit. What happens if you remove the PIC, and pull the lines up/down with a resistor?.
Best Wishes |
|
|
asmallri
Joined: 12 Aug 2004 Posts: 1634 Location: Perth, Australia
|
|
Posted: Wed Jun 29, 2005 5:44 am |
|
|
You are modifying a multibyte variable (w_millisecond++;) both inside and outside the interrupt handler. Similarly you are testing the same multibyte variable that is being modified by the interrupt handler. (Naughty naughty) There are a couple of ways around this problem. Disable the timer interrupt in the mainline before you test/modify w_millisecond++;
The other way to is use flags.
Code: |
#int_TIMER0
TIMER0_isr()
{
if (++w_millisecond == 1000)
{
w_millisecond = 0;
flag_done1000ms = true;
}
}
// global variable
boolean flag_done1000ms;
// somewhere in the initialisation phase in main before enabling interrupts
flag_done1000ms = false;
.....
while(1)
{
if (flag_done1000ms)
{
flag_done1000ms = false; // Clear timer flag
led1 = led1 ^ 1;
output_bit(PIN_A5, led1);
}
|
_________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
Last edited by asmallri on Wed Jun 29, 2005 6:10 am; edited 1 time in total |
|
|
GoldServe
Joined: 27 Jun 2005 Posts: 10
|
|
Posted: Wed Jun 29, 2005 5:57 am |
|
|
Ttelmah wrote: | First comment: Well done, on posting readable code!. Far better than most questioners. :-)
|
Thanks!
Ttelmah wrote: | What are the components to the right of the PIC?. The top right pin is labelled apparently as some form of output, and is connecting back to a pin on the PIC that you have configured as an output. |
The components are LDO regulators, TPS73601 and TPS73201. This isn't my circuit and I do wonder why the output is connected back to the pic. It doesn't make sense that the pic must know about the output state of the drivers right? I've configured the port as output so if i connect something to it, it shouldn't matter am I correct?
Ttelmah wrote: | However also note that you have not specified #use fast_io for the PIC port, so the compiler will still be generating it's own TRIS control.
Remember that since you have set the pins as 'output', and the GPIO output register will be 'undefined' on boot up, the other pins may be high or low. Personally, if I was setting the TRIS register, I'd ensure that I set the output register to a 'known' state at the same point. |
Point taken, will modify the program to reflect that.
Ttelmah wrote: | Realistically, it sounds as if there is a hardware fault of some sort in the circuit. What happens if you remove the PIC, and pull the lines up/down with a resistor?. |
I haven't gone down this route yet. I have on order a SMT soic8 to dip8 adapter coming. I can do further testing when it comes. Otherwise, I don't want to rip off the IC.
The circuit seems so simple yet it refuses to behave. I'll update the first post with the modified program. |
|
|
Ttelmah Guest
|
|
Posted: Wed Jun 29, 2005 7:12 am |
|
|
GoldServe wrote: | Ttelmah wrote: | First comment: Well done, on posting readable code!. Far better than most questioners. :-)
|
Thanks!
Ttelmah wrote: | What are the components to the right of the PIC?. The top right pin is labelled apparently as some form of output, and is connecting back to a pin on the PIC that you have configured as an output. |
The components are LDO regulators, TPS73601 and TPS73201. This isn't my circuit and I do wonder why the output is connected back to the pic. It doesn't make sense that the pic must know about the output state of the drivers right? I've configured the port as output so if i connect something to it, it shouldn't matter am I correct?
Ttelmah wrote: | However also note that you have not specified #use fast_io for the PIC port, so the compiler will still be generating it's own TRIS control.
Remember that since you have set the pins as 'output', and the GPIO output register will be 'undefined' on boot up, the other pins may be high or low. Personally, if I was setting the TRIS register, I'd ensure that I set the output register to a 'known' state at the same point. |
Point taken, will modify the program to reflect that.
Ttelmah wrote: | Realistically, it sounds as if there is a hardware fault of some sort in the circuit. What happens if you remove the PIC, and pull the lines up/down with a resistor?. |
I haven't gone down this route yet. I have on order a SMT soic8 to dip8 adapter coming. I can do further testing when it comes. Otherwise, I don't want to rip off the IC.
The circuit seems so simple yet it refuses to behave. I'll update the first post with the modified program. |
You have the first bit wrong. If something unknown is connected 'back' to a processor pin, that pin _must_ be configured as an _input_. As an output, it'll be trying to drive the signal either high or low, and if the regulator output is trying to drive it to a different voltage a relatively high current will be being drawn, possibly even shutting the circuit down. This is why the pins by default 'wake up' as inputs, since this is the 'safe' configuration...
Remove your 'TRIS' line completely. If you leave the processor in it's default state, it'll wake up with the pins as inputs. The compiler default will automatically change the pin you toggle to an 'output', as soon as you drive it, so this may well then work.
Best Wishes |
|
|
GoldServe
Joined: 27 Jun 2005 Posts: 10
|
|
Posted: Wed Jun 29, 2005 9:25 am |
|
|
Thanks. That makes sense. I'll give it a try.
All I will do now is not use the directive #use_fastio and not set the trisio register. Just use the bits (output them high or low). That sounds correct right? |
|
|
GoldServe
Joined: 27 Jun 2005 Posts: 10
|
|
Posted: Wed Jun 29, 2005 5:03 pm |
|
|
Can someone tell me why i'm getting a 3sec delay instead of a 1second delay using:
// Setup timer 0 - 1000000 / 4 / 256 = 1ms
setup_counters(RTCC_INTERNAL,RTCC_DIV_4);
setup_timer_1(T1_DISABLED);
Someone on another forum said I was getting this:
Quote: | Also note that your toggling frequency should be around 1000000/256/1000 -> 3.905Hz and not 1Hz as you are expecting ... |
|
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Thu Jun 30, 2005 1:57 am |
|
|
GoldServe wrote: | Can someone tell me why i'm getting a 3sec delay instead of a 1second delay using:
// Setup timer 0 - 1000000 / 4 / 256 = 1ms
setup_counters(RTCC_INTERNAL,RTCC_DIV_4);
setup_timer_1(T1_DISABLED);
Someone on another forum said I was getting this:
Quote: | Also note that your toggling frequency should be around 1000000/256/1000 -> 3.905Hz and not 1Hz as you are expecting ... |
| Your timer0 should fire every 1ms as expected. My guess is the person in the other forum missed your RTCC_DIV_4 parameter.
How did you meassure your 3sec. delay? Please note that your led is toggled every second, so 1 second on and 1 second off, a total off 2 seconds for a complete period. |
|
|
GoldServe
Joined: 27 Jun 2005 Posts: 10
|
|
Posted: Thu Jun 30, 2005 6:21 am |
|
|
How i'm measuring it is from the time I turn the PIC on, I count 3 seconds and the output from the LDO goes high to ~3V. When I count another 3 seconds, I'll see the voltage try to dip to 2.8V and then go back to 3V. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Thu Jun 30, 2005 8:37 am |
|
|
Which compiler version are you using?
I compiled your first version in v3.226 and the configuration looks ok. I don't have the hardware so couldn't confirm a correct timing.
Quote: | When I count another 3 seconds, I'll see the voltage try to dip to 2.8V and then go back to 3V. | This is strange, why is the voltage not dropping to 0V? Are you sure GP1 is now configured as an input? |
|
|
Ttelmah Guest
|
|
Posted: Thu Jun 30, 2005 8:46 am |
|
|
GoldServe wrote: | How i'm measuring it is from the time I turn the PIC on, I count 3 seconds and the output from the LDO goes high to ~3V. When I count another 3 seconds, I'll see the voltage try to dip to 2.8V and then go back to 3V. |
Count?...
Have you tried a watch?.
A lot of people can count quite reasonably for reasonable intervals, but go '1', 'and2', 'and3' etc., And are a good half second 'early' on the first few counts. If you are 'counting' time, you need to use something like 'thousandand1', 'thousandand2' etc..
How has the internal timing 'tweak' value been stored/kept during reprogramming?. The internal RC oscillator, is normally pretty accurate, but this tweak value must be maintained if the oscillator is going to be reasonably accurate.
Best Wishes |
|
|
djpark
Joined: 02 Mar 2004 Posts: 49
|
|
Posted: Thu Jun 30, 2005 8:51 am |
|
|
I have no objection on someone trying to put his own program on a piece of the hardware I designed.
However, he should at least keep his ethic of not removing the copyright notice from the original circuit diagram.
The original is found here and it looks clearer and it may help you to better idea of what it is supposed to do.
Anyway, it is outdated and the new version is using different GPIO to drive.
Thanks.
-- dj |
|
|
GoldServe
Joined: 27 Jun 2005 Posts: 10
|
|
Posted: Thu Jun 30, 2005 8:17 pm |
|
|
Sorry DJ, I didn't mean to take credit or not give you credit. I just didn't want people e-mailing you thinking it was me or something! Sorry again! |
|
|
|
|
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
|