please help me...

Status
Not open for further replies.

indie

New Member
hi there...i have some problem with this code, after i measured the pulsewidth on my oscilloscope i got 1 ms for min(1 step) and 2.4 ms for max(255 step), but my motor only move 140 degree(it should be 180 degree), so i need to changed the max pulse from D'2000' to D'3000'

#define MIN_PULSE D'800'; in usec
#define MAX_PULSE D'3000'; in usec
#define PULSE_RANGE (MAX_PULSE - MIN_PULSE)

, but i didn't see the change of max pulsewidth on my oscilloscope, so what's wrong...please help...

nb:this code was download from jaaphavinga page.

regards
indie


; timer runs at 1Mhz, for 4MHz PIC version, baudrate = 9600
; timer runs at 5Mhz, for 20MHz PIC version, baudrate = 38400
; define HIGH_SPEED if running on 20 Mhz
#define HIGH_SPEED


ifdef HIGH_SPEED
#define TIMER_PERIOD D'26' ; is defined by baudrate, resolution and the max. number of instructions per interrupt.
#define TIMER_PERIOD_SCALE 5 ; real_timer_period = TIMER_PERIOD/TIMER_PERIOD_SCALE usec
#define BAUDRATE D'38400'
else
#define TIMER_PERIOD D'26' ; is defined by baudrate, resolution and the max. number of instructions per interrupt.
#define TIMER_PERIOD_SCALE 1 ; real_timer_period = TIMER_PERIOD/TIMER_PERIOD_SCALE usec
#define BAUDRATE D'9600'
endif

; pulse width modulation for rc-servo motors
#define MIN_PULSE D'800'; in usec
#define MAX_PULSE D'2000'; in usec
#define PULSE_RANGE (MAX_PULSE - MIN_PULSE)

#define INIT_PULSE_COUNT (MIN_PULSE*TIMER_PERIOD_SCALE/TIMER_PERIOD)
#define END_OF_PERIOD_COUNT (PULSE_RANGE*TIMER_PERIOD_SCALE/TIMER_PERIOD)


#define TIMER_CORRECTION_VALUE D'6'

#define TIMERCOUNT (0xff-TIMER_PERIOD+TIMER_CORRECTION_VALUE)
#define PWD_REGISTERS D'8'
#define PWD_REGISTERS_MASK 0x80


; serial interface
; baudrate is 9600/38400
; bit-duration of serial is 1/9600 = 104 usec
; bit-duration of serial is 1/38400 = 26 usec
; oversampling of serial signal should be at least 2 times , higher sampling rate is more reliable
; 1 bit-duration is n timer ticks: n = baudrate / (real_timer_period)
; correct for 2 extra substages!
#define SER_BIT_TIMER ((D'1000000'*TIMER_PERIOD_SCALE)/(BAUDRATE*TIMER_PERIOD))
#define SER_BIT_TICKS SER_BIT_TIMER-D'2'

; The first delay after detection of the startbit is 1.5* de bit-duration
; correct for 2 extra substages!
#define SER_FIRST_BIT_TICKS (SER_BIT_TIMER * D'3') / D'2' - D'2'

#define SER_BYTE_SIZE D'8'

#define SER_RX_BIT 0x04 ; A4 is receive bit
 
Check if the data type (8 bit, 16 bit, 32 bit) in #define match with the variables declared in the program.

For example
#define test 0xffff

char ch=test


// ch will be 0xff instead of 0xffff
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…