C Library for mbedWSE project based single board computer for hardware peripherals

Dependents:   Lab7_wse Lab7_wse_student mbed_WSEPRJSBC_EncoderTest mbed_WSEPRJSBC_ADC_test ... more

Weapons and Systems Engineering mbed based single board computer

/media/uploads/jebradshaw/mbedwseprojectsbc_final_small.jpg

Contains C library function listing for hardware peripheral support. Includes functions for +/-10V 12-bit 8-Channel analog-to-digital converter (ADC), 10-bit 2-Channel digital-to-analog converter (DAC), motor control/servo ports, and quadrature encoder ports. Board includes physical Ethernet, USB Host, and CAN bus interfaces. Also includes xbee socket and external I/O pins straight to processor for on-board I2C, SPI, ADC, and DAC.

Schematic

/media/uploads/jebradshaw/mbed_wseprojsbc_schematic_20150211.jpg

Description

This single board computer was designed for the Weapons and Systems Engineering department at the US Naval Academy. The board encompasses a multitude of functional capability for interfacing to a variety of sensors and actuators used in embedded control systems. The board can be powered from a 7-36V DC / AC power supply using a 2.1mm standard barrel connector. The on board bridge rectifier composed of individual diodes allows either polarity on the connector power supply. The four primary external integrated circuits on the board all use the SPI bus for communication. The four primary components are the analog to digital converter, the digital to analog converter, and the two dedicated encoder/counter IC's. The encoder/counter IC's off-load the micro-processor from the burden of external interrupts during high frequency edge detection. The IC's offer 32-bit resolution counting/quadrature decoding, rollover and status information, and index detection for absolute position encoder interfacing. The MAX1270 analog to digital converter (ADC) was chosen for its internal reference and bi-polar voltage input range and scaling program-ability (0-5V, 0-10V, +/-5V, +/-10V). The ADC provides 12-bit resolution at these voltage ranges and are individually channel select-able. Note that careful attention must be used when driving the ADC inputs when in Bipolar operation. An Op-Amp with insufficient current drive capability (milli-amps) will be unable to overcome the internal voltage reference on the input pin due to impedance mismatch/ output current drive capability. This should be checked with an oscilloscope on the input pin if discrepancies between measured voltage values and ADC results exist.

The MAX522 DAC provides 0-5V 10-bit voltage resolution. The range is dependent on the selected 5V board voltage reference source (external 5V switching regulator vs. USB power supply). The board power supply 5V reference can be read by connecting the supply to an external ADC channel and reading the voltage on the 0-10V range.

/media/uploads/jebradshaw/mbed_wseprojsbc_schematic_20140922.pdf - Schematic in PDF

Test Program

/media/uploads/jebradshaw/main_mbedwsesbctest.cpp - Program for testing the library, control the SBC with serial commands

http://developer.mbed.org/users/jebradshaw/code/mbed_WSEPRJSBC_EncoderTest/ - Program for testing the Quadrature Encoder Channels

http://developer.mbed.org/users/jebradshaw/code/mbed_WSEPRJSBC_ADC_test/ - Program to read two channels from the MAX1270 ADC in +/- 10V operation.

http://mbed.org/handbook/Windows-serial-configuration - Link to Serial Driver Installation instructions

Datasheets

/media/uploads/jebradshaw/oki-78sr.pdf - 5V switching regulator

/media/uploads/jebradshaw/ls7366r_w_program.pdf - Encoder IC's

/media/uploads/jebradshaw/max1270.pdf - ADC 8-Channel 12-bit 5V to 10V single/bi-polar input

/media/uploads/jebradshaw/max522.pdf - DAC 2-Channel 0-5V 10-bit

/media/uploads/jebradshaw/mcp2551_can_transceiver.pdf - CAN Transceiver

/media/uploads/jebradshaw/0821-1x1t-36-f.pdf - Ethernet Jack

/media/uploads/jebradshaw/190-009-263r001.pdf - CAN connector

Printed Circuit Board (ExpressPCB)

/media/uploads/jebradshaw/mbedprjv10_20140916.pcb

Partslist (partial)

/media/uploads/jebradshaw/mbedprjv10_partslist.pdf

Revision:
3:103665166deb
Parent:
2:9cddaa7eee11
--- a/mbedWSEsbc.h	Thu Sep 18 15:20:09 2014 +0000
+++ b/mbedWSEsbc.h	Thu Sep 18 18:36:16 2014 +0000
@@ -1,7 +1,12 @@
-// C Library for the WSE-PROJ-SBC
-// J Bradshaw
-// 20140912
+/* C Library for the WSE-PROJ-SBC
+ J Bradshaw
+ 20140912
+ 20140918 J Bradshaw - Found CS mistake in Encoder routines
+    Added comments in Init function, encoder functions
+*/
 
+
+// LS7366 ENCODER IC DEFINITIONS
 //=============================================================================
 // Four commands for the Instruction Register (B7,B6) - LS7366
 //=============================================================================
@@ -25,13 +30,13 @@
 // Set-up hardwired IO
 SPI spi_max1270(p5, p6, p7);
 SPI spi(p5, p6, p7);
-DigitalOut max1270_cs(p8);  //MAX1270 ADC CS
-DigitalOut max522_cs(p11);  //MAX522 DAC CS
+DigitalOut max1270_cs(p8);  //CS for MAX1270 ADC (U3)
+DigitalOut max522_cs(p11);  //CS for MAX522 DAC (U5)
 
-DigitalOut ls7166_cs1(p19);    //CS for LS7366
-DigitalOut ls7166_cs2(p20);    //CS for LS7366
+DigitalOut ls7166_cs1(p19); //CS for LS7366-1 (U8)
+DigitalOut ls7166_cs2(p20); //CS for LS7366-2 (U9)
 
-DigitalOut mot1_ph1(p21);
+DigitalOut mot1_ph1(p21);   //
 DigitalOut mot1_ph2(p22);
 PwmOut mot_en1(p23);
 
@@ -228,6 +233,7 @@
     }    
     wait_us(1);
     LS7366_cmd(WR,MDR0);// Write to the MDR0 register
+    wait_us(1);
     spi.write(0x03); // X4 quadrature count mode
     if(chan_num!=2){
         ls7166_cs1 = 1;    
@@ -237,84 +243,83 @@
     }
 }
 
-void LS7366_reset_counter(int chan_num){
+void LS7366_reset_counter(int chan_num){    
+    spi.format(8, 0);           // set up SPI for 8 data bits, mode 0
+    spi.frequency(2000000);     // 2MHz SPI clock
     
-    spi.format(8, 0);
-    spi.frequency(2000000);
-    
-    if(chan_num!=2){
+    if(chan_num!=2){            // activate chip select
         ls7166_cs1 = 0;    
     }
     else{
         ls7166_cs2 = 0;    
     }    
-    wait_us(1);
-    LS7366_cmd(CLR,CNTR);//Clear the counter register
-    if(chan_num!=2){
+    wait_us(1);                 // short delay
+    LS7366_cmd(CLR,CNTR);       // Clear the counter register
+    if(chan_num!=2){            // de-activate chip select
         ls7166_cs1 = 1;    
     }            
     else{
-        ls7166_cs2 = 1;    
+        ls7166_cs2 = 1;
     }
-    wait_us(1);
+    wait_us(1);                 // short delay
     
-    if(chan_num!=2){
+    if(chan_num!=2){            // activate chip select
         ls7166_cs1 = 0;    
     }            
     else{
         ls7166_cs2 = 0;    
     }        
-    wait_us(1);
-    LS7366_cmd(LOAD,CNTR);//
-    if(chan_num!=2){
+    wait_us(1);                 // short delay
+    LS7366_cmd(LOAD,CNTR);      // load counter reg
+    if(chan_num!=2){            // de-activate chip select
         ls7166_cs1 = 1;    
     }            
     else{
-        ls7166_cs1 = 1;    
+        ls7166_cs2 = 1;    
     }
 }
 
-void LS7366_write_DTR(int chan_num,long enc_value){
-    union bytes
+void LS7366_write_DTR(int chan_num, long enc_value){
+    union bytes                // Union to speed up byte writes
     {
         char byte_enc[4];
         long long_enc;
     }counter;
     
-    spi.format(8, 0);
-    spi.frequency(2000000);
+    spi.format(8, 0);           // set up SPI for 8 data bits, mode 0
+    spi.frequency(2000000);     // 2MHz SPI clock
     
-    counter.long_enc = enc_value;
+    counter.long_enc = enc_value; // pass enc_value to Union
     
-    if(chan_num!=2){
+    if(chan_num!=2){              // activate chip select
         ls7166_cs1 = 0;    
     }            
     else{
         ls7166_cs2 = 0;    
     }   
-    wait_us(1);
-    LS7366_cmd(WR,DTR);//
-    spi.write(counter.byte_enc[3]);
+    wait_us(1);                 // short delay
+    LS7366_cmd(WR,DTR);         // Write to the Data Transfer Register
+    spi.write(counter.byte_enc[3]); // Write the 32-bit encoder value
     spi.write(counter.byte_enc[2]);
     spi.write(counter.byte_enc[1]);
     spi.write(counter.byte_enc[0]);
-    if(chan_num!=2){
+    if(chan_num!=2){            // de-activate the chip select
         ls7166_cs1 = 1;    
     }            
     else{
         ls7166_cs2 = 1;    
     }     
     
-    wait_us(1);
-    if(chan_num!=2){
+    wait_us(1);                 // short delay
+    if(chan_num!=2){            // activate chip select
         ls7166_cs1 = 0;    
     }            
     else{
         ls7166_cs2 = 0;    
     }
-    wait_us(1);
-    LS7366_cmd(LOAD,CNTR);//
-    if(chan_num!=2){
+    wait_us(1);                 // short delay
+    LS7366_cmd(LOAD,CNTR);      // load command to the counter register from DTR
+    if(chan_num!=2){            // de-activate chip select
         ls7166_cs1 = 1;    
     }            
     else{
@@ -342,24 +347,22 @@
 }
 
 void mbedWSEsbcInit(unsigned long pcbaud){
-    led1 = 0;
+    led1 = 0;           //Initialize all LEDs as off
     led2 = 0;
     led3 = 0;
-    led4 = 0;         
-    max1270_cs = 1;
+    led4 = 0;
+    max1270_cs = 1;     //Initialize all chip selects as off
     max522_cs = 1;
     ls7166_cs1 = 1;
     ls7166_cs2 = 1;
     
     wait(.2);   //delay at beginning for voltage settle purposes
     
-    mot_en1.period_us(50);   
-    
-    pc.baud(pcbaud);        //Set up serial port baud rate
-    pc.printf("\r\n");      //Initialize with a Carriage Return and Newline
+    mot_en1.period_us(50);   //20KHz for DC motor control PWM
+    pc.baud(pcbaud); //Set up serial port baud rate
+    pc.printf("\r\n");
     xbee.baud(9600);
     
-    spi.frequency(5000000);
     LS7366_reset_counter(1);
     LS7366_quad_mode_x4(1);       
     LS7366_write_DTR(1,0);