Erik
I am getting to old to be a purist any more. I always use the platform
or chip with the best or most intuitive dev environment.
Short piece of code using a Teensy 3.0. I use the Visual Micro debugger
in Microsoft Visual Studio 2015 all running on the latest Arduino
environment.
const
int ledPin = 11;
#define
MainPeriod 100 // measurement frame duration, milliseconds
#define
pulseInput 2 // input pin for pulseIn
#define
pulseOutput 4
long
previousMillis = 0;
unsigned
long duration = 0; // receive pulse width
unsigned
long outDuration = 0;
long
pulsecount = 0;
void
setup()
{
pinMode(
pulseInput, INPUT);
Serial.begin(19200);
pinMode(ledPin,
OUTPUT);
analogWriteFrequency(4, 40000);
//set the pwm frequency
analogWriteResolution(12);
// use the highest resolution
}
void
loop()
{
unsignedlong currentMillis = millis();
if (currentMillis - previousMillis >= MainPeriod)
{
previousMillis = currentMillis;
outDuration = (duration / 23.95);
analogWrite(
pulseOutput, outDuration);
// write current time and F values to the serial port
// not implimented for production but handy to see the frequencies
//Serial.print(currentMillis);
//Serial.print(" "); // separator!
//float Freq = 0.5e6 / float(duration); // assume pulse duty cycle 0.5
//Freq *= pulsecount;
//Serial.print(Freq);
//Serial.print(" ");
//Serial.print(pulsecount);
//Serial.print(" ");
//Serial.print(duration);
//Serial.print(" ");
//Serial.println(outDuration);
duration = 0;
pulsecount = 0;
}
// instead of single measurement per cycle - accumulate and average
duration += pulseIn(
pulseInput, HIGH, MainPeriod * 900);
pulsecount++;
}
>On 25.08.15 13:19, Marius Liebenberg wrote:
>> Thanks all for the help. I used a Teensy 3.0 bord from the drawer and
>> it works great. I am reading a 2khz signal from the parport and
>> converting it to a 40khz signal. Duty cycle is from 0% to 99%.
>
>That was quick! Using the arduino environment, or just the gnu
>toolchain? (It'd take me a good bit longer than you did, to write the
>ISR, and figure the mode bitpatterns for the timers, from the
>datasheet.)
>
>Erik
>
>--
>"Ben and Paddy (police officers from Ramingining, about 20 kilometres
>away) came
>over and took it away from me." - Damien Lumsden referring to an
>unexploded WW2
>bomb he'd been carting around in the backof his ute.
>http://www.abc.net.au/news/2015-08-25/wwii-bomb-loaded-on-ute-for-nt-show-and-tell-before-detonation/6723614
>
>------------------------------------------------------------------------------
>_______________________________________________
>Emc-users mailing list
>[email protected]
>https://lists.sourceforge.net/lists/listinfo/emc-users
------------------------------------------------------------------------------
_______________________________________________
Emc-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/emc-users