Page 1 of 1

Pulse counter

PostPosted: Thu Apr 17, 2014 10:44 am
by maheshkumar0487
My external pulse is input to Psoc 1. How can i set 15 sec such that the counter counts upto 15 sec only?? DO i need to use both timer and counter or any one of them enough. My external pulse frequency vary from 1 Hz to 3 Hz.

Re: Pulse counter

PostPosted: Thu Apr 17, 2014 11:59 am
by bobmarlowe
Looks like your design is not very time-critical. I would suggest to poll for your input-signal and start an 8-bit timer, period 240, input frequency 16Hz. To get the 16 Hz you probably need a pre-devider.

Bob

Re: Pulse counter

PostPosted: Thu Apr 17, 2014 4:47 pm
by danadak
If you want to count the number of 1 - 3 Hz pulses in a 15 sec period, you need a gate that
is 15 sec wide. The sleep timer can generate 1 Hz, comes for "free", part of the HW resources,
can generate an interrupt. So count that out in ISR and when it reaches 15 stop the ISR and 8 bit
pulse counter, read and reset pulse counter, then reset ISR gate count value, and restart the
ISR.

Or run the sleep counter at Nyquist for the input pulses, 1/6 Hz or faster, use that to do the
pulse counting by pin polling, and for gate period generation (ISR counts to 90), and save a counter.
Only HW needed is sleep timer.

Regards, Dana.

Re: Pulse counter

PostPosted: Sat Apr 19, 2014 11:28 am
by maheshkumar0487
Thank you sir,, I got it by using PWM and Timer.. Now i got the count value on LCD. I have to send it as sms using GSM modem. I have gone through whole GSM in the datasheet. I can send some defined data through GSM but how can i send the data which is been counted. Is there any command strcpy(value,value1) which used in 8051??

Thanks for replying to me sir!!!!

Re: Pulse counter

PostPosted: Sat Apr 19, 2014 12:08 pm
by bobmarlowe
You may use any C-function in the #included libraries
math, stdlib, strings and so on. Have a look into the C-manuals accessable from Help->Documentation->Compiler and Programming Documents


Bob

Re: Pulse counter

PostPosted: Sun Apr 20, 2014 7:41 am
by danadak
Most common is to convert numeric to character string and send serially,
UART, I2C, USB, SPI, whatever as a character string.

f()'s such as itoa(), ltoa(), sprintf()....

Regards, Dana.

Re: Pulse counter

PostPosted: Tue Apr 22, 2014 4:11 am
by maheshkumar0487
Sir i want to send variable value which will vary for every 30 seconds.. I can send some massages which are fixed..

Re: Pulse counter

PostPosted: Tue Apr 22, 2014 2:37 pm
by danadak
So you first convert to string using f()'s such as itoa(), ltoa(), sprintf()....

Then transmit over UART.

Then on receive side write a simple routine to convert string back to numeric. You cant use the library
functions like atoi(), atol(), because they are defined for converting strings in program memory, not RAM.


Regards, Dana.

Re: Pulse counter

PostPosted: Thu May 08, 2014 12:41 pm
by maheshkumar0487
This is my code which counts and display the count value on LCD. The count value to be sent as message using GSM modem. Getting 2 errors and many warnings, I am hoping that all i have given correct statements..

#include <m8c.h> // part specific constants and macros
#include "PSoCAPI.h" // PSoC API definitions for all User Modules
#include "delay.h"
void delay(void);
void delay2(void);
void lcd_print_int (int value );
char theStr1[] = "Your heart rate";
char theStr2[] = "bpm";

void main(void)
{
int count,time;
int i,j;
char str_1[] = "Heart beat ";
char str_2[] = "Monitor";
char str_3[] = "Press switch";
char str_4[] = "Keep your finger";
char str_5[] = "in sensor";
char str_6[] = "Counting.....";
UART_1_Start(UART_1_PARITY_NONE); // GSM_UART
LCD_1_Start();
LCD_1_Position(0,2);
LCD_1_PrString(str_1); //Heart beat
LCD_1_Position(1,4);
LCD_1_PrString(str_2); //Monitor
Delay10msTimes(250);
PRT0DR = 0x00;
Delay10msTimes(250);
LCD_1_Start();
LCD_1_Position(0,1);
LCD_1_PrString(str_3); // Press switch
// Delay10msTimes(250);
while(1)
{

if(PRT1DR == 0x01)
{
LCD_1_Start();
LCD_1_Position(0,0);
LCD_1_PrString(str_4); // Keep your finger
LCD_1_Position(1,4);
LCD_1_PrString(str_5);
// GSM_code_start
delay2();
UART_1_CPutString("a");
delay2();
UART_1_CPutString("t");
delay();
UART_1_PutChar(13);
delay2();
UART_1_CPutString("a");
delay2();
UART_1_CPutString("t");
delay2();
UART_1_CPutString("+");
delay2();
UART_1_CPutString("c");
delay2();
UART_1_CPutString("m");
delay2();
UART_1_CPutString("g");
delay2();
UART_1_CPutString("f");
delay2();
UART_1_CPutString("=");
delay2();
UART_1_CPutString("1");
delay2();
UART_1_PutChar(13);
delay2();
UART_1_CPutString("a");
delay2();
UART_1_CPutString("t");
delay2();
UART_1_CPutString("+");
delay2();
UART_1_CPutString("c");
delay2();
UART_1_CPutString("m");
delay2();
UART_1_CPutString("g");
delay2();
UART_1_CPutString("s");
delay2();
UART_1_CPutString("=");
delay2();
UART_1_PutChar(34);
delay2();
UART_1_CPutString("8");
delay2();
UART_1_CPutString("1");
delay2();
UART_1_CPutString("3");
delay2();
UART_1_CPutString("7");
delay2();
UART_1_CPutString("9");
delay2();
UART_1_CPutString("0");
delay2();
UART_1_CPutString("5");
delay2();
UART_1_CPutString("9");
delay2();
UART_1_CPutString("5");
delay2();
UART_1_CPutString("9");
delay2();
UART_1_PutChar(34);
delay2();
UART_1_PutChar(13);
delay2();
UART_1_CPutString("Heart rate is normal");
delay2();
UART_1_PutChar(26);

// GSM_CODE_END



PRT0DR=0X00;
Delay10msTimes(250);Delay10msTimes(250);
PRT0DR=0X01;
LCD_1_Start();
LCD_1_Position(0,2);
LCD_1_PrString(str_6);
//Counter8_Start();
Timer8_Start();
Delay10msTimes(250);Delay10msTimes(250);
Delay10msTimes(250);Delay10msTimes(250);
Delay10msTimes(250);Delay10msTimes(250);

Timer8_Stop();
//Counter8_bReadCounter();
Timer8_bReadTimer();

if (Timer8_bReadTimer()>245)
{
count=0;
lcd_print_int (count );
Delay10msTimes(250);Delay10msTimes(250);
Delay10msTimes(250);Delay10msTimes(250);
Delay10msTimes(250);Delay10msTimes(250);
LCD_1_Start();
}
else
count=(2*(250-Timer8_bReadTimer()))+20;
{
LCD_1_Start();
lcd_print_int (count );
Delay10msTimes(250);Delay10msTimes(250);
Delay10msTimes(250);Delay10msTimes(250);
Delay10msTimes(250);Delay10msTimes(250);
LCD_1_Start();
}
}

}


}

void lcd_print_int (int value )
{
char str[10]=" ";
LCD_1_Position(0,0); //
LCD_1_PrString(theStr1);
itoa (str,value,10);
LCD_1_Position(1,3);
LCD_1_PrString(str);
LCD_1_Position(1,8); //
LCD_1_PrString(theStr2);


}

void delay2(void)
{
int i;
for(i=0;i<=10000;i++);
}


check my code and help me out to get proper output...

Re: Pulse counter

PostPosted: Thu May 08, 2014 1:42 pm
by danadak
Post your project -


“File”
“Archive Project”
Use Firefox or IE, not chrome to post.


Regards, Dana.

Re: Pulse counter

PostPosted: Thu May 08, 2014 10:32 pm
by bobmarlowe
You did not enable interrupts which may be needed for PutString()

@Dana
The software here is up-to-date and can afaik work with chrome, vanadium and Molybdenum :mrgreen:

Bob

Re: Pulse counter

PostPosted: Fri May 09, 2014 1:47 am
by maheshkumar0487
Yup got it sir,

How to set UART baudrate 9600b/s. clock=(8*9600)=76.8KHz to get this clock sysclk(24MHz)/312.5. How can i set baudrate in chip diagram?? Can i do it in software??

Re: Pulse counter

PostPosted: Fri May 09, 2014 2:20 am
by danadak
Take a look at this -

http://www.cypress.com/?rID=39848 PSOC 1 Baudrate

Regards, Dana.

Re: Pulse counter

PostPosted: Sat May 10, 2014 7:28 am
by maheshkumar0487
Attached file contains my gsm checking project.. Just i want to transmit data "lab is opened" using uart after pressing switch. Initially switch off.. baudrate arranged correctly...
check my project and if any errors pls tell me..

Re: Pulse counter

PostPosted: Sat May 10, 2014 9:54 am
by danadak
In chip view, upper left hand corner, Global Resources, you have CPU_clock set
to SysClk/8, should be SysClk/1

Regards, Dana.

Re: Pulse counter

PostPosted: Sun May 11, 2014 2:08 am
by maheshkumar0487
Thank you sir, Finally got the GSM_CHECK output..

Now i have to send message which contains variable value....
How can i chage variable value to ascii and send as message....

Re: Pulse counter

PostPosted: Sun May 11, 2014 3:05 am
by danadak
Via use of extended library of Compiler, itoa(0, ltoa(), ftoa(), sprintf(),
all convert numerics into a string. You declare a string buffer, pass
it as a pointer to these functions, and they will do conversion and
fill the buffer with a NULL terminated string. Then you use UART
APIs to send. Remember to use following in file where f()'s are used

Code: Select all
#include <stdlib.h>
#include <string.h>


When you declare the char array make it 1 bigger than longest string you
will handle, to make room for NULL character, which terminates string.

Regards, Dana.