![]() ![]() ![]() So what's the point of an interrupt if you don't want it to interrupt anything? Why not just read the pin once on every pass of the loop if that's what you're going to do. You're disabling interrupts for the entire loop. I don't see how rpmcount can ever be greater than 1 in that code. This interrupt is run each time the processor senses a falling slope in the tach inputÄetachInterrupt(0) //im not sure if this is necessary here analogWrite(11, int(rpm)) //THIS GUY IS THE BUGGER - when //out, the code works fine, else NOT! Serial.print(timeold) //time at end of interval - hence timeold=millis() Rpm = (rpmcount)*0.82 // 0.82 is a correction factor to get to the analog voltage I need for the gauge If (d_t >= 150) // fixed read interval of 150ms Don't process interrupts during main loop Triggers on FALLING (change from HIGH to LOW) Interrupt 0 is digital pin 2, so that is where the Input is connected Unsigned long timeold = 0 // used to calculate d_t= millis()-timeold Volatile int rpmcount =0 // volitile because the variable is manipulated during the interrupt I'm an Arduino noob - sure hope someone can help me learn something here! (I should note for anyone looking at the code that the 'rpm' variable isn't really actual RPM, it's supposed to represent the pwm value that is required to drive the analog gauge needle to the correct position). This makes no sense to me, but it's the best I can figure now. Specifically, I get about 10x as many 'rpmcount's - meaning (I think) that the code is getting Interrupted way more often when the AnalogWrite is there. It's very repeatable: //out the Analog write, and everything works correctly put it back in, and the data goes haywire. ![]() But when I implement the write, it seems to impact the function of the original code. So, I've added an analogWrite statement to the code. But, I want to output a PWM voltage to the movement of an analog gauge. The code reads a 0-5V square wave output from the engine CPU, and writes the result via a serial print. I've borrowed some code to help me write a frequency counter. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |