Shop OBEX P1 Docs P2 Docs Learn Events
First SX-28 program driving DC motor with position — Parallax Forums

First SX-28 program driving DC motor with position

Rob v.d. bergRob v.d. berg Posts: 89
edited 2006-10-24 17:49 in General Discussion
Hi,

My first SX28 program (basic+asm) is for control a DC motor,·it runs·to a·position received by an uart (2400).
On the motor there is a gearbox (1:30) and·on the shaft·there·are 12 magnets (N-Z-N-Z...). An Allegro Hall sensor
gives speed and direction back. PWM signal (1960Hz, 0-255) and sensor are made·in the interrupt routine (asm).

Everything works·well. To compensated the clock ticks caused by·the interrupt, I looked at the scope
and the timing for 2400 baud (4.16msec). By changing the·EffectiveHz parameter of FREQ·in 18_750_000
the timing was good and all works well. Interrupt = 500_000 (2usec)
I did not compensated the assembly·Hall sensor part, because it was not needed!!. Can someone explain this?

So there are some·questions left:
-·how·to·calculate the effectivehz parameter
- must i compensated the Hall sensor part as well·for clock ticks
- please any reaction on the·source

Regards
Rob.

Comments

  • BeanBean Posts: 8,129
    edited 2006-10-22 14:14
    Rob,
    Using SXSim, you interrupt takes about 69 cycles. And it runs every 100 cycles.
    So the interrupt is using 69% of the clocks, that leaves 31% of the clocks for the foreground code.
    31% of 50MHz = 15,500,00

    Since your interrupt code doesn't use any of the __PARAMx variables, you would use alot less cycles is you used "INTERRUPT NOPRESERVE 500_000"
    Then your routine would only take 31 cycles of every 100. Leaving 69% for foreground code.
    69% of 50MHz = 34,500,000

    Bean

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheap used 4-digit LED display with driver IC·www.hc4led.com

    Low power SD Data Logger www.sddatalogger.com
    SX-Video Display Modules www.sxvm.com

    "People who are willing to trade their freedom for·security deserve neither and will lose both." Benjamin Franklin
    ·
  • RsadeikaRsadeika Posts: 3,837
    edited 2006-10-22 15:21
    Rob,

    I noticed that you are using a serin command, are you running into any difficulties with this. I know that when I use the pulsin command with an interrupt, I do have problems.

    Ray
  • Rob v.d. bergRob v.d. berg Posts: 89
    edited 2006-10-23 11:07
    Hi Bean ,

    I still use in the first part of the interrupt·the __param1,· is there an alternative for that?
    Regards
    Rob.


    :PWM_output·'total 13 ticks
    · inc ··PWM_Count
    · mov ··__param1,PWM_Count
    · mov···FSR,#PWM_Value
    · cja···ind,__param1,:PWM_High
    · clrb··PWM_out
    · jmp ··:done_PWM
    ································································································································································ totaal
    :PWM_High 'totaal 2
    · setb··PWM_out
    · NOP
    ············································································································································
    :done_PWM


    ·
  • BeanBean Posts: 8,129
    edited 2006-10-23 15:05
    Rob,
    Oops, I didn't see that.
    You would have to change around the code, but maybe something like:

    MOV FSR,#PWM_Value
    MOV W,IND
    BANK $00
    ; Now compare W to PWM_Count

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheap used 4-digit LED display with driver IC·www.hc4led.com

    Low power SD Data Logger www.sddatalogger.com
    SX-Video Display Modules www.sxvm.com

    "People who are willing to trade their freedom for·security deserve neither and will lose both." Benjamin Franklin
    ·
  • Rob v.d. bergRob v.d. berg Posts: 89
    edited 2006-10-23 16:56
    Bean,

    Thanks,· i·shall try to change·it

    Regards

    Rob.
  • Rob v.d. bergRob v.d. berg Posts: 89
    edited 2006-10-24 10:41
    Hi,
    I have change my PWM interrupt with the red items, and my first impression is that it works:
    Thanks
    regards
    Rob

    :PWM_output 
      inc   PWM_Count                
      mov   __param1,PWM_Count      
      mov   FSR,#PWM_Value          
      cja   ind,__param1,:PWM_High 
      clrb  PWM_out                 
      jmp   :done_PWM        
                                                                                                                                                                     
    :PWM_High 'totaal 2
      setb  PWM_out          
      NOP               
                                                                                                                                                 
    :done_PWM
    
    

    :PWM_output 
      inc   PWM_Count                
      mov   [color=red]w[/color],PWM_Count      
      mov   FSR,#PWM_Value          
      cja   ind,[color=red]PWM_Count[/color],:PWM_High 
      clrb  PWM_out                 
      jmp   :done_PWM        
                                                                                                                                                                     
    :PWM_High 
      setb  PWM_out          
      NOP               
                                                                                                                                                 
    :done_PWM
    
    
  • BeanBean Posts: 8,129
    edited 2006-10-24 11:51
    Rob,
    The "MOV W,PWM_Count" is not needed. The very next instruction "MOV FSR,#PWM_Value" will clobber W anyway.
    The code will work ** IF ** PWM_Count happens to be in the global RAM area (that is it's address is <$10).
    If PWM_Count is NOT in the global RAM area, when FSR is changed PWM_Count will not be accessable.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheap used 4-digit LED display with driver IC·www.hc4led.com

    Low power SD Data Logger www.sddatalogger.com
    SX-Video Display Modules www.sxvm.com

    "People who are willing to trade their freedom for·security deserve neither and will lose both." Benjamin Franklin
    ·
  • Rob v.d. bergRob v.d. berg Posts: 89
    edited 2006-10-24 17:49
    Bean,

    Thanks, it's clear.

    Rob.
Sign In or Register to comment.