Shop OBEX P1 Docs P2 Docs Learn Events
How do I properly use the CTRA/FRQA/PSHA calls? — Parallax Forums

How do I properly use the CTRA/FRQA/PSHA calls?

PoundSign2PoundSign2 Posts: 129
edited 2013-10-13 22:32 in Propeller 1
Hello friends! While looking through the OBEX I found some PWM objects and I wanted to better understand PWM. It's not something that I use frequently so I don't have much experience with it. After looking through the Propeller Manual under the CTRA/FRQA/PHSA commands I didn't come away with an exact method of using it properly. The point of the CTRA is to be the Counter and FRQA I believe sets the frequency (seems obvious) however I really don't know what PHSA is or how it works, and I don't know what it means. My guess is that PHSA means Phase(PortA).

While the OBEX files have given me a much better intuition as to how the code is executing and doing it's thing, I still do not understand how to construct the code on my own. A little insight and help would be much appreciated. Especially a good expanation for what is going on. Like what is CTRA, why do I use this and why and how do I use the other 2 registers (PHSA & FREQA)?

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2013-10-13 14:35
    You need to have a look through the Parallax Semiconductor Application Notes, particularly AN001 which documents the counters and the various modes of operation. It includes sample code. AN008 describes the use of the counters to implement an ADC.
  • jmgjmg Posts: 15,173
    edited 2013-10-13 19:06
    PoundSign2 wrote: »
    . Like what is CTRA, why do I use this and why and how do I use the other 2 registers (PHSA & FREQA)?

    Follow Mike's suggestion, and it's likely the biggest conceptual leap, is to grasp that a Prop 'Counter' is actually a 32 bit adder that can do

    PHSA = FRQA + PHSA at a rate up to once every clock cycle.

    The Add is conditional, based on the 5-bit CTRMODE Field in the CTRA config register.

    In the DOCs it says : The counter operates by adding the contents of FRQA to PHSA at each clock cycle the accumulate condition is true.
  • PoundSign2PoundSign2 Posts: 129
    edited 2013-10-13 19:49
    The AN001 uses a lot of Assembly it appears. Is there a more direct guide to how to do PWM for brightness control? I am beginning to understand it more, but learning this plus assembly is just a bit more than my skill will allow.
  • Mike GreenMike Green Posts: 23,101
    edited 2013-10-13 20:54
    The best way to do PWM is to use a ready-to-go object from the Object Exchange that handles the counters for you using assembly when needed. This object and this object will do PWM for you. The first does it directly in PASM. The second uses the video generator and PASM to do it. This third object only uses the cog counters, but has some limitations.
  • PoundSign2PoundSign2 Posts: 129
    edited 2013-10-13 22:32
    Mike Green wrote: »
    The best way to do PWM is to use a ready-to-go object from the Object Exchange that handles the counters for you using assembly when needed. This object and this object will do PWM for you. The first does it directly in PASM. The second uses the video generator and PASM to do it. This third object only uses the cog counters, but has some limitations.

    Thanks a bunch for the links. Earlier I downloaded another example however, I've spent the last few hours trying to modified to something I could use. Hadn't got a clue how to make it work, but I tried and managed to learn a bunch in the process (since I was looking up syntax like crazy). Anyways what I did was download THIS OBEX file and tried to get it to work on all 8 pins (16..23) but I could never get it to work. I somehow got 6 to turn on, but I don't know how I did it. Just a chance bug perhaps. In any case, thanks for the help I really appreciate. The 32 channel PWM OBEX file is pretty much what I'm looking for. I just want to control the Demo Board and QuickStart on-board LEDs to experiment with.
Sign In or Register to comment.