Gordo
100 kW
My goodness Arlo, use a socket on that poor IC. I am surprised you haven't cook it? I have a couple of breadboards like in Lebowski's pictures and some sockets you can have.
Yup surface mount! I will look at making the next version cleaner but this is the way it is for now!Gordo said:My goodness Arlo, use a socket on that poor IC. I am surprised you haven't cook it? I have a couple of breadboards like in Lebowski's pictures and some sockets you can have.
Arlo1 said:#1 Is there a simple list for microchip of the C code? Or what files do I look for in my computer. List specific to dspic30f3010?
#2 How do I get a throttle to flash the LED at different speeds?
#3 How do I work on the rs232? I have spent over 40hours on my computer earning this and I'm not afraid to spend 1000s of hours more but every few days I want to see some progress.
I'm not asking to be spoon fed info but its just so hard to find what I want and everything is so u n organized!
void busyLoop(int loops) {
volatile int i;
for(i = 0; i < loops; i++) {}
}
void main(void) {
unsigned int val;
setupAD();
setupLED();
while(1) {
ledOn();
val = readAD();
busyLoop(val);
ledOf();
busyLoop(val);
}
}
;this routine drives the motor when the time per e-revolution
;is too low. The motor will be driven by this routine until
;e-rpm rises above a certain limit and this is maintained for
;at least 7 e-revolution. The routine will then clear the drive_1
;bit, initialise for drive_2 and set the drive_2 bit.
drive_1:
;--------------------------------------- get current position and store in phi
clr w0
btsc PORTD, #0
bset w0, #1
btsc PORTD, #1
bset w0, #2
btsc PORTB, #4
bset w0, #3 ;compute address in hall_drive_pos
mov #hall_drive_pos, w1
add w0, w1, w1
mov [w1], w2 ;get direct_drive position
mov w2, phi ;and use for commutation
;--------------------------------------- compare new and old position pointer, update which halls flipped
mov phi_pointer, w1 ;get old position pointer
mov w0, phi_pointer
;invert phi_pointer bits
com w0, w0
;perform and with phi_pointer_prev -> all resulting '1's now indicate falling edge
and w0, w1, w0
;'or' them with halls_flipped
ior halls_flipped
;--------------------------------------- are we too slow ? -> clear fast_rotation_counter, end
;TMR2 overflow indicates 'too slow'
btss IFS0, #6
bra dr1_fast_enough
bclr IFS0, #6
clr fast_rotation_count
clr halls_flipped
bra dr1_end
;--------------------------------------- did all halls flip ? if not, end
dr1_fast_enough:
mov #0x0E, w0
cp halls_flipped
bra nz, dr1_end
;--------------------------------------- reset halls_flipped and timer for next time measurement
clr halls_flipped
clr TMR2
bclr IFS0, #6
;--------------------------------------- increment fast_rotation_counter
inc fast_rotation_count
;--------------------------------------- did fast_rotation_counter reach limit ? if not: end
mov #7, w0
cp fast_rotation_count
bra ltu, dr1_end
;--------------------------------------- if yes: switch to drive_2
call initialise_drive_2
;--------------------------------------- end
dr1_end:
return
;w0: 0-255: angle (0-359 degrees)
;based on: sin(a+b) = sin(a) * cos(b) + cos(a) * sin(b)
; cos(a+b) = cos(a) * cos(b) - sin(a) * sin(b)
sine_cosine:
;save registers
push w0
push w1
push w2
push w3
push w9
push w10 ;sin(a+b) scratchpad
push w11 ;cos(a+b) scratchpad
push w12 ;points to sin(b) array
push w13 ;points to cos(b) array
;initialise variables
mov w0, w9
mov #tblpage(sincos_b), w1
mov w1, TBLPAG
mov #tbloffset(sincos_b), w12
mov #tbloffset(sincos_b)+16, w13
mov #0x7FFF, w1
mov w1, cos ;cos (a) = 1 (at start when a=0)
clr sin ;sin (a) = 0 (at start when a=0)
do #7, sc_do_end ;process all 8 bits in w0
;bit 7 = 0 ? skip multiplication
btss w9, #7
bra sc_skip_mult
;multiply variables with constant if bit is set
;w10 = sin(a) * cos(b)
tblrdl [w13], w1 ;cos(b)
mov sin, w0 ;sin(a)
mul.ss w0, w1, w2 ;32768*x 32768*y = 65536*w3 + w2 = 32768 * ans -> ans = 2*w3
rlc w2, w2 ;answer from mul.ss must be multiplied by 2 to stay in [-1..1]
rlc w3, w10 ;transfer msb of w2 via carry to lsb w10
;w10 += cos(a) * sin(b)
tblrdl [w12], w1 ;sin(b)
mov cos, w0 ;cos(a)
mul.ss w0, w1, w2
rlc w2, w2
rlc w3, w3
add w10, w3, w10
;w11 = cos(a) * cos(b)
tblrdl [w13], w1 ;cos(b)
mov cos, w0 ;cos(a)
mul.ss w0, w1, w2
rlc w2, w2
rlc w3, w11
;w11 -= sin(a) * sin(b)
tblrdl [w12], w1 ;sin(b)
mov sin, w0 ;sin(a)
mul.ss w0, w1, w2
rlc w2, w2
rlc w3, w3
sub w11, w3, w11
mov w10, sin ;sin(a)_new := sin(a+b)
mov w11, cos ;cos(a)_new := cos(a+b)
sc_skip_mult:
;rotate w9 for next bit
sl w9, #1, w9
;move pointer to next position in contants array
inc2 w12, w12
sc_do_end:
inc2 w13, w13
;restore registers
pop w13
pop w12
pop w11
pop w10
pop w9
pop w3
pop w2
pop w1
pop w0
return
.align 32
sincos_b: ;first sin(b)
.fixed 0.0 ;sin(360/2)
.fixed 0.99996 ;sin(360/4)
.fixed 0.707107 ;sin(360/8)
.fixed 0.382683 ;sin(360/16)
.fixed 0.195090 ;sin(360/32)
.fixed 0.098017 ;sin(360/64)
.fixed 0.049068 ;sin(360/128)
.fixed 0.024541 ;sin(360/256)
;then cos(b), 8 (*2) addresses later
.fixed -1.0 ;cos(360/2)
.fixed 0.0 ;cos(360/4)
.fixed 0.707107 ;cos(360/8)
.fixed 0.923880 ;cos(360/16)
.fixed 0.980785 ;cos(360/32)
.fixed 0.995185 ;cos(360/64)
.fixed 0.998795 ;cos(360/128)
.fixed 0.999699 ;cos(360/256)
/*********************************************************************
void InitUART(void)
UART Initialization 8N1, 9600 baud, char rcv int, tx int when 1 buf free
*********************************************************************/
void InitUART(void) //U1TXREG U1RXREG
{
UART1_ATX_TRIS = 0; // set Alternate Tx TRIS to output
UART1_ARX_TRIS = 1; // set Alternate Rx TRIS to input
U1MODEbits.ALTIO = 1; // Use ALT IO Pins 11-Tx 12-Rx
U1MODEbits.PDSEL = 0x00; // 8 bits No parity
U1MODEbits.STSEL = 0; // 1 stop bit
U1STA = 0; // interrupt when char rcvd & when xmit buf free
U1BRG = ((FCY/9600)/16) - 1; // UART baud rate divisor bits 9600 baud
// U1BRG=64=(Fcy/(baudrate*16)) - 1
U1MODEbits.UARTEN = 1; // UART enabled
U1STAbits.UTXEN = 1; // Transmitter enabled
IEC0bits.U1RXIE = 1; // enable serial receive interrupts
// IEC0bits.U1TXIE = 1; // enable serial transmit interrupts
}
pelle242 said:especially if you look into more advanced but fundamentally flawed things like FOC.
Lebowski said:pelle242 said:especially if you look into more advanced but fundamentally flawed things like FOC.
fixed that for you![]()
Lebowski said:I've coded my whole motor controller in Assembly. I'm starting to wonder how usefull C is for programming
a microcontroller.
Ok, I understand C is very portable but, how portable is it really when all the registers you need to
write are microcontroller specific ?
How much advantage does C give you for performing computations ? In 30F Assembly practically everything is
16 integer, isn't this the same for the (free) C compiler ? Or does that allow floating point ? Only fixed point ?
Another advantage to C would be build in sine/cosine functions, does it have that ? These would be true advantages.
Im using a serial/usb converter so does this meen the converter is stepping up the 5v from the usb to 12v?pelle242 said:For rs232 a zero is -12V and a one is +12V, to make it less sensitive to interferance. Most MCUs use 0V for zero and Vcc (5 or 3.3v) for one. Something is needed to handle that. A very popular chip is the MAX232 or MAX233. If you hook it directly to your it wont work and you might fry your MCU.
Something like this is handy: http://www.ebay.com/sch/?_kw=USB%20ttl&_clu=2&_fcid=192&_localstpos=&_stpos=&gbr=1
It can be hooked directly to the MCU.
It can also be used to program infineon controllers.
If you have a mobile phone data cable they can often be moded to do the same thing.