|
|
View previous topic :: View next topic |
Author |
Message |
ye
Joined: 11 May 2005 Posts: 57 Location: london
|
code halted by setup_timer_0() |
Posted: Mon Nov 21, 2005 6:59 am |
|
|
Hi all,
I have the little code below working on PIC10F200. Somehow the code is suspended by setup_timer_0(). I knew that by hooking a LED to pin 'PSU_EN'.
The code is here:
Code: | #include<10F200.h>
#fuses NOMCLR,NOWDT,NOPROTECT
#use delay( clock = 4000000 )
#bit PSU_EN = 0x06.0 // Output signal to power control circuit
#bit POWER_OFF = 0x06.1 // Input signal from main pic for indication of system status
#bit POWER_SW = 0x06.2 // Input signal from the power on button
#bit USB_SW = 0x06.3 // Input signal from USB
#use fast_io(B)
//Otherwise the compiler will want to control the TRIS
void main()
{
int timer_value;
int ellapsed_time = 0;
/////////////////////////////////////////////////////////////////////////////////////////
// Setup the timer which support a counting of at least 5 seconds //
// The timer register is 8 bit and the prescaler register is 8 bit long as well //
// Use the longest overflow time here and the timer overflows every: //
// //
// (4 * 256 / 4000000) * 256 = 665536 us = 0.67 s //
// //
// where first 256 is the prescaler value, the second 256 the timer value. //
// and 4 is from 'Fosc/4' and 4000000 is the internal clock speed //
// //
// NOTE: the product given by the bracket is 256 us which is the clock tick period //
/////////////////////////////////////////////////////////////////////////////////////////
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256);
set_tris_b(0b00001110); //Remember B3, must be an input.
while(1)
{
PSU_EN = 1;
delay_ms(500);
PSU_EN = 0;
delay_ms(500);
}
/////////////////////// Other code ////////////////////////
} |
Can you see any problem here at all?
Thx |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Mon Nov 21, 2005 10:43 am |
|
|
Your code is a simple test and doesn�t show any clue that will cause the described problem.
I would spot the troubleshoot in a hardware problem.
You had some problems when you start working with the PIC10F200,
( A problem about PIC10F200
Posted: Fri Nov 18, 2005 7:55 am )
where you didn�t save the factory OSCCAL register values at power up.
@Ttelmath direct you how to proceed regarding this. My questions are:
1) Are you working with the same PIC ?
2) If so, what�s the actual value of OSCCAL ?
3) Did you try with another PIC ?
4) What about your DC power quality, decoupler capacitor and the involved wiring ?
Best wishes,
Humberto |
|
|
ye
Joined: 11 May 2005 Posts: 57 Location: london
|
|
Posted: Mon Nov 21, 2005 11:16 am |
|
|
Thx.
I think I've figured out the problem. In MPLAB I set MCLR as 'functions as GP3' and then it worked. I don't really know why here but I suppose it has something to do with the programmer?
Yes,I am working on the same pic. Actually, I have a better version of code and I would like to post it here:
Code: | #include<10F200.h>
#fuses NOWDT,NOPROTECT
#use delay( clock = 4000000 )
#bit PSU_EN = 0x06.0 // Output signal to power control circuit
#bit POWER_OFF = 0x06.1 // Input signal from main pic for indication of system status
#bit POWER_SW = 0x06.2 // Input signal from the power on button
#bit USB_SW = 0x06.3 // Input signal from USB
#bit OSCCAL_0 = 0x05.0 // define bit 0 of OSCCAL register
#use fast_io(B) //Otherwise the compiler will want to control the TRIS
void main()
{
int timer_value,powerOn = 0;
int ellapsed_time = 0;
int i =0;
/////////////////////////////////////////////////////////////////////////////////////////
// Setup the timer which support a counting of at least 5 seconds //
// The timer register is 8 bit and the prescaler register is 8 bit long as well //
// Use the longest overflow time here and the timer overflows every: //
// //
// (4 * 256 / 4000000) * 256 = 665536 us = 0.67 s //
// //
// where first 256 is the prescaler value, the second 256 the timer value. //
// and 4 is from 'Fosc/4' and 4000000 is the internal clock speed //
// //
// NOTE: the product given by the bracket is 256 us which is the clock tick period //
/////////////////////////////////////////////////////////////////////////////////////////
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256);
// Set TRIS states. GP3 must always work as INPUT.
set_tris_b(0b11111110);
// The following assembly disables portb pull ups. There is no straight default C code to do this.
// It actually set bit 6 of OPTION register which disables week pull-ups at GP0, GP1 and GP3
#asm
movlw 0b11010111
option
#endasm
// Disable bit 0 of OSCCAL register
// Setting this bit will make GP2 work as INTOSC/4 output
// Clearing it will allow GP2 work as I/O
OSCCAL_0 = 0;
////////////////// other code /////////////////////
}
|
Thanks |
|
|
|
|
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
|