Friday, 15 February 2013

Arduino Due C Timer Coding (Interrupt Counting) -



Arduino Due C Timer Coding (Interrupt Counting) -

i have arduino due i'm doing lot of neat stuff in 1 section of code i'm handeling flowsensor , getting readings it. flowsensor hooked interrupt hallsensor device. problem i'm having math based off of single seconds worth of collection data, when turn on interrupt , sleep sec calculations flowrate in gp/m works great. purposes can't afford pause , collect data, instead calculate alter in time of greater one thousand milliseconds. take amount of time passed since lastly loop, devide 1000 milliseconds or 1 sec have percentage of 1 sec stored in variable, multiply count percentage , should arrive @ number of counts per second. results in ever growing number regardless of fact 0 numbers prior next loop. below i've included way formatted expressions , loop code flowsensor, i'd post whole code don't want waste space on stackoverflow , know portion of code works sleep method.

long currentmillis = 0; long lastmillis = 0; int checkmillis = 0; volatile int nbtopsfan; //measuring rising edges of signal int newnbtopsfan; float realnbtopsfan; float realmillis; float calc; float calcd; int calcf; int hallsensor = 7; void loop() { if (lastmillis = 0) { lastmillis = millis(); } currentmillis = millis(); checkmillis = (currentmillis - lastmillis); if (checkmillis >= 1000) { realmillis = (checkmillis / 1000); realnbtopsfan = (nbtopsfan * realmillis); newnbtopsfan = realnbtopsfan; calc = (newnbtopsfan * 60 / 7.5); //(pulse frequency x 60) / 7.5q, = flow rate calc = (calc / 60); calc = (calc / 3.78541); calc = (calc * 1.47); calcd = (calc * 100); calcf = calcd; nbtopsfan = 0; lastmillis = 0; checkmillis = 0; realmillis = 0; realnbtopsfan = 0; newnbtopsfan = 0; } }

your first line should read:

if ( lastmillis == 0 ) { lastmillis = millis(); }

you need double = evaluate variable

c timer count arduino sleep

No comments:

Post a Comment