Hello,
Im trying to make a couter with a 16F628A to count the rising edge pulses in portb, and show the count in a LDC.
Im trying to make a kind of data logger to capture two lines of data and clock.
So my first problem is how to detect the rising edge and then be able to count them.
Thanks in advance.
Rising edge counter
There are 2 methods to catch an edge, the RB0/INT pin, and the CCP module coupled with Timer1. Both of these PIC functions have options to catch either the rising or falling edge of a signal. You can find both referenced in the datasheet.
[color=darkred][b]xor[/b][/color]
[url=http://circuit-ed.com]CircuitED -[/url]
[url=http://circuit-ed.com]CircuitED -[/url]
I took your advice xor, and looked for some info about RB0/INT.
It is the basic program Im doing with pic 16F628 A and EP3 , but.. I think when I enable interrupts the LCD gets a bit crazy.
I use RB0 to capture the pulses. Also I dont know how to disable the interrupts after the capture is done.
So, Im thinking of use other pic and other port to connect the display using the custom LCD library... at the moment I can't find other solution....
Thanks for your help
It is the basic program Im doing with pic 16F628 A and EP3 , but.. I think when I enable interrupts the LCD gets a bit crazy.
I use RB0 to capture the pulses. Also I dont know how to disable the interrupts after the capture is done.
Code: Select all
program Test
sub procedure Interrupt
' other lines
clearbit(INTCON,INTF)
end sub
main:
OPTION_REG=0
INTCON=%11010000
portb=0
trisb=%00000011 'all output, except RB0/INT and RB1 as inputs
while true
' the program
' showing LCD 4bit mode in port B
wend
end.
Thanks for your help
-
- Posts: 231
- Joined: 14 Nov 2004 19:43
If you wish to disable the interrupt you can simply not reset the INTF interrupt flag, or clear INTE interrupt enable, or clear GIE global interrupt enable. Any one or more of these will disable it.
Example of setting up RB0 Edge Interrupt:
Example of setting up RB0 Edge Interrupt:
Code: Select all
dim counter as longint
sub procedure interrupt
If INTCON.INTF = 1 Then ' check type of interrupt
inc(counter) ' increment pulse counter
End If
INTCON.INTF = 0 ' clear interrupt flag to catch next pulse
end sub
sub procedure INT_Setup
counter = 0 ' clear pulse counter
OPTION_REG = 0
INTCON = 0
OPTION_REG.RBPU = 0 ' PortB pullups active
OPTION_REG.INTEDG = 1 ' interrupt on RB0 rising edge
INTCON.INTE = 1 ' enable RB0 interrupt
INTCON.INTF = 0 ' clear interrupt flag ... enables jump to ISR
INTCON.GIE = 1 ' enable global interrupts
end sub
main:
PORTB = 0
TRISB = 1 ' RB0 as input
INT_Setup ' setup registers
While true
' any running code
Wend
end.
[color=darkred][b]xor[/b][/color]
[url=http://circuit-ed.com]CircuitED -[/url]
[url=http://circuit-ed.com]CircuitED -[/url]
-
- Posts: 2
- Joined: 11 Mar 2016 14:26
Re: Rising edge counter
you can make positive edge by this code
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections
char x1[7];
char x;
void main() {
trisd=255;
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR);
lcd_cmd(_lcd_cursor_off);
lcd_out(1,1,"my counter");
while(1)
{
if(PORTD.B1==1)
{ x+=1;
inttostr(x,x1) ;
// LCD_CMD( _LCD_MOVE_CURSOR_RIGHT);
ltrim(x1);
lcd_out(2,1,x1);
while(1){
if(portd.b1==0) break;
}
}
}
//Lcd_Cmd(_LCD_CURSOR_OFF);
//Lcd_Cmd(_LCD_TURN_OFF); // Clear display
//Lcd_Cmd(_LCD_UNDERLINE_ON); // Cursor off
//Lcd_Out(1,1,"h"); // Write text in first row
Delay_ms(2000);
//Lcd_Cmd(_LCD_CLEAR); // Clear display
}
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections
char x1[7];
char x;
void main() {
trisd=255;
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR);
lcd_cmd(_lcd_cursor_off);
lcd_out(1,1,"my counter");
while(1)
{
if(PORTD.B1==1)
{ x+=1;
inttostr(x,x1) ;
// LCD_CMD( _LCD_MOVE_CURSOR_RIGHT);
ltrim(x1);
lcd_out(2,1,x1);
while(1){
if(portd.b1==0) break;
}
}
}
//Lcd_Cmd(_LCD_CURSOR_OFF);
//Lcd_Cmd(_LCD_TURN_OFF); // Clear display
//Lcd_Cmd(_LCD_UNDERLINE_ON); // Cursor off
//Lcd_Out(1,1,"h"); // Write text in first row
Delay_ms(2000);
//Lcd_Cmd(_LCD_CLEAR); // Clear display
}