PWM for HSC12 microntroller

Status
Not open for further replies.

windozeuser

Member
I have on my hands a dragon board from Wytec, that uses the HSC12 microntroller. It has a 24 Mhz bus, because the Debug12 runs a PLL loader to speed up the bus.

I need someone that is knowledgeable with HSC12 and controlling a servo with the PWM module of the HSC12.

I cannot use PORT T timer because it's going to be used by another function. So I will have to use the PWM that is outputted on PWM4 PORT P Pin 4

I have this code:

Code:
dotit

        MOVB #$04, PWMPRCLK	 ;ClockA=Fbus/2**4=24MHz/16=1.5MHz
	      MOVB #125, PWMSCLA	 ;ClockSA=1.5MHz/2x125=1.5Mhz/250=6000Hz
	      MOVB #$10, PWMCLK	   ;Use clockSA for chan 4 PWM
	      MOVB #$10,PWMPOL		 ;High then low for polarity
	      MOVB #$0,PWMCAE		   ;Left aligned
	      MOVB #$0, PWMCTL	   ;Co       n               c       a       t
	      MOVB #120, PWMPER4	 ;PWM_Freq=ClockSA/100=6000Hz/100=50 Hz. 

	      MOVB #0,PWMCNT4		   ;Start the counter with zero
	      BSET PWME,%00010000  ;Enable chan 4 PWM


servo

	MOVB #6, PWMDTY4		 ; need value here to make duty cycle

        bra servo

I dont understand how to calculate duty cycle, what to put in PWMDTY4, to get the duty cycle for the servo

using a futabo servo, 1.3ms CCW, 1.5ms (center), and 1.7ms (Cw) at 50Hz

Any help would be appreciated!
 
I fixed my code, and I verified with an oscilloscope that I do indeed have a 20mS period, and the pulse is 1.5mS wide.

However, the servo is not responding correctly, I tried tying the grouns together and it had weird behavior.
 
tying grounds? which ones ? a servo only has 3 wire, vcc gnd dat

wat type of behavior>?

when pulse is @ 1.5ms, servo goes to center right?>
 
The servo ground and Microcontroller ground.

The servo keeps rotating far from center.
I checked on O-Scope have a 20mS period, and the pulse is 1.5mS wide exactly.

The PWM on the microcontroller has WAIT AND FREEZE options what are those for? maybe that is needed to be turned on?

PSWAI — PWM Stops in Wait Mode
Enabling this bit allows for lower power consumption in Wait Mode by disabling the input clock to
the prescaler.
1 = Stop the input clock to the prescaler whenever the MCU is in Wait Mode.
0 = Allow the clock to the prescaler to continue while in wait mode.
 
idk, but i do kno if its rotating to a direction it is working, try turning pulse up to 1.8ms, test,,, then turn to 1.2ms, you may like results,,,
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…