function for servo type PULSEOUT

Help
2011-08-09
2013-03-12
  • alejandro1957
    alejandro1957
    2011-08-09

    I would like to create a void title like this:

    void Delay_us(unsigned int Tiempo_us)
         {
         unsigned int Delta;
         for(Delta=0;Delta<((Tiempo_us-1)/3);Delta++)
            {
             _asm
              nop
             _endasm;
            }
         }

    void Delay_ms(unsigned int Tiempo_ms)
         {
         unsigned int Delta;
         for(Delta=0;Delta<Tiempo_ms;Delta++)
            {
             Delay_us(1000);
            }
         }

    void Pulseout(unsigned int Puerta,unsigned int Valor)
         {
          Puerta==1;
          Delay_us(Valor);
          Puerta==0;
         }

    void Impulso(void)
         {
          Pulseout(0,1000);
          Delay_ms(20);
         }

     
  • alejandro1957
    alejandro1957
    2011-08-09

    sorry for my english  :-(

     
  • Maarten Brock
    Maarten Brock
    2011-08-09

    If you would like to do that than why don't you?
    Is there a question missing or were you just informing the rest of the world of your wishes?

    Btw I would suggest to either use a timer inside the innermost function or write it completely in assembler. Any change of the compiler or your settings could change the timing behaviour of your function.

     
  • alejandro1957
    alejandro1957
    2011-08-09

    program because the pic with gcbasic, wanted to learn to do it with SDCC.
    I still have half a mind.

    if I had already done so, I would have already made ​​it known

    sorry for my english :-(

     
  • Raphael Neider
    Raphael Neider
    2011-08-09

    I guess that the following will not work as intended:

    void Pulseout(unsigned int Puerta,unsigned int Valor)
         {
          Puerta==1; /* ?!? What is intended here? */
          Delay_us(Valor);
          Puerta==0; /* ?!? What is intended here? */
         }
    

    Puerta==1; and Puerta==0; are comparison expressions - not assignments.
    Should you want to set a bit in an SFR (e.g., PORTA) for Valor microseconds, you might try something like

    void Pulseout(unsigned int mask,unsigned int Valor)
         {
          /* You might want to use LATA instead of PORTA here ... */
          PORTA |= mask; /* Set all bits in PORTA that are set in mask. */
          Delay_us(Valor);
          PORTA &= ~mask; /* Clear all bits in PORTA that are set in mask. */
         }
    

    But without you telling us what you intent to do, we won't be able to help.

    Best regards

    Raphael

     
  • alejandro1957
    alejandro1957
    2011-08-09

    Raphael, thanks for the reply.
    the problem is that I use more than one port (management of 12 servo).8 PORTB + 8 PORTD + 4 PORTC (PIC16F877A) .
    I had already thought the mask type
    PORTB=0x01;
    …….
    PORTB=0xFF;
    but as you could do with more than one port????

    the library GCBASIC is:

    'PulseOut

    macro Pulseout (Pin, Time)

    Set Pin On

    Wait Time

    Set Pin Off

    end macro

     
  • Raphael Neider
    Raphael Neider
    2011-08-09

    You will have to use pointers:

    void Pulseout(volatile unsigned char *port, unsigned char mask, unsigned int Valor)
    {
        *port |= mask; /* Set all bits that are set in mask. */
        Delay_us(Valor);
       *port &= ~mask; /* Clear all bits that are set in mask. */
    }
    
    Pulseout(&PORTA, (1 << 4), 1000);
    Pulseout(&LATA, (1 << 4), 1000);
    
     
  • alejandro1957
    alejandro1957
    2011-08-10

    thanks for the code, I'll try during the week.
    happy holidays to all…………… :-)