industrialNETworXnetx

| 05.11.2008 | 10:47 | 4 replies

PWM

Hi,
i want to write a code for a PWM.
Config.netX.c:

  {"EATIMER",RX_PERIPHERAL_TYPE_TIMER,0},           // EinAus Timer
    1,                                              // use counter 1  
    1000000,                                        // 1000000µs = 1second
    FALSE,                                          // Continuous Mode, trigger again and again 
    FALSE,                                          // Interrupt disabled  
    FALSE,                                          // No external Clock  
    RX_HWTIMER_TRIGGER_NONE,                        // No Trigger   
    0,                                              // No I/O reference  
    0                                               // No Prescaler 
   },
............
  {{"GPIOOUT",RX_PERIPHERAL_TYPE_GPIO,0},
    14,                                                 // GPIO 14  
    RX_GPIO_TYPE_OUTPUT,                                // GPIO as Output 
    RX_GPIO_POLARITY_NORMAL,                            // high active
    RX_GPIO_OUTPUTMODE_PWM,                             // PWM Mode  
    RX_GPIO_COUNTER_1,                                  // Reference Counter is Counter1  
    FALSE,                                              // Disables IRQ  
    1000,                                               // Threshold: 1000µs = 1ms  
   }

resources.c:
//Indifizierung des EA_Timers
  if((eRslt = Drv_TimIdentifyTimer("EATIMER",0,&ptRscE->tRem.phTim))!=TLR_S_OK) 
  {
    goto leave;
  }

//Indifizierung des GPIO
if((eRslt = Drv_GpioIdentifyGpio("GPIOOUT",0,&ptRscE->tRem.phGpio))!=TLR_S_OK)
{
goto leave;
}

//Initialisierung des EA_Timers
if((eRslt = Drv_TimInitializeTimer(ptRscE->tRem.phTim))!=TLR_S_OK)
{
goto leave;
}


//Initialisierung des GPIOs
if((eRslt = Drv_GpioInitializeGpio(ptRscE->tRem.phGpio))!=TLR_S_OK)
{
goto leave;
}



Prozess.c:

        eRslt = Drv_TimStartTimer(ptRscE->tRem.phTim);
eRslt = rX_TimGetTime(ptRscE->tRem.phTim, &TimVal);
eRslt = rX_TimGetTime(ptRscE->tRem.phTim, &TimVal);
eRslt = rX_TimGetTime(ptRscE->tRem.phTim, &TimVal);
eRslt = rX_TimGetTime(ptRscE->tRem.phTim, &TimVal);
eRslt = rX_TimGetTime(ptRscE->tRem.phTim, &TimVal);


The problem is that TimVal has always the value 5391693, and it does not change.

So the Timer is not working properly ?!?!

regards

M T

M T

Hilscher Gesellschaft für Systemautomation mbH

| 07.11.2008 | 08:28

Abslimo wrote:

Prozess.c:
        eRslt = Drv_TimStartTimer(ptRscE->tRem.phTim);
        eRslt = rX_TimGetTime(ptRscE->tRem.phTim, &TimVal);
        eRslt = rX_TimGetTime(ptRscE->tRem.phTim, &TimVal);
        eRslt = rX_TimGetTime(ptRscE->tRem.phTim, &TimVal);
        eRslt = rX_TimGetTime(ptRscE->tRem.phTim, &TimVal);
        eRslt = rX_TimGetTime(ptRscE->tRem.phTim, &TimVal);

The problem is that TimVal has always the value 5391693, and it does not change.
So the Timer is not working properly ?!?!

Mixing up functions again? Why use rX_TimGetTime() on a HW Timer, that was setup with Drv_TimStartTimer?

When using HW Timers "Drv_Tim* is the way to go":

  Drv_TimStartTimer(hHWTimer);
  Drv_TimGetTime(hHWTimer, &ulCurValue);

When using SW Timers "rX_Tim*" is the right choice:

 rX_TimCreateTimer(&hSWTimer, TimerFunction, NULL, RX_TIM_AUTO_STOP, 0, 100);
 rX_TimGetTime(hSWTimer, &ulCurValue);

Regards

MT

| 11.11.2008 | 17:07

Hi, thanks for the Help.
i have now an other problem. i want to use a GPIO as a Switch. He should turn on or off after a certain time.
this is my code :

....
        if((EoA != EoA_1)&&(EoA == 1))
        {
        //********************Ein****************************************************
        eRslt = Drv_TimStopTimer(ptRscE->tRem.phTim1);
        eRslt = Drv_TimGetTime(ptRscE->tRem.phTim1, &TimVal);
        POKE(NETX_GPIO_THRSH_CAPT14,(Gpio14Max*100));
        //GPIO Standard: ptGpio14Cfg->mode = 1 --- GPIO low: ptGpio14Cfg->inv = 1
        Gpio14Mode = (PEEK(ptGpio14Cfg)&0xFFFFFFEF) | 0xC;
        POKE(ptGpio14Cfg, Gpio14Mode);
        //start Count1
        eRslt = Drv_TimStartTimer(ptRscE->tRem.phTim1); 
        //GPIO14 PWM
        ptGpio14Cfg->mode = 3;
        //***************************************************************************
        }
        else if((EoA != EoA_1)&& (EoA == 0))
        {
        //********************Aus****************************************************
        eRslt = Drv_TimStopTimer(ptRscE->tRem.phTim1);
        eRslt = Drv_TimGetTime(ptRscE->tRem.phTim1, &TimVal);
        POKE(NETX_GPIO_THRSH_CAPT14,(Gpio14Max*100));
        //GPIO Standard: ptGpio14Cfg->mode = 1 --- GPIO low: ptGpio14Cfg->inv = 0
        Gpio14Mode = (PEEK(ptGpio14Cfg)& 0xFFFFFFEB) | 0x8;
        POKE(ptGpio14Cfg, Gpio14Mode);
        //start Count1
        eRslt = Drv_TimStartTimer(ptRscE->tRem.phTim1); 
        //GPIO PWM
        ptGpio14Cfg->mode = 3;
        //***************************************************************************
        }


The problem is in the implementation of the 2 commands (mode = xx and Inv = xx). These commands are not executed simultaneously.
The delay is 100ns. The GPIO has during the delay an incorrect output value.

Regards

M T

M T

Hilscher Gesellschaft für Systemautomation mbH

| 13.11.2008 | 09:24

I am not able to understand your problem, or what you are trying to do.

But from the code I see, i have some remarks. Why you are trying to reconfigure the GPIO to output mode temporarily?

Wouldn't it be easier to keep it in PWM mode and just restart the timer? Another thing. Why don't you first set it to PWM mode and start the timer afterwards.

Informational:
-------------
The PWM module always sets the output to "high level" for the 0 <= time Threshhold (or timer stop). This can be inverted by setting bit 2 in the GPIO_CFG register. Maybe there is a misunderstanding here?

Regards

MT

| 13.11.2008 | 14:39

Hi,
i have to program a "programable limit switch". It works like a PWM.
If i should switch off (the switch is at the moment on, and after "Gpio14Max" µsec it should be off) then:

        eRslt = Drv_TimStopTimer(ptRscE->tRem.phTim1);
        POKE(NETX_GPIO_THRSH_CAPT14,(Gpio14Max*100));
        //GPIO Standard: ptGpio14Cfg->mode = 1 --- GPIO low: ptGpio14Cfg->inv = 0
        Gpio14Mode = (PEEK(ptGpio14Cfg)& 0xFFFFFFEB) | 0x8;
        POKE(ptGpio14Cfg, Gpio14Mode);
        //start Count1
        eRslt = Drv_TimStartTimer(ptRscE->tRem.phTim1);
        //GPIO PWM
        ptGpio14Cfg->mode = 3;

If i should switch on (the switch is at the moment off, and after "Gpio14Max" µsec it should be on) then:
        eRslt = Drv_TimStopTimer(ptRscE->tRem.phTim1);
        POKE(NETX_GPIO_THRSH_CAPT14,(Gpio14Max*100));
        //GPIO Standard: ptGpio14Cfg->mode = 1 --- GPIO low: ptGpio14Cfg->inv = 1
        Gpio14Mode = (PEEK(ptGpio14Cfg)&0xFFFFFFEF) | 0xC;
        POKE(ptGpio14Cfg, Gpio14Mode);
        //start Count1
        eRslt = Drv_TimStartTimer(ptRscE->tRem.phTim1);
        //GPIO14 PWM
        ptGpio14Cfg->mode = 3;

I try to reconfigure the GPIO to output temporarly, so that the switch(GPIO) will not change his condition before the timer reach his threshold. And this is the reason, why I start the timer firstly, then I keep the GPIO in PWM mode.
The problem is:
When I keep the GPIO in PWM mode (ptGpio14Cfg->mode = 3), he change his output value whether (1->0->1) or (0->1->0) before the timer reach his threshold.
I could give you an oscilloscope Image from the Output value if you want.

Login