Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Hardware & Devices
  4. Discussing with me about my program

Discussing with me about my program

Scheduled Pinned Locked Moved Hardware & Devices
comtutorialquestion
2 Posts 2 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    ling1995
    wrote on last edited by
    #1

    Respected sir: I am involving in a program which is written by myself about using MSP430F149 to control the step motor.I would like to show them here.( this is the datasheet of MSP430F149: [^] )And I think maybe they could be improved but I don’t know how to do it. Could you give me some suggestions? This is the program: <#include <msp430x14x.h> typedef unsigned int uint; typedef unsigned char uchar; #define PWM BIT2 void int_clk() { uchar i; BCSCTL1&=~XT2OFF; //open XT oscillator BCSCTL2|=SELM1+SELS;//MCLK 8M and SMCLK 1M do { IFG1 &= ~OFIFG; //clean the wrong sign of vibration for(i = 0; i < 100; i++) _NOP(); //delay waiting } while ((IFG1 & OFIFG) != 0); //If sign is 1,continue to wait IFG1&=~OFIFG; } void int_pwm() { P1SEL|=PWM;//choose P12 to bePWM output P1DIR|=PWM; TACCR0=800;//PWM signal cycle 10KHz TACCR1=400;//duty cycle 1:1 TACCTL1=OUTMOD0+OUTMOD1+OUTMOD2; //outputted mode choosing TACTL|=TASSEL1+MC0; } void main() { WDTCTL=WDTPW+WDTHOLD;//close watchdog int_clk(); //clock initialization int_pwm(); //initialize PWM while(1);//end> The program is base on controlling the return of step motor by using MSP4300f149. The outputted port of PWM is P1.2 while the signal cycle is 10KHZ. The duty cycle is 1:1. Do you have any advice about my program? Best wishes~

    J 1 Reply Last reply
    0
    • L ling1995

      Respected sir: I am involving in a program which is written by myself about using MSP430F149 to control the step motor.I would like to show them here.( this is the datasheet of MSP430F149: [^] )And I think maybe they could be improved but I don’t know how to do it. Could you give me some suggestions? This is the program: <#include <msp430x14x.h> typedef unsigned int uint; typedef unsigned char uchar; #define PWM BIT2 void int_clk() { uchar i; BCSCTL1&=~XT2OFF; //open XT oscillator BCSCTL2|=SELM1+SELS;//MCLK 8M and SMCLK 1M do { IFG1 &= ~OFIFG; //clean the wrong sign of vibration for(i = 0; i < 100; i++) _NOP(); //delay waiting } while ((IFG1 & OFIFG) != 0); //If sign is 1,continue to wait IFG1&=~OFIFG; } void int_pwm() { P1SEL|=PWM;//choose P12 to bePWM output P1DIR|=PWM; TACCR0=800;//PWM signal cycle 10KHz TACCR1=400;//duty cycle 1:1 TACCTL1=OUTMOD0+OUTMOD1+OUTMOD2; //outputted mode choosing TACTL|=TASSEL1+MC0; } void main() { WDTCTL=WDTPW+WDTHOLD;//close watchdog int_clk(); //clock initialization int_pwm(); //initialize PWM while(1);//end> The program is base on controlling the return of step motor by using MSP4300f149. The outputted port of PWM is P1.2 while the signal cycle is 10KHZ. The duty cycle is 1:1. Do you have any advice about my program? Best wishes~

      J Offline
      J Offline
      Jochen Arndt
      wrote on last edited by
      #2

      What kind of answer do you expect? You are mainly setting configuration registers which can't be improved. The only code portion that can be improved is the loop in your int_clk() function. The final clearing of the OFIFG bits can be omitted because those are already cleared when the loop terminates. The inner for loop seems to be unnecessary when _NOP() does what it indicates (just do nothing while the processor runs) and there is no requirement for a delay between consecutive writes to the IFG1 register. Then that function can be:

      void int_clk()
      {
      BCSCTL1&=~XT2OFF; //open XT oscillator
      BCSCTL2|=SELM1+SELS;//MCLK 8M and SMCLK 1M
      do
      {
      IFG1 &= ~OFIFG; //clean the wrong sign of vibration
      }
      while ((IFG1 & OFIFG) != 0); //If sign is 1,continue to wait
      }

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups