romel_emperado
Advanced Member level 2
- Joined
- Jul 23, 2009
- Messages
- 606
- Helped
- 45
- Reputation
- 132
- Reaction score
- 65
- Trophy points
- 1,318
- Location
- philippines
- Activity points
- 6,061
I've jumped quite late into the discussion, so please refresh my memory. Are you using a PIC16F628 in your design?
By the way, one of the best online tutorials for Hi-Tech C compiler I've come across is:
**broken link removed**
They cover both the baseline and midrange PICs using both Assembly and Hi-Tech C. The each tutorial is in PDF form along with the source code.
All Gooligum tutorials are very professionally done and well thought out, very impressive considering they are free.
Let me know the PIC you are using in your designs and I'll download the datasheet.
---------- Post added at 23:19 ---------- Previous post was at 22:37 ----------
Disable Brown-Out Detection by adding the Configuration Register Macro just after htc.h include statement:
Code:#include <htc.h> __CONFIG(WDTE_OFF & HS & ....... & BOREN_OFF)
Be sure to use the correct and appropriate configuration mask definitions which are listed in the pic16f628.h found in the include directory in the Hi-Tech compiler directory.
Code:#ifndef _HTC_H_ #warning Header file pic16f628.h included directly. Use #include <htc.h> instead. #endif /* header file for the MICROCHIP PIC microcontroller * 16F628 */ #ifndef __PIC16F628_H #define __PIC16F628_H // // Configuration mask definitions // // Config Register: CONFIG #define CONFIG 0x2007 // Oscillator Selection bits // ER oscillator: CLKOUT function on RA6/OSC2/CLKOUT pin, Resistor on RA7/OSC1/CLKIN #define FOSC_ERCLK 0xFFFF // ER oscillator: I/O function on RA6/OSC2/CLKOUT pin, Resistor on RA7/OSC1/CLKIN #define FOSC_ERIO 0xFFFE // INTRC oscillator: CLKOUT function on RA6/OSC2/CLKOUT pin, I/O function on RA7/OSC1/CLKIN #define FOSC_INTOSCCLK 0xFFFD // INTRC oscillator: I/O function on RA6/OSC2/CLKOUT pin, I/O function on RA7/OSC1/CLKIN #define FOSC_INTOSCIO 0xFFFC // EC: I/O function on RA6/OSC2/CLKOUT pin, CLKIN on RA7/OSC1/CLKIN #define FOSC_ECIO 0xFFEF // HS oscillator: High-speed crystal/resonator on RA6/OSC2/CLKOUT and RA7/OSC1/CLKIN #define FOSC_HS 0xFFEE // XT oscillator: Crystal/resonator on RA6/OSC2/CLKOUT and RA7/OSC1/CLKIN #define FOSC_XT 0xFFED // LP oscillator: Low-power crystal on RA6/OSC2/CLKOUT and RA7/OSC1/CLKIN #define FOSC_LP 0xFFEC // Watchdog Timer Enable bit // WDT enabled #define WDTE_ON 0xFFFF // WDT disabled #define WDTE_OFF 0xFFFB // Power-up Timer Enable bit // PWRT disabled #define PWRTE_OFF 0xFFFF // PWRT enabled #define PWRTE_ON 0xFFF7 // RA5/MCLR pin function select // RA5/MCLR pin function is MCLR #define MCLRE_ON 0xFFFF // RA5/MCLR pin function is digital input, MCLR internally tied to VDD #define MCLRE_OFF 0xFFDF // Brown-out Reset Enable bit // BOD Reset enabled #define BOREN_ON 0xFFFF // BOD Reset disabled #define BOREN_OFF 0xFFBF // Low-Voltage Programming Enable bit // RB4/PGM pin has PGM function, low-voltage programming enabled ... ... ... ...
This is the preferable method rather than using a value such as 0x3F3, as it is much easier to set/unset the correct bits in the Configuration Register.
However, a brown-out condition occurring with such regularity is an indication of more serious problems which should be dealt with directly.
// Power up timer enable
#define PWRTEN 0x3FF7
#define PWRTDIS 0x3FFF
the POWER ON reset is currently disabled in my configuration.. I will try that first before going to hardware.. I think this will solve my problem..
Yes, that definitely could be your problem and it would explain several of the problems you have described.
Ciao
T0IF cause the trouble
char count;
void interrupt timer0_isr(void)
{
count++;
if(count == 16) // 16 for 1 second
{
PORTB++; // effect a change on PORTB
count = 0;
}
T0IF = 0; //
}
char count;
void interrupt timer0_isr(void)
{
count++;
if(count == 16) // 16 for 1 second
{
PORTB++; // effect a change on PORTB
count = 0;
T0IF = 0; //disable timer interrupt
}
}
#include<htc.h>
__CONFIG(FOSC_INTOSCIO & WDTE_OFF & PWRTE_ON & MCLRE_ON & BOREN_OFF & CP_OFF);
int count;
void interrupt timer0_isr(void)
{
T0IF = 0;
count= count+1;
PORTB ^= 1;
}
void main()
{
OPTION_REG = 0b0111; // prescale by 256
T0CS = 0; // select internal clock
T0IE = 1; // enable timer interrupt
GIE = 1; // enable global interrupts
TRISB = 0b00000000; // output changes on LED // Global interrupt enable
while(1)
{
if(count == 5)
{
count = 0;
RB1 ^= 1;
}
}
}
1. is there 10K pull up for all the port pins.
my 10K is okay. I change pull ups many times.. maybe I should try timer 1 and see the result2. Measure all the port pins or pull up and see if they all measure 10k or any pull up is damaged.
as of now I have only 1 PIC all others are 8051. I will try to get 1.3. change the controller and test it.
my breadbord has a Lm7805 inbuilt and the current rating of my power supply is 200ma transformer.(I dont know how much current is flowing to the controller.4. what is the voltage and current rating of the power supply used.
void interrupt timer_isr()
{
T0IF = 0;
PORTB ^= 1;
}
void interrupt timer_isr()
{
T0IF = 0;
count++;
if(count == 2)
{
count = 0;
PORTB ^= 1;
}
}
try changing the power supply to min 500mA. But thats not a problem i feel... its hardware problem for sure.... check the oscillator oscillation and its value in frequency...
int count = 0;
void interrupt timer_isr()
{
T0IF = 0;
count++;
}
void main()
{
TRISB = 0b00000000;
while(1)
{
if(count == 2)
{
count = 0;
RB1 ^= 1;
}
}
}
what is the initial value of count?
int count = 0;
instead of this
while(1)
{
if(count == 2)
{
count = 0;
RB1 ^= 1;
}
try this
while(1)
{
while(count <= 2)
{
count = 0;
RB1 ^= 1;
}
I figured out the problem now.. the interrupt is working well when I use PORTB to blink a LED .. why?
blinking of LED in PORTA is happening during simulation but in real hardware it's not.. why?
Note 1:
On RESET, the TRISA register is set to all
inputs. The digital inputs are disabled and
the comparator inputs are forced to
ground to reduce current consumption.
2:
TRISA<6:7> is overridden by oscillator
configuration. When PORTA<6:7> is
overridden, the data reads ‘0’ and the
TRISA<6:7> bits are ignored.
CMCON = 0x07;
TRISA = 0x00;
PORTA is an 8-bit wide latch. RA4 is a Schmitt Trigger
input and an open drain output. Port RA4 is multiplexed
with the T0CKI clock input. RA5 is a Schmitt Trigger
input only and has no output drivers. All other RA port
pins have Schmitt Trigger input levels and full CMOS
output drivers. All pins have data direction bits (TRIS
registers) which can configure these pins as input or
output.
When using PORTA, have you disabled the comparators, so that the PORTA pins can be used as outputs?
CMCON = 0x07;
TRISA = 0x00;
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?