Jump to content
43oh

vladn

Members
  • Content Count

    49
  • Joined

  • Last visited

  • Days Won

    3

Reputation Activity

  1. Like
    vladn got a reaction from MichelKohler in PWM changes depending on the code it's running   
    Ok, I found a partial workaround within a baseline Energia framework. The idea is to re-sync analogWrite() to the pwm signal iself . This works OK up to around 580Hz PWM frequency (good enough for my brushed motor PID controller project). For highly dynamic PWM (like audio) I have to dig deeper...
    int pwm; int dir; void setup() { //attach the PWM update interrupt handler to the PWM pin itself //*must* use the *rising* edge (falling edge messes up PWM) //on my Tiva-C Launchpad this works up to ~580Hz PWM frequency attachInterrupt(RED_LED, handler, RISING); //prime the pwm pin interrupts pwm = 1, dir = 1; analogWrite (RED_LED, pwm); } void loop() { pwm += dir; //pwm value should be constrained between 1 and 245, otherwise interrupts stop if (pwm == 254 || pwm == 1) dir = -dir; delayMicroseconds(2733); //some random value } //handler without the pwm value change detection logic void handler() { analogWrite (RED_LED, pwm); } /* //handler with the pwm value change detection logic void handler() { static int p_pwm = -1; if (p_pwm != pwm) { analogWrite (RED_LED, pwm); p_pwm = pwm; } } */
  2. Like
    vladn got a reaction from MichelKohler in PWM changes depending on the code it's running   
    I've spent some time recently experimenting with the Tiva timer PWM mode (not the PWM module). I have modified the wiring_analog.c such that duty cycle changes using PWMWrite() are now glitch free. Hence it is suitable for driving servos and other timing critical sources with frequent duty cycle updates. No interrupts are required.
     
    The changes are:
    - bypassing the timer disable/reset if it is already initialized to the PWM mode;
    - setting both MRSU and ILD bits in the Mode register such that both frequency and match register update are postponed to the next timer period;
    - the intermediate result of the duty cycle computation is increased so that large analog_res values do not cause overflow (useful for setting the duty cycle in microseconds for the servo)
     
    I tried to do a "minimally invasive" code modification to avoid compatibility issues. If the module interface change is acceptable then things can be done a bit cleaner/faster. Since I've already spend time learning the Tiva timer internals I can do further tweaks to the code if there is a community consensus on the optimal PWM interface (as a superset of Arduino).
     
    Try the code and see if you find any issues with it. If it does not cause any compatibility problems perhaps someone can help me integrate it into the next energia release.
    wiring_analog.c
  3. Like
    vladn got a reaction from L.R.A in PWM changes depending on the code it's running   
    I've spent some time recently experimenting with the Tiva timer PWM mode (not the PWM module). I have modified the wiring_analog.c such that duty cycle changes using PWMWrite() are now glitch free. Hence it is suitable for driving servos and other timing critical sources with frequent duty cycle updates. No interrupts are required.
     
    The changes are:
    - bypassing the timer disable/reset if it is already initialized to the PWM mode;
    - setting both MRSU and ILD bits in the Mode register such that both frequency and match register update are postponed to the next timer period;
    - the intermediate result of the duty cycle computation is increased so that large analog_res values do not cause overflow (useful for setting the duty cycle in microseconds for the servo)
     
    I tried to do a "minimally invasive" code modification to avoid compatibility issues. If the module interface change is acceptable then things can be done a bit cleaner/faster. Since I've already spend time learning the Tiva timer internals I can do further tweaks to the code if there is a community consensus on the optimal PWM interface (as a superset of Arduino).
     
    Try the code and see if you find any issues with it. If it does not cause any compatibility problems perhaps someone can help me integrate it into the next energia release.
    wiring_analog.c
  4. Like
    vladn got a reaction from L.R.A in PWM changes depending on the code it's running   
    To illustrate the benefits of the glitch free PWM here is a super trivial (essentially a one liner) servo library. No interrupts required - very efficient. Supports digital servos at higher PWM freqs too ! Two examples are included - a  minimalistic one for a single servo, and a bit more involved one running 3 servos asynchronously with different control PWM frequencies and sweep periods. This library *requires* the wiring_analog.c file from the post above (it replaces the original one in the hardware/lm4f/cores/lm4f/).
     
    TServo.zip
  5. Like
    vladn got a reaction from L.R.A in PWM changes depending on the code it's running   
    The linker seems to have a sporadic problem (huge .bin files) with uint64_t that I used in the updated PWMWrite(). Changed the type to float and things seem to work OK now. Please use the updated version:
    wiring_analog.c
    Also added support for the floating point angle to the TServo
    TServo.zip
    Updated code also posted to github:
    https://github.com/vladn2/Energia/
     
  6. Like
    vladn reacted to spirilis in assembler listing   
    From cli, cd into the tmp build dir where it compiled the sketch then use arm-none-eabi-objdump -dS on the .elf file. Kudos to @@Rickta59 for teaching me that trick.
  7. Like
    vladn got a reaction from bluehash in [Energia Library] Arduino "Scheduler" port to Energia Qs   
    Below is the variant with the automatic yield at the end of all loops. You can defeat it by defining NO_AUTO_YIELD in the Energia.h.
    Also included is an additional example how to spawn a task (not a loop). It does the job then exits, the context descriptor is then deallocated by the "scheduler".
     
    I really like this task switcher, it is clean and minimalistic. Perhaps adding power management (going to sleep if all threads are suspended with a wakep on timer) would help, but for 95% hobbby apps this is not critical.
     
    Again to run it you need both the library and the changes to the Energia core files (in ./hardware/lm4f/cores/lm4f/ directory):
    Scheduler_v02.zip
    core_changes_v02.zip
  8. Like
    vladn got a reaction from reaper7 in [Energia Library] Timer based non-blocking "pulseIn" equivalent   
    Since I already "killed" time learning Tiva timer internals I decided to publish a library for a timer-based non-blocking "pulseIn" eqiuvalent. The library sets the timer to the edge time capture mode. Then interrupt is used to read the values captured by the timer.
     
    The library can measure positive and negative intervals simultaneously. It also can measure the pulse duration in a continuous pulse train.
     
    My initial intention was to use it with HC-SR0x sonars such that:
    - acquisition delay in the loop() could be completely avoided;
    - no long interrupts are required (improving the system interrupt latency);
    - pulse duration measurement accuracy is very high since it is done in hardware.
    I think there are more applications for this, for example reading RC servo input signal or even decoding PPM.
     
    There are two examples: a basic test project and an illustration of the asynchronous (non-blocking) sonar operation.
     
    This is v0.1, there could be bugs but things are working OK so far. Enjoy...
     
    TPulseIn.zip
  9. Like
    vladn got a reaction from bluehash in [Energia Library] Arduino "Scheduler" port to Energia Qs   
    Ok, here is the first attempt. I kept the Copyright headers intact. My background is in EE, I have zero experience with open software project management tools in general and github in particular.
     
    Here is the library. It is a true cooperative context switcher. The default context stack size for the new task is 1024 (defined in Scheduler.h).
    It worked with almost no changes.
    Scheduler.zip
     
    However it needs changes to the delay function in the wiring.c and an empty "hook" from the Arduino source distribution for the yield() (so that the modified delay is backwards compatible and works without the scheduler).
    changes.zip
    These need to be placed in the ../hardware/lm4f/cores/lm4f/ directory (hooks.c is a new file, wiring.c is a replacement).
     
    The test code works on my Tiva Launchpad as it should. So does the delay in a plain (non-scheduler) code. Please let me know if I messed up something.
  10. Like
    vladn got a reaction from bluehash in [Energia Library] Timer based non-blocking "pulseIn" equivalent   
    Since I already "killed" time learning Tiva timer internals I decided to publish a library for a timer-based non-blocking "pulseIn" eqiuvalent. The library sets the timer to the edge time capture mode. Then interrupt is used to read the values captured by the timer.
     
    The library can measure positive and negative intervals simultaneously. It also can measure the pulse duration in a continuous pulse train.
     
    My initial intention was to use it with HC-SR0x sonars such that:
    - acquisition delay in the loop() could be completely avoided;
    - no long interrupts are required (improving the system interrupt latency);
    - pulse duration measurement accuracy is very high since it is done in hardware.
    I think there are more applications for this, for example reading RC servo input signal or even decoding PPM.
     
    There are two examples: a basic test project and an illustration of the asynchronous (non-blocking) sonar operation.
     
    This is v0.1, there could be bugs but things are working OK so far. Enjoy...
     
    TPulseIn.zip
  11. Like
    vladn got a reaction from AxelTB1426459920 in [Energia Library] Timer based non-blocking "pulseIn" equivalent   
    Since I already "killed" time learning Tiva timer internals I decided to publish a library for a timer-based non-blocking "pulseIn" eqiuvalent. The library sets the timer to the edge time capture mode. Then interrupt is used to read the values captured by the timer.
     
    The library can measure positive and negative intervals simultaneously. It also can measure the pulse duration in a continuous pulse train.
     
    My initial intention was to use it with HC-SR0x sonars such that:
    - acquisition delay in the loop() could be completely avoided;
    - no long interrupts are required (improving the system interrupt latency);
    - pulse duration measurement accuracy is very high since it is done in hardware.
    I think there are more applications for this, for example reading RC servo input signal or even decoding PPM.
     
    There are two examples: a basic test project and an illustration of the asynchronous (non-blocking) sonar operation.
     
    This is v0.1, there could be bugs but things are working OK so far. Enjoy...
     
    TPulseIn.zip
  12. Like
    vladn got a reaction from Rei Vilo in [Energia Library] Arduino "Scheduler" port to Energia Qs   
    I have ported the Arduino cooperative scheduler described here:
    http://arduino.cc/en/Reference/Scheduler
    to Energia (Tiva Launchpad) platform.
     
    However, being new to both Arduino and Energia I need some help from Energia guys, specifically:
    1. Check the copyright issues - is it OK to port this thing to Energia (the code seem to have an Android Open Source Project Copyright) ?
    2. It required some minor mods to few Energia files (wiring.c Energia.h). Not sure where should I post it.
    3. If #1 is OK I'll post the library for testing here.
  13. Like
    vladn reacted to fughilli in 3 new libraries: Arduino "Servo" library clone, ultrasonic ranger library, data smoothing library   
    Hello all!
     
    I've got three new libraries to share with you!
     
    They are:
     
    An Arduino "Servo" library clone (StellarPad):
     
    Duplicates all of the functionality of the Arduino "Servo" library. Fully compatible with all existing sketches that use the Arduino "Servo" library. Based upon the Eigendreams servo library posted here a while back. Supports 8 servos as-is. Can be modified to do a heck of a lot more, but that is up to you to incorporate (at least for now -- update to come soon).
     
    An ultrasonic rangefinder library (StellarPad, easily modifiable to work with other Energia devices):
     
    Designed for the HC-SR04 rangefinder, about $5 on e-bay. Should also work with some other rangefinders, but I have not tested any others. That is, again, up to you (for now). Supports as many of them as you can fit on your I/O.
     
    A data smoother library (All Energia/Arduino supported devices):
     
    Inspired by the Arduino "smoothing" example by Tom Igoe. Allows the creation of "Smoother" objects that calculate running averages of raw data. "Smoother" is a template class and can be instantiated to work with int's, float's, long's, etc.
     
    All three libraries have their own examples, and the following is an example that incorporates the functionality of all of them (No comments, sorry! This one is pretty self-explanatory. See the library-specific examples for more details):
    #include <SonicRanger.h> #include <Smoother.h> #include <Servo.h> SonicRanger sr; Servo servo; Smoother<int, 10> ssmoother; boolean smoothing = false; void setup () { sr.attach(PE_1, PE_2); servo.attach(PF_1); pinMode(BLUE_LED, OUTPUT); digitalWrite(BLUE_LED, LOW); pinMode(PUSH2, INPUT); attachInterrupt(PUSH2, buttonISR, FALLING); } void loop () { float distance = sr.getDistance(INCHES); int processedDistance; if(distance > 0) { processedDistance = (int)(distance * 1000); processedDistance = constrain(processedDistance, 2000, 12000); if(smoothing) { ssmoother.pushValue(processedDistance); processedDistance = ssmoother.pullValue(); } servo.write(map(processedDistance, 2000, 12000, 0, 180)); } delay(50); } void buttonISR () { smoothing = !smoothing; digitalWrite(BLUE_LED, smoothing); } Video demonstration of the above example sketch:
     
    http://youtu.be/IViqIa4Rl9Y
     
    Enjoy!
     
    -K/Fughilli
    SonicRanger.zip
    Smoother.zip
    Servo.zip
  14. Like
    vladn reacted to bluehash in RC522 Library on Stellaris   
    Sorry for the trouble everyone. It has been fixed. Please double check and let me know.
    Again apologies.
  15. Like
    vladn got a reaction from JVimes in Development kit terminology (newbie question)   
    Hi everyone. I am also new to the MSP430 and have few questions related to this topic.
    (I have an engineering background and quite faimilar with coding and HW, but the last time I did micro work was >10yrs ago).
     
    I've got a MSP-EXP430G2 Launchpad and installed  the CCS. I can blink LEDs and do other simple stuff.
    I am a bit confused on the Launchpad functionality though -
    1. What exactly happens when I run debug (F11) in CCS ? Does the program run on the socketed device or in the emulator part ?
    2. Does run->debug actually program the flash memory on the socketed device ?
    2.a If "no" can I use the CCS+Launchpad to flash the socketed device when finished debugging (and use it outside of the launcpad) ?
    2.b If "yes" how can avoid flashing the device every time I debug something ?
     
    I apologise for dummy (and possibly repeated) questions. If you can point me to the a relevant thread or a TI document I would much appreciate the help !
×
×
  • Create New...