Shop OBEX P1 Docs P2 Docs Learn Events
Toggling I/O pins at high frequency — Parallax Forums

Toggling I/O pins at high frequency

analog2003analog2003 Posts: 4
edited 2010-09-07 11:49 in Propeller 1
Hello

I am using the Propeller chip for the very first time. I am stuck with something, and hoping someone out there has some suggestions on how to go about it.
I am using this controller to generate periodic 50% duty-cycle switching signals. The clock is at 80MHz and used the "waitcnt" command (format: waitcnt(offset + cnt)) to toggle the desired outputs. The documentation says that the min offset is 381 and I also got from one of the help spin files that the shortest pause time with a 80MHz clock is about 54usec.
Now, my question is, is it possible by any other method to obtain the switching at higher frequency? I am aiming for frequencies around 1MHz.

Thanks in advance.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2010-09-02 15:53
    Using WAITCNT is somewhat limiting. There are two counters in each cog that can be used to generate pulse trains with 50% duty cycle well over 80MHz and these can be set up using Spin. Download the application note on the counters (AN001). Go to the main Parallax webpage and click on the Downloads button. You'll see a Propeller Downloads button. Click on that and you'll see a link to the application note and sample code.
  • analog2003analog2003 Posts: 4
    edited 2010-09-07 10:14
    Awesome! That really helped. However, I need multiple pins to toggle at the same frequency. I tried to read the states of APIN using "ina[APIN]", but I am unable to assign it to another I/O pin. I tried different options which result in a syntax error. I think I am doing it the wrong way. I am also thinking if it actually is possible to assign states of an I/O pin to another.

    Thanks again for your help.
  • Mike GreenMike Green Posts: 23,101
    edited 2010-09-07 10:31
    There are delays inherent in copying the state of one I/O pin to another. It's quite possible to use multiple counters, but setting up the relative phase relationships can be difficult. It sounds like you need to use assembly language to toggle the I/O pins. It's quite easy there to set up whatever relationship you want from one I/O pin to another.

    You really need to describe your needs in more detail. It's difficult to advise you without more information.
  • analog2003analog2003 Posts: 4
    edited 2010-09-07 10:48
    Yes, I figured there would be delays in copying the state of a pin to other. Actually, I cannot even see the delayed output at the pins to think about correction. All this is to generate 4-bit digital word going from 0000 to 1111, which means I need 3 more pins to do the same as APIN. I was wondering if it is not possible to do that in SPIN?
  • Mike GreenMike Green Posts: 23,101
    edited 2010-09-07 11:02
    You can easily write to 4 I/O pins at the same time whether in Spin or assembly. You could also use the video generator to do this. That (among other things) consists of a special purpose shift register that could be used to shift out 4 x 4-bit values (actually 4 x 8-bit values with 4 bits ignored). It all depends on the details (which you are not giving for some reason).
  • analog2003analog2003 Posts: 4
    edited 2010-09-07 11:16
    I could provide more information for sure, its just that I do not realize what more information is required here. Please let me know.
  • tonyp12tonyp12 Posts: 1,951
    edited 2010-09-07 11:31
    If you want a 4 bit counter updated at 1mhz on 4 pins,
    And just sticking to Spin?
  • Mike GreenMike Green Posts: 23,101
    edited 2010-09-07 11:49
    Things to describe:

    1) Frequency or repetition rate of signal, range of this if variable.

    2) Relationship of one set of 4 I/O states to another. Are you trying to produce waveforms? Stepper motor drive signals?
Sign In or Register to comment.