Shop OBEX P1 Docs P2 Docs Learn Events
My first attempt at Spin — Parallax Forums

My first attempt at Spin

Pablo1234Pablo1234 Posts: 19
edited 2010-05-27 07:09 in Propeller 1
ok hear is my code, I'm trying to emulate my pbasic code I wrote weeks ago.
the concept is that lfo1Amp will contain an 8 bit integer that I will send to a I2C DAC with some more code. I want access to the freq (.084mS - 10,000 mS) and duty of the triangle wave without changeing the Freq or phase. I do understand I could do this alot easyer with cnta in duty mode but I want to start my prop exp with trying to convert my pbasic code and adding features.
please give me comments I havent had time to upload this to my prop yet and won't till next thursday, I'm haveing twins in 2 weeks so my wife has me doing all kinds of fun things around the house.
 

I know its slopy and clumsy but its my first atempts at SPIN.

found some bracket errors i fixed at the end.

another edit, I addid bit reduction and bias settings and some description notes

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
A woman is the only thing I am afraid of that I know will not hurt me. - Abraham Lincoln

http://www.youtube.com/user/Pablos0071·projects I have worked

Post Edited (Pablo1234) : 5/26/2010 2:22:18 PM GMT

Comments

  • mparkmpark Posts: 1,305
    edited 2010-05-22 14:25
    I find it very confusing that your lfo1 "frequency" actually appears to be the period of the waveform. Also, use s for seconds, not S (S is the abbreviation for siemens).
    Good luck with the twins.
  • Pablo1234Pablo1234 Posts: 19
    edited 2010-05-22 19:13
    yes due to useing 500 microseconds timeslice the frequency is equivalent of the time on and also the time off. if it was in 1 millisecond it would be half.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    A woman is the only thing I am afraid of that I know will not hurt me. - Abraham Lincoln

    http://www.youtube.com/user/Pablos0071·projects I have worked
  • Pablo1234Pablo1234 Posts: 19
    edited 2010-05-23 14:47
    I'm not realy familer with execution times in spin. how long would it take rougly to execute the loop? in the BS2p it would be considerable, I actualy took my pause out altogether in my PBasic code when doing this and it was only outputing a square wave.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    A woman is the only thing I am afraid of that I know will not hurt me. - Abraham Lincoln

    http://www.youtube.com/user/Pablos0071·projects I have worked
  • TonyWaiteTonyWaite Posts: 219
    edited 2010-05-26 14:28
    Hi Pablo1234,

    I can't see your code - could you kindly re-post it so that we can take a look?

    Regards,

    T o n y
  • StefanL38StefanL38 Posts: 2,292
    edited 2010-05-26 21:04
    First of all a BIG compliment to you for beeing brave enough to ask "why would (almost) nobody answer me?"

    I'm almost everyday in this forum for three years know and I haven't seen this question before.
    You seem to have a healthy selfconfidence and I appreciate this kind of asking very much.

    OK, so as long as we wait for the code beeing reposted or even better re-attached a hint about execution-time

    Do you have an oscilloscope? If yes you could add a line of code that does toggle an IO-pin by xor-ing the corresponding bit of an IO-Pin in the OutA-register
    and then measuring the frequency

    Another approach could be to start a frequency measuring code in a second cog (which in fact runs completely independent from the other code as the standard-case)
    and measure the frequency of the bit toggling with that code. Then execution-time is 1/freq

    I understand the basic thing of what you are doing. But with the small comments you made in the code it would take me an hour to understand what is going on in your code.
    Which line of code does what?

    I enjoy researching solutions to questions if I understand the details of a problem within 5 minutes even if the research or writing samplecode takes two hours.
    As this forum is a free thing to answer or not I feel free to do it that way.

    best regards

    Stefan
  • JasonDorieJasonDorie Posts: 1,930
    edited 2010-05-27 02:17
    Not being able to see the code, it's difficult to guess how long it might take, however there's a different way to do it - Measure it.

    In many of my programs, I use code like this:
    StartTime := cnt  'cnt is the system cycle counter
     
    repeat 10
      CallFunction
     
    ElapsedTime := cnt - StartTime
    

    If you use the SimpleSerial object or TV object to send the results to either the PropSerialTerminal or to a TV, you can see exactly how many clock cycles the code took to execute.· Since you know what your clock speed is, you can easily convert the result to seconds.· I usually leave the result in cycles, because it's more accurate when measuring my code optimization efforts.


    Note that there will be some overhead involved in taking the measurement, but you can figure out what that is by doing this:

    StartTime := cnt  'cnt is the system cycle counter
    MeasurementOverhead := cnt - StartTime
    
    

    For most things this wouldn't matter, but if you're measuring a very small amount of code it might be useful.

    Jason
    ·
  • MagIO2MagIO2 Posts: 2,243
    edited 2010-05-27 07:09
    @JasonDorje:
    Just a little addendum to make it clear for everyone, if you need adequate time-measurement the full sequence looks like that

    StartTime := cnt  'cnt is the system cycle counter
    MeasurementOverhead := cnt - StartTime
     
    StartTime := cnt
     
    ' code to be measured comes here
     
    ElapsedTime := cnt - StartTime - MeasurementOverhead
    
    

    In the example you gave (repeat ... + call function) the repeat and call time is included as well. So, if you are really interested in the pure runtime of the function you can include the repeat 10 between StartTime and MeasurementOverhead. This subtracts the time for the repeat handling. And if you like you can also call an empty function with the same number of parameters, which also eliminates the overhead for preparing the call stack, call the function and return. Then you really get a number which tells you how long the code inside the function took.

    Surely it's obvious to all the skilled people here, but my feeling is that there·might some who'll·be happy for·the pointer.

    Post Edited (MagIO2) : 5/27/2010 7:17:04 AM GMT
Sign In or Register to comment.