Thanks again! I probably missed something, made some mistake. Now the pulsing starts without any accesses to the output pin.
Yes it does, but on the AVR boards analogWrite() is set-up for 8-bit phase correct PWM, where as we're using 16-bit fast PWM mode.
What is "AVR boards"? Phase correct PWM? I guess using analog.Write might not work as I guessed.
Here is the code working:
#include <Wire.h>
#include <hd44780.h>
#include <hd44780ioClass/hd44780_I2Cexp.h>
//#define BACKLIGHT_PIN 13
hd44780_I2Cexp mylcd; // declare lcd object: auto locate & config exapander chip
// LCD geometry
#define LCD_COLS 16
#define LCD_ROWS 2
long print_cnt = millis() + 500;
void setup()
// put your setup code here, to run once:
{
//1Hz 90% dutycycle
pinMode(9, OUTPUT); // Set digital pin 9 (D9) to an output
TCCR1A = _BV(COM1A1) | _BV(COM1A0) | _BV(WGM11); // Enable the PWM output OC1A on digital pins 9 and invert output
TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS12); // Set fast PWM and prescaler of 256 on timer 1
ICR1 = 62499; // Set the PWM frequency to 1Hz: 16MHz/(256 * 1Hz) - 1 = 62499
OCR1A = 6249; // Set the duty-cycle to 10%: 62499 / 10 = 6249
delay(10);//allow pwm timers to start
//// digitalWrite(9, HIGH);
// digitalWrite(9, LOW);
// analogWrite(9,25);
int status;
status = mylcd.begin(LCD_COLS, LCD_ROWS);
if (status) // non zero status means it was unsuccesful
{
status = -status; // convert negative status value to positive number
// begin() failed so blink error code using the onboard LED if possible
hd44780::fatalError(status); // does not return
}
mylcd.clear();
// initalization was successful, the backlight should be on now
// Print start message to the LCD
mylcd.print("Started");
Serial.begin(115200);
Serial.println("Measuring online");
pinMode(A2, INPUT);//+5 from object
pinMode(A3, INPUT);//Strobe from object
Serial.println("Waiting for neg flank");
while (analogRead(A3) > 512) {
// Serial.println(analogRead(A3));
}
Serial.println("Waiting for pos flank");
while (analogRead(A3) <= 512)
{
Serial.print(analogRead(A3));
}
Serial.println("Measuring setup and sync ready.");
}
void print_time()
{
int hour, minute, second;
unsigned long mill_tmp = millis();//+59L*60000L;
if (mill_tmp > print_cnt)
{
print_cnt += 1000;
mylcd.setCursor(0, 1);
hour = mill_tmp / 3600000;
if (hour < 10)mylcd.print(" ");
mylcd.print(hour);
mylcd.print(".");
minute = (mill_tmp / 60000) % 60;
if (minute < 10)mylcd.print("0");
mylcd.print(minute); //print hours
mylcd.print(".");
second = (mill_tmp / 1000) % 60;
if (second < 10)mylcd.print("0");
mylcd.print(second); //print hours
/*
mylcd.print((mill_tmp / 60000) % 60); //print minutes
mylcd.print(".");
mylcd.print((mill_tmp / 1000) % 60); //print seconds
*/
// Serial.print(mill_tmp / 3600 000); //print hours
// Serial.print(".");
// Serial.print((mill_tmp % 60 000) / 1000); //print minutes
// Serial.print(" ");
}
}
void loop()
// put your main code here, to run repeatedly:
{
float loaded, idle;
while (analogRead(A3) > 512) {} //wait for neg flank
loaded = analogRead(A2) * 5.0 / 1024.0;
// Serial.print( analogRead(A2));Serial.print(" ");
/* if (loaded < 3.0)
{
print_time();
// Serial.print(millis() / 60000); //print minutes
// Serial.print(" ");
}*/
mylcd.setCursor(0, 0);
mylcd.print(loaded); mylcd.print(" ");
Serial.print(loaded); Serial.print(" ");
while (analogRead(A3) <= 512) {} //wait for pos flank
idle = analogRead(A2) * 5.0 / 1024.0;
/* if (idle < 3.0)
{
print_time();
// Serial.print(millis() / 60000);
// Serial.print(" ");
}
*/
// Serial.println( analogRead(A2));
Serial.println(idle);
mylcd.print(idle); mylcd.print(" ");
print_time();
}