Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

CCS Count Input time in Low and High State of PIN state

Status
Not open for further replies.

nagkiller

Full Member level 4
Joined
Jul 9, 2009
Messages
238
Helped
37
Reputation
74
Reaction score
37
Trophy points
1,308
Location
Brazil
Activity points
2,703
CCS Count Input time in Low and High State of PIN

How to count time up and time down, write value to eeprom and show in terminal using CCS Compiler???

This is the code in U1... TX
Code:
#include <12F629.h>
#FUSES NOWDT
#FUSES INTRC_IO
#FUSES NOMCLR
#FUSES NOBROWNOUT
#use delay(int=4000000)
void main()
{
   while(TRUE)
   {
      output_a(0xFF);
      delay_ms(10);
      output_a(0x00);
      delay_ms(25);
   }
}



I wanna to count 30 times in low and high in U2 (RX).

Code:
#include <12F629.h>
#FUSES NOWDT
#FUSES INTRC_IO
#FUSES NOMCLR
#FUSES NOBROWNOUT
#use delay(int=4000000)
#use rs232(baud=1200,parity=N,xmit=PIN_A1,rcv=PIN_A2,bits=8)

int tempo =0;
int conta =0;
int endereco =1;

void main()
{
   while(TRUE)
   {
   do
   {
      printf("\r\n\****************");
      printf("\r\n\ ");
      printf("\r\n\Conta = %u" conta);
      do
         {
            tempo++;
         } while (!input(PIN_A4));
      printf("\r\nTempo Low = %u" tempo);
      write_eeprom( endereco, tempo );
      tempo=0;
      endereco++;
      do
         {
            tempo++;
         } while (input(PIN_A4));
      printf("\r\nTempo High = %u" tempo);
      write_eeprom( endereco, tempo );
      tempo=0;   
      endereco++;
      conta++;
      printf("\r\n\ ");
   } while (conta <= 29);   
   printf("\r\n\****************");
   printf("\r\n\ ");
   printf("\r\nEND COUNT!!!");
   printf("\r\n\ ");
   printf("\r\n\****************");
   break;
   }
}

Any help please???
 
Last edited:

You didn't report particular problems with your code, in which regard do you expect help?

Technically, the tempo++ loops are counting time with a unit of some machine cycles, this should work for maximum 25 ms pulse width.

It's a bad idea however to write the data directly to EEPROM, this causes huge delays. It might work if you resync on the input at the begin of each low and high measuring interval, otherwise write the data to internal RAM first.
 

It turns out that changing the level of the pin, the count is not accurate ...
Even commenting lines for eeprom and serial communication.
The intervals of pulses that are accurate microsecond!
What I want to do really is to receive and decode the code HT6P20B Holtek.
 

To decode the Holtek code, you need to distinguish 33 from 67% duty cycle, but not measure exact pulse widths.
 

Just must be able to distinguish th > tl from th < tl.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top