First SX-28 program driving DC motor with position
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.
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
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
·
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
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
·
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
·
Thanks,· i·shall try to change·it
Regards
Rob.
I have change my PWM interrupt with the red items, and my first impression is that it works:
Thanks
regards
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
·
Thanks, it's clear.
Rob.