Shop OBEX P1 Docs P2 Docs Learn Events
Can the SX generate a 32 bit word? — Parallax Forums

Can the SX generate a 32 bit word?

datacpsdatacps Posts: 139
edited 2007-08-08 02:08 in General Discussion
I read the information on the DDS that uses a 32 bit word command to generate a frequency from 0 to 30 mhz. I also got info that the prop chip can do it but I don't know assembly or Spin.· I have my circuit working perfectly Thanks to Bean with a freqout up top 20Khz with 1 hz accuracy of 1 hz.· The um-fpu chip is 14.00 dollars just to write 32 bit words. Then another 14 for the DDS chip.. I also was wondering what is the highest freqout possible (it does not have to be accurate above 20khz.) It just needs to send a high freqout to pulse a neon transformer and light up a tube. I was testing one and I set my Function generator to 271khz to light the tube I was using.·I did my·PCB layout to include both chips and a fram chip too incase I need to go that route...·I am trying to figure out which way to go on this?

Also the EEPROMs are 2.40 @ I rather buy another sxchip 28 or 48 for 2.51 and get 50 million times better chip.
eyes.gif·

Comments

  • Sparks-R-FunSparks-R-Fun Posts: 388
    edited 2007-08-01 16:33
    The SX uses an 8-bit core. Internally all math and logic operations are done using 8-bit numbers. Larger numbers can be “processed” through the use of additional instructions and logic. SX/B adds this additional processing whenever Word variables are used instead of Byte variables. So the answer to your question is that the SX can generate a 32-bit number if you explicitely program it to do this. However it can not natively do this with a built-in instruction.

    You may want to look at the 32-bit math routines found on SxList.com If you want to learn to do 32-bit math on the SX you can save $14.00 - $2.51 = $11.49. If you think it will take you more than an hour or two to set that up and want to save time… $14 might not seem so steep!

    I can not speak with authority on the maximum frequency limitation of the SX. However, I expect it will be in the MHz range when coupled with an appropriate oscillator. It should be more than enough to drive your neon transformer.

    I hope this helps.

    - Sparks
  • datacpsdatacps Posts: 139
    edited 2007-08-01 21:43
    Thanks Sparks..... I thought it could do it which will save me on getting the CO-Chip. I think I will switch to the SX48 which should have room to do everything I need it to do and I won't have to add another SX 28. I will still use the FRAM chip to store the values that I need to run in automode.
    BTW Sparks you have a great website with a lot of fun stuff. Thanks for all your help.
  • Sparks-R-FunSparks-R-Fun Posts: 388
    edited 2007-08-03 21:18
    The SX48 should be able to process your 32-bit numbers fine if you are willing to take the time to figure out how to do it.

    As for the website, I assume you are referring to SparkFun.com. I agree. It is a great site! Unfortunately I had no part in that and am not affiliated with the site. I have noticed, however, that a good formula for success in the hobby world is to give information away for free and charge reasonable prices for your products. Parallax and SparkFun both do a great job of this!

    Let us know if you get 32-bit math working. I am sure there will be others interested in doing 32-bit math at some point.

    - Sparks
  • datacpsdatacps Posts: 139
    edited 2007-08-04 16:30
    Thanks again Sparks.. I am reading the information on the SX/List I am trying to figure out how to convert the value from my encoders to a 32 bit. In the examples it show how to add and multiply ect.. I have my sub already readiing my encoders then generating the freqout. I have to look at it and see if there is anyway to convert to 32 bit or I have to change my sub to create the 32 bit value. I am out of RAM so I have to go to the SX/48. I am ordering the SX/48 board for ten dollars.. You can't beat that .. and you are right about how Parallax and Sparkfun. If it where not for the Stamp I would have never got into this hobby and if it wasn't for this forum and the members here like yourself I would have never been able to complete my projects. I am just upset I did not get into it sooner because it is so much fun that I am addicted to it. This is way better than video games.. AS for the MATH it is not my best subject so it will take me a little time to figure it out. I also have to figure a way to store the 32 bit value to the FRAM chip and then run them in a autorun mode. I am open to suggestions...Thanks again
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2007-08-05 18:42
    If you want to do 32bit math easily, check out C4SX:
    http://forums.parallax.com/showthread.php?p=663042
    The cc1b compiler supports 32bit integer, fixed point and floating point math.
    It uses operator overloading so you can use the normal expression symbols
    * + - / % (eg. float c = a * b[noparse];)[/noparse].

    regards peter
  • datacpsdatacps Posts: 139
    edited 2007-08-07 00:40
    I looked at the link but I like using SX/B for now. I will try to do it in SX/B if possible I don't know how I will do it yet. It looks like I will have to eventually learn assembly, or C or another language to do more complicated programming. There should be a way to do it with SX/B I was hoping someone pointed me in the right direction......Thanks for the info Peter.
  • BeanBean Posts: 8,129
    edited 2007-08-07 12:54
    Carlos,
    · Here is a routine you can add to the program I already wrote for you that will set the frequency to 8 times the value given. It is a modified version of the original subroutine. You can have both in your program.

    · This SetFreqX8 works up to 388KHz (by specifying a value of 48500).

     
    SUB SetFreqX8  ' SetFreqX8 SUB 1,2
      ' NOTE: Values above 48500 will be limited to 48500 (388 Khz)
      ' NOTE: Values below 70 will not generate anything (no interrupts), 
      '  this can be used to disable the interrupts to do serial comm or other critical timing
     
      IF __PARAMCNT = 1 THEN
        freqWanted = __PARAM1
      ELSE
        freqWanted = __WPARAM12
      ENDIF
     
      IF freqWanted < 70 THEN
        freqWanted = 0
      ENDIF
     
      IF freqWanted > 48500 THEN
        freqWanted = 48500
      ENDIF
     
      tempW2 = $2FAF ' $2FAF0800 = 800,000,000 ((50MHz / 16) * 256)
      tempW = $0800
     
      period = 0
      optReg = 0 ' Assume freq is below 382 (no interrupts)
     
      IF freqWanted > 70 THEN
        optReg = 1 ' Assume prescaler is 1:1
        ' Adjust prescaler to keep frequency above 12207
        DO
          IF freqWanted < 12208 THEN
            freqWanted = freqWanted << 1 ' * 2
            INC optReg ' Adjust prescaler
          ENDIF
        LOOP UNTIL freqWanted >= 12208
      
      
        ' Perform division period = 800,000,000 / frequency
        FOR temp = 1 TO 17
          period = period << 1
          IF tempW2 >= freqWanted THEN
            period.0 = 1
            tempW2 = tempW2 - freqWanted
          ENDIF
          tempW2 = tempW2 << 1
          tempW2.0 = tempW.15
          tempW = tempW << 1
       NEXT
    
     
      ENDIF ' freqWanted >= 382
     
      ' Set period+1
      periodMSBPlus1 = period_MSB + 1
    
     
      ' Get option register value
      LOOKUP optReg, $A0, $88, $80, $81, $82, $83, $84, $85, $86, $87, optReg
    
     
      ' Set option register
      OPTION = optReg
    
     
      ' If no frequency output, make sure pin is low
      IF optReg = $A0 THEN
        FreqOutPin = 0
      ENDIF
    ENDSUB
     
    

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Teacher: What is the difference between ignorance and apathy ?
    Student: I don't know and I don't care
    Teacher: Correct !
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.hittconsulting.com


    Post Edited (Bean (Hitt Consulting)) : 8/7/2007 12:59:51 PM GMT
  • datacpsdatacps Posts: 139
    edited 2007-08-08 02:08
    Wow Bean thanks again. You make it seems so easy. I would of tried to change the entire Sub. It just needed your touch to a few lines and there it is. This chip and Parallax just keep amazing me. When I think I have to go to a bigger chip or another chip people like yourself have solutions for newbies and others on this forum.

    The code for 32 bit
    DO
    IF freqWanted < 12208 THEN
    freqWanted = freqWanted << 1 ' * 2
    INC optReg ' Adjust prescaler
    ENDIF
    LOOP UNTIL freqWanted >= 12208

    Original code
    DO
    IF freqWanted > 24414 THEN
    freqWanted = freqWanted >> 1 ' / 2
    DEC optReg ' Adjust prescaler
    ENDIF
    LOOP UNTIL freqWanted <= 24414

    With just a few lines of code you can do it just like that.. I was reading all the other stuff and did not have a clue where to begin. I am out of Ram but you just changed a few lines of the original code and it now generates 32 bit. I don't think I can find the words to thank you bean and the other great members on this site.. I am not sure enough to explain what you did but it looks like you multiplied the freqwanted by 2 and inc the adjust prescale .
    new code
    IF freqWanted > 70 THEN
    optReg = 1 ' Assume prescaler is 1:1
    ' Adjust prescaler to keep frequency above 12207

    original code
    IF freqWanted >= 382 THEN
    optReg = 4 ' Assume prescaler is 1:8

    I posted what I see and hope that maybe this will help other members that may have the same question..
Sign In or Register to comment.