Capture frequency

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 6.

Moderator: Benj

Post Reply
407charles
Posts: 122
Joined: Thu Jun 26, 2014 12:01 pm
Has thanked: 41 times
Been thanked: 19 times
Contact:

Capture frequency

Post by 407charles »

Hi my friend how are you? I hope your are doing well. I got a problem trying to make a program to capture frequency. I'm using the atmel 328p but I'm not sure if I set the registers correctly. Can you take a look at it? You may be able to guide me in the right direction. Thanks a lot for your help. Right know I'm using a comparator to eliminate transmission noise. The program is not working it just gave me an 8 count after start up but it does not count the signal in the ICP1 pin. I appreciate all your help.
Attachments
AVR capture frequency.fcfx
Here is my program
(7.41 KiB) Downloaded 266 times

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times
Contact:

Re: Capture frequency

Post by kersing »

I have moved your question to the English forum and created a new topic for it. Posting unrelated questions in an existing topic (hijacking a topic) is not done, please keep topics on subject in especially when writing English in the non English language forums.
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Capture frequency

Post by Benj »

Hello,

I noticed this.

Code: Select all

//while (TIFR1.5 == 0);
while (TIFR1 & 0x10 == 0);
bit 5 equates to hex 0x20 so I think your code should be like this.

Code: Select all

//while (TIFR1.5 == 0);
while (TIFR1 & 0x20 == 0);
Same goes for this.

Code: Select all

//TIFR1.5 = 0;
TIFR1 &= 0xEF;
Probably should be like this.

Code: Select all

//TIFR1.5 = 0;
TIFR1 &= 0xDF;

407charles
Posts: 122
Joined: Thu Jun 26, 2014 12:01 pm
Has thanked: 41 times
Been thanked: 19 times
Contact:

Re: Capture frequency

Post by 407charles »

Thanks a lot for your quick response. I did the changes you suggest to the program. It does display values without input. I had the comparator switch off and I got values without any input but when I switch the comparator on (ACSR bit 7 = 0) it does not work. Looks like the code is more complex than I thought. I got no idea if all the registers needed for this task are set correctly. First, I got the comparator register ACRS bit 6 enable (logic 1) to get a reference voltage to the positive pin ( according with datasheet) but I switched to 0 and still not capturing data. I will appreciate all the help. Thanks a lot.
Attachments
AVR capture frequency.fcfx
frequency capture.
(7.41 KiB) Downloaded 301 times

User avatar
cubitus54
Flowcode v5 User
Posts: 110
Joined: Wed Jun 19, 2013 7:18 am
Has thanked: 7 times
Been thanked: 32 times
Contact:

Re: Capture frequency

Post by cubitus54 »

Hello,

I'm not sure, but there is no external counter input for the 328.

This entry exists on the Mega 2560 on the timer 5 (see p161 TCCR5B : CSn2, CSn1, CSn0 => 111 = External clock source on Tn pin. Clock on rising edge)
Flowcode V6.1.2.0(11 05 2015)

407charles
Posts: 122
Joined: Thu Jun 26, 2014 12:01 pm
Has thanked: 41 times
Been thanked: 19 times
Contact:

Re: Capture frequency

Post by 407charles »

Hello my friend, I checked the Arduino website and I found the datasheet for atmega 328p which is the processor of the arduino 1 and nano. Datasheet Chapter 16 is about the 16 bit timer/counter 1 and it can be configured into capture mode at pin 12 which is the ICP1 pin. I believe that I just missing something. The way the program is displays a value without any input. I missing something or I got a register set up wrong. I still reading some more trying to find the mistake. Thanks a lot for your interest. I'm trying to develop this program because in the industrial environment there are two dynamic measurements for machine control: temperature and speed. By being able to capture frequency I can converted to time and then find the speed using a tachometer, encoder or a photo switch. Thanks a lot for your time and concern.

Post Reply