Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F92310646
pindefs.c
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Tue, Nov 19, 07:31
Size
2 KB
Mime Type
text/x-c
Expires
Thu, Nov 21, 07:31 (2 d)
Engine
blob
Format
Raw Data
Handle
22417028
Attached To
R6619 Oncilla Motordriver Firmware
pindefs.c
View Options
#include "p33FJ128MC804.h"
#include "pindefs.h"
#include "motordriver.h"
void pin_init()
{
// pin default configuration
ADPCFG = 0xffff; // Set all Analog ports as Digital I/O
// TRISA = 0xffff; // Everything is input
// TRISB = 0xffff; // Everything is input
mdv_master_reset = gpio_create(GPIO_PORT_B,GPIO_PIN_15,GPIO_OUTPUT);
// set motor 1 control pins to output
// TRISCbits.TRISC3 = 0; // MODE1 is output
// TRISBbits.TRISB11 = 0; // DIR1 is output
// TRISBbits.TRISB14 = 0; // TRQ1 is output
// TRISBbits.TRISB10 = 0; // SPD1 is output
// TRISAbits.TRISA4 = 0; // COAST1 is output
// TRISAbits.TRISA3 = 0; // BREAK1 is output
TRISAbits.TRISA0 = 1; // CSOUT1 is input (analog input)
// set motor 2 control pins to output
TRISAbits.TRISA9 = 0; // MODE2 is output
TRISAbits.TRISA7 = 0; // DIR2 is output
TRISCbits.TRISC6 = 0; // TRQ2 is output
TRISBbits.TRISB12 = 0; // SPD2 is output
TRISAbits.TRISA8 = 0; // COAST2 is output
TRISAbits.TRISA10 = 0; // BREAK2 is output
TRISAbits.TRISA1 = 1; // CSOUT2 is input (analog input)
// set motors reset pin to output
mdv_master_reset_enable(); // set the motor drivers in reset-state
// set motors error feedback pin to input
TRISBbits.TRISB13 = 1; // FF2 is input
// quadrature encoder inputs
TRISCbits.TRISC4 = 1; // QEI1_A is input
TRISCbits.TRISC5 = 1; // QEI1_B is input
TRISBbits.TRISB6 = 1; // QEI2_A is input
TRISBbits.TRISB7 = 1; // QEI2_B is input
// RC servo pins
TRISBbits.TRISB0 = 0; // SERVO1 is output
TRISBbits.TRISB1 = 0; // SERVO2 is output
// SPI 1 interface: absolute magnetic encoders
TRISBbits.TRISB8 = 0; // SPI1_CLK is output
TRISBbits.TRISB4 = 0; // SPI1_CS is output
TRISBbits.TRISB9 = 1; // SPI1_DI is input
// SPI 2 interface: force/torque sensors
TRISCbits.TRISC7 = 0; // SPI2_CLK is output
TRISBbits.TRISB5 = 0; // SPI2_CS is output
TRISCbits.TRISC8 = 1; // SPI2_DI is input
TRISCbits.TRISC9 = 0; // SPI2_DO is output
TRISBbits.TRISB2 = 0; // SPI2_SYNC is output
// General Purpose led
TRISBbits.TRISB3 = 0; // LED is output
// RS485 interface pins
TRISCbits.TRISC2 = 0; // RS485 enable pin is output
TRISCbits.TRISC1 = 0; // RS485 transmit pin is output
TRISCbits.TRISC0 = 1; // RS485 receive pin is input
// PORT_RS485_RECEIVER_DISABLE;
//UART1 connects to RS485
// RPINR18 = 0b0001111100000000; //tie U1CTS to Vss, tie UART1RX to RP0
// RPOR0 = 0b0000001100000000; //tie UART1TX to RP1
_U1RXR = 16; // Map UART1 RX to port RP16
_RP17R = 3; // Map UART1 TX to RP17
//SPI 1 configuration. It may already be configured, but better to repeat
_SDI1R = 9; // Map SPI 1 DI to RP 9
_RP8R = 8; // Map RP8 to SPI 1 Clock Output
//SPI 2 configuration, it may already be configured, but better to repeat
_SDI2R = 24; //Map SPI 2 DI to RP24
_RP23R = 11; //Map RP23 to SPI 2 Clock Output
_RP25R = 10; //Map RP25 to SPI2 DO
}
Event Timeline
Log In to Comment