How to detach Ticker

19 Apr 2012

I just recently pick up mbed and learn the programing lanague involve for my school final year project .

now the problem is that , I cant seem to use the detach the function Fert, a function to be called by ticker at 2 min interval . Itried using the sample for the detach given in the ticker library and it dosent seem to work .

void Fert() { //Fertilizer function to be called
    if (Error==0) {
        Elapse=Elapse+2;
        if (Elapse>Min1) {
            Clock.start();
            RClock=Clock.read();
            while ((Min2>RClock)&&(Error==0)) {
                FPump=1;
                FValve=1;
                wait(5);
                if (FCheck()>1) {
                    Error=1;
                    BLF.attach(FL,4);
                    Clock.stop();
                }
            }
            PULSE2=1;
            wait(5);
            if (US2>0) { //input variable
                FTank=1;
            } else {
                FTank=0;
            }
            PULSE2=0;
            Clock=0;
            Clock.stop();
            FPump=0;
            FValve=0;
            //insert code to retrive FHz & FDur from wifly
            Min1=FHz*60; //Convesion of fertilizer timing to hour
            Min2=FDur*60;//conversion of duration of fertilizing to minutes.
            Elapse=0; // Reset Elapse
        }
        }
        if (Error==1) {
        ErrorL=1;
        void.detach(); //compiler error on this line
        }
    }

Thank for helping ~ and sorry about the messy code

19 Apr 2012

Is void really the name of your Ticker object? I think that is a reserved word. You should use the same object name as was used for the attach.

I tried this code and it turned on the LED after 1 second but didn't continue to blink every second so the detach succeeded.

#include <mbed.h>

Ticker      fertilizerTicker;
DigitalOut  led1(LED1);

void Fert()
{
    fertilizerTicker.detach();
    led1 = !led1;
}

int main()
{
    led1 = 0;
    fertilizerTicker.attach(Fert, 1.0f);
}
19 Apr 2012

Oh , so it should be detach the ticker and not the function ~ i see thanks~

as for the void part , i wrote that after i tried Fert.detach(); and it dint work hence i try copy pasting what the mbed library guide wrote on detach which is void detach();

though i got another question what do they mean by void ?

20 Apr 2012

To control the speed of an small single phase AC ventilator I try to shift Pwm pulses with respect to mains in order to fire a Triac at various phase angles. My approach is the following Sample mains using Ticker every 200_us together with time from a Timer (200 samples 40msec or two mains periods) From samples determine time when mains cross zero (0 phase angle ). Calculate a delay DT wait (DT) and program Pwmout immediately afterwards The results are not consistent Any suggestions how to control an ac motor Thank you Markos

21 Apr 2012

Markos, it's a long time since I did this but from memory most AC motors tend to work synchronously with the mains supply frequency. They can however loose sync and resync for example when starting and also if the load is too great. So sometimes you can slow the motor down by a method that induces 'slip' by reducing the power supplied as you are doing, but it is easy for the motor to stall, not start or vary in speed with the load fluctuations. Some AC motors with a stator coil can be speed controlled by varying the current through this winding.

Have you tried your circuit with a lamp of similar current rating as your motor? If your software/hadware is not working this will show up with the lamp brightness fluctuating, but if OK then your motor is not sutable for this method of control and really requires a variable frequency drive.

If you want to post more details of the motor type and describe how the results are not consistant, this may help further discussion.

08 May 2012

Kevin, I try to control a small ventilator less than 1kw of a wood pellet burner. The speed control of this fan by the existing controller is in 10 steps. The speed variation is by lowering voltage to increase slip. Hope to test soon software and hardware interface with a lamp first and the ventilator after. Keep you informed on the outcome. Thank you for your interest. Markos