c - using timer, Simpletimer or Timer_Three, Timer_Five as interrupt /Better solution? -


i'm trying sketch running, no luck yet.

i want set pin high every 100ms,which 5 full waves of 50hz ac power. , when turned on want start 2nd timer switch off after 0-100ms. can catch 1-10 half waves ssr incl. 0 crossing...

tried simpletimer did not work

#include <simpletimer.h>  simpletimer mot_on; simpletimer mot_off; int motorspeed=50; int timer_id;  void setup() {    serial.begin(115200);    pinmode(19, output);    mot_on.setinterval(1000, on);       // initialize timer1, , set 100ms= 5 full waves=10% of full cycle  //   mot_off.setinterval(10, off);    // initialize timer    timer_id=mot_off.setinterval(1000, off);    serial.println(timer_id); }  void on() {   if (motorspeed>90)   {      mot_off.enable(0);   }   digitalwrite(19, high);   // fire triac }  void off() {    digitalwrite(19, low);   // fire triac    mot_off.disable(0);  // } 

unfortunately disable not take affect! not disables enything...just running mad :-)

void loop() {    int off_time=motorspeed/100;    mot_off.setinterval(100*off_time, off);  } 

i tried timer3 , timer 5... no luck either: skript not stop timer!!!

#include <timerthree.h> #include <timerfive.h>  int motorspeed=50; int timer_id;  void setup() {    serial.begin(115200);    pinmode(19, output);    timer3.attachinterrupt(on);   timer3.initialize(100000);    timer5.attachinterrupt(off);   timer5.initialize(10000); }  void on() {   if (motorspeed>90)    {timer5.start();}//    serial.println("on");    digitalwrite(19, high);   // fire triac } void off() {    digitalwrite(19, low);   // fire triac    serial.println("off");    timer5.stop();  // }      void loop() {   int off_time=motorspeed/100;   timer5.setperiod(100*off_time); } 

here go, answer !!!! ssr 0 crossing function possible change speed in 10 steps (you can change in script 100000 :-) steps)

with simpletimer:

#include <simpletimer.h>  simpletimer mot_off;  volatile int i;               // variable use counter of dimming steps. volatile since passed between interrupts int ac_pin = 19;                 // output opto triac  int mot_speed = 50;                  // in % speed level (0-100)  0 = off, 100 = full speed                                 //1 second = 1.000 int freqstep = 20;              // means 20ms 1 full wave. every 20ms check if should switch ssr off right speed                                 //if speed 50 (50%) set pin high every 200ms, after 5x calling timer (i=50)time = 100ms set pin low next 5x calling of timer)                                 //if speed 10 (10%) set pin high every 200ms, after 1x calling timer (i=10)time = 20ms set pin low next 9x calling of timer)  void setup() {    serial.begin(115200);    pinmode(ac_pin, output);       mot_off.setinterval(freqstep, off_check); }  void off_check() {      if(i>mot_speed)      {                            digitalwrite(ac_pin, low);  // turn off ssr  //      serial.println("off"); //      serial.println(i);                      }      else      {       digitalwrite(ac_pin, high); //      serial.println("on"); //      serial.println(i);                }      i+=10;       if (i>100) {i=0;}                                  }  void loop() {   mot_off.run(); } 

and timerone:

#include <timerone.h>           // avaiable http://www.arduino.cc/playground/code/timer1  volatile int i;               // variable use counter of dimming steps. volatile since passed between interrupts int ac_pin = 19;              // output opto triac  int mot_speed = 50;           // in % speed level (0-100)  0 = off, 100 = full speed                                    //1 second = 1.000.000 int freqstep = 20000;             // means 20ms 1 full wave. every 20ms check if should switch ssr off right speed                                   //if speed 50 (50%) set pin high every 200ms, after 5x calling timer (i=50)time = 100ms set pin low next 5x calling of timer)                                   //if speed 10 (10%) set pin high every 200ms, after 1x calling timer (i=10)time = 20ms set pin low next 9x calling of timer)    void setup() {  // begin setup   serial.begin(115200);      pinmode(ac_pin, output);                          // set triac pin output   timer1.initialize(freqstep);                      // initialize timerone library freq need   timer1.attachinterrupt(off_check, freqstep);      //    // use timerone library attach interrupt }  void off_check() {      if(i>mot_speed)      {                            digitalwrite(ac_pin, low);  // turn off ssr  //      serial.println("off"); //      serial.println(i);                      }      else      {       digitalwrite(ac_pin, high); //      serial.println("on"); //      serial.println(i);                }      i+=5;       if (i>100) {i=0;}  }  void loop()  {    } 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -