Presentation is loading. Please wait.

Presentation is loading. Please wait.

System Software Design Dan Sweet May 6 th, 2008 Western Washington University Bicycle Power Meter.

Similar presentations


Presentation on theme: "System Software Design Dan Sweet May 6 th, 2008 Western Washington University Bicycle Power Meter."— Presentation transcript:

1 System Software Design Dan Sweet May 6 th, 2008 Western Washington University Bicycle Power Meter

2 General System Design Freescale MC13213 8-bit MCU Bus Frequency: 8 MHz (from external xtal) Memory Requirements: MCU1 & 2: ~5000 bytes ROM for SMAC MCU1 & 2: ~5000 bytes ROM for SMAC MCU1: ~4000 bytes ROM for uC/OS MCU1: ~4000 bytes ROM for uC/OS MCU1: ~2000 bytes of RAM total MCU1: ~2000 bytes of RAM total MCU2: ~1000 bytes of ROM for Time-Slice MCU2: ~1000 bytes of ROM for Time-Slice MCU2: ~1000 bytes of RAM total MCU2: ~1000 bytes of RAM total MCU1 total: ~9000 ROM, ~2000 RAM MCU1 total: ~9000 ROM, ~2000 RAM MCU2 total: ~6000 ROM, ~1000 RAM MCU2 total: ~6000 ROM, ~1000 RAM

3 Kernal Choice MCU 1: uC/OS Tick period of 1 ms Tick period of 1 ms 4 Tasks 4 Tasks MCU 2: Time Slice Routine Slice Period of ~.25 seconds Slice Period of ~.25 seconds 3 main slice functions 3 main slice functions

4 MCU 1 uC/OS Design Task 1: StartTask Highest priority (4) Highest priority (4) Initial task which begins other tasks Initial task which begins other tasks Only runs once before termination Only runs once before termination Task 2: RxIn Receives data via wireless transceiver Receives data via wireless transceiver Controls all SMAC functionality & interfaces with the SMAC modules Controls all SMAC functionality & interfaces with the SMAC modules Will run sporadically (whenever an incoming message is received) Will run sporadically (whenever an incoming message is received) Next highest priority (5) Next highest priority (5)

5 MCU 1 Task 2: RxIn Task 2: RxIn Receives data via wireless transceiver Receives data via wireless transceiver Controls all SMAC functionality & interfaces with the SMAC modules Controls all SMAC functionality & interfaces with the SMAC modules Will run sporadically (whenever an incoming message is received about every.25 seconds) Will run sporadically (whenever an incoming message is received about every.25 seconds) Execution Time: ~ < 10 ms Execution Time: ~ < 10 ms Next highest priority (5) Next highest priority (5) SMAC Functions Used: MLMESetMC13192ClockRate(0); MLMESetMC13192ClockRate(0); MLMESetChannelRequest(CHANNEL_NUMBER); MLMESetChannelRequest(CHANNEL_NUMBER); MLMEMC13192PAOutputAdjust(OUTPUT_POWER); MLMEMC13192PAOutputAdjust(OUTPUT_POWER); MLMERXEnableRequest(&rx_packet,0); MLMERXEnableRequest(&rx_packet,0); Zero means wait forever with RX ON

6 MCU 1 Task 2: RxIn SMAC Data Members: byte gu8RTxMode; //current mode of radio byte gu8RTxMode; //current mode of radio byte rx_data_buffer[x]; //holds in data byte rx_data_buffer[x]; //holds in data tRxPacket rx_packet; tRxPacket rx_packet; SMAC structure for RX packets rx_packet.u8DataLength = 0; //length of data rx_packet.u8DataLength = 0; //length of data rx_packet.pu8Data = &rx_data_buffer[0]; rx_packet.pu8Data = &rx_data_buffer[0]; rx_packet.u8MaxDataLength = 128; rx_packet.u8MaxDataLength = 128; rx_packet.u8Status = 0; rx_packet.u8Status = 0;

7 MCU 1 uC/OS Design (cont.) Task 3: UpdateData Will perform necessary manipulation on incoming data before updating LCD Will perform necessary manipulation on incoming data before updating LCD Must receive access to the LCD via a mutex key (Cal_Interface must use LCD too) Must receive access to the LCD via a mutex key (Cal_Interface must use LCD too) Third highest priority (6) Third highest priority (6) Period: ~.5 Seconds Period: ~.5 Seconds Execution Time: <25 ms Execution Time: <25 ms

8 MCU 1 Task 4: Cal_Interface() Cal_Interface() controls the user interface to calibrate the strain coefficients It takes control of LCD and incoming data (uses LCD mutex and data mutex). Informs user to place given weight on pedal, takes reading, process is repeated for other pedal No data needs to be sent to the pedal unit, which simplifies communication. Period: Sporadic (whenever user presses set-up button) Execution Time: (excluding waiting for user input) ~2 seconds per pedal = 4 seconds

9 MCU 1 Interrupts OC0Isr: (may be removed) Simple Output Compare Timer to control time slice delay and any other misc. delays Simple Output Compare Timer to control time slice delay and any other misc. delays Execution Time <1 us Execution Time <1 us IRQIsr (From SMAC protocol): Routine to handle incoming messages Routine to handle incoming messages Created as part of SMAC requirements Created as part of SMAC requirements Execution Time <1 ms Execution Time <1 ms Vscirx (From SMAC protocol): Interfaces the MCU to transceiver via SCI Interfaces the MCU to transceiver via SCI Execution Time < 1 us Execution Time < 1 us IRQTimer1 (From SMAC protocol): Separate output compare timer for the SMAC protocol Separate output compare timer for the SMAC protocol Execution Time <2 us Execution Time <2 us OSTickIsr: (From uC/OS) – OS Tick Timer OSCtxSw: (From uC/OS) – OS Context Switch Interrupt KBIIsr: Controls interrupt from button Controls interrupt from button Will generate interrupt when button is pressed Will generate interrupt when button is pressed Execution Time < 2 us Execution Time < 2 us

10 MCU1 Data Flow Diagram RxIn, UpdateData, & Cal_Interface must have access to the incoming Rx data. Normally, RxIn & Update data swap control over this data (during normal operation) When Calibration is started, UpdateData is suspended so the Cal_Interface can output data to LCD and perform calculations on incoming data Cal_Interface changes Cal_Coefficient which is used by UpdateData to calculate torque

11 MCU 1 CPU Load RxIn execution time: ~10 ms every ~.25 s UpdateData execution time: ~25 ms /.25 s Calibrate Routine Does not run at same time, so is not included in main CPU load Normal Operation Mode CPU load: L = (10 ms + 25 ms)/.25 s = 14% CPU Load* L = (10 ms + 25 ms)/.25 s = 14% CPU Load* *Excludes Interrupts

12 MCU 2 Time Slice Design Three Operations of Time Slice Collect data from Accelerometer (A/D) Collect data from Accelerometer (A/D) Collect data from Strain Gauges (A/D) Collect data from Strain Gauges (A/D) Send out data via SMAC wireless Tx Send out data via SMAC wireless Tx *These Items may be combined into a single inline routine

13 MCU 2 Interrupts OC0Isr: Simple Output Compare Timer to control time slice delay and any other misc. delays Simple Output Compare Timer to control time slice delay and any other misc. delays Execution Time <1 us Execution Time <1 us IRQIsr (From SMAC protocol): Routine to handle incoming messages Routine to handle incoming messages Created as part of SMAC requirements Created as part of SMAC requirements Execution Time <1 ms Execution Time <1 ms IRQTimer1 (From SMAC protocol): Separate output compare timer for the SMAC protocol Separate output compare timer for the SMAC protocol Execution Time <2 us Execution Time <2 us Vscitx (From SMAC protocol): Interfaces the MCU to transceiver via SCI Interfaces the MCU to transceiver via SCI Execution Time < 1 us Execution Time < 1 us

14 MCU 2: Sample Accelerometer Slice For each axis sampled: An initial calibration routine run once (not every slice) An initial calibration routine run once (not every slice) Take a set of samples (16-64) and average them, acts as LPF (8-bit samples) Take a set of samples (16-64) and average them, acts as LPF (8-bit samples) Subtract calibration value Subtract calibration value Apply a discrimination window to filter noise Apply a discrimination window to filter noise Integrate to get velocity Integrate to get velocity Do movement end check Do movement end check Save new value in old value spot Save new value in old value spot

15 Integration on set of samples INT32U velocityx[2], accelerationx[2]; velocityx[0],acceleration[0] = last value velocityx[1],acceleration[1] = new value velocityx[1]= velocityx[0]+ accelerationx[0]+ ((accelerationx[1] -accelerationx[0])>>1);

16 MCU 2: Sample Strain values Sampled in 10-bit mode (3.1 mV per step) Two separate channels sampled Each channel sampled several times and averaged to reduce noise Raw data stored in global variable to be sent to MCU1

17 MCU 2: Tx Slice Data members used: tTxPacket tx_packet;//SMAC structure for TX packets tTxPacket tx_packet;//SMAC structure for TX packets INT8U tx_data_buffer[x];//Data buffer to hold TX data INT8U tx_data_buffer[x];//Data buffer to hold TX data tx_packet.u8DataLength;//Length of data tx_packet.u8DataLength;//Length of data tx_packet.pu8Data = &tx_data_buffer[0];//Load the address of our txbuffer into tx structure. tx_packet.pu8Data = &tx_data_buffer[0];//Load the address of our txbuffer into tx structure.

18 MCU 2: Tx Slice Major SMAC Functions used: MLMESetChannelRequest(CH_NUM); MLMESetChannelRequest(CH_NUM); Sets channel number MLMEMC13192PAOutputAdjust(OUT_POW); MLMEMC13192PAOutputAdjust(OUT_POW); Sets output power of Tx MCPSDataRequest(&tx_packet); MCPSDataRequest(&tx_packet); Transmits Packet, blocks until sent out.

19 MCU 2 Data Flow Diagram Flow of data in MCU 2 is very simple, since it is a time slice routine No two slices can access a data member simultaneously, so there is no conflicting access to data Major data will be global to simplify the access amongst different functions Operation is the same whether MCU 1 is in normal operation or in calibration mode

20 MCU 2 CPU Load Slice Period: ~.25 seconds A/D speed: Bus clock = 8 MHz Bus clock = 8 MHz A/D pre-scaler = 4 A/D pre-scaler = 4 A/D rate = 2 MHz A/D rate = 2 MHz A/D conversion time (10-bit @ 2 MHz) = 14 us A/D conversion time (10-bit @ 2 MHz) = 14 us Accelerometer A/D slice: 16 samples for each average = 224 us 16 samples for each average = 224 us Total Time: < 500 us Total Time: < 500 us Strain Gauge A/D slice: 8 samples per average * 2 = 224 us 8 samples per average * 2 = 224 us Total Time: < 400 us Total Time: < 400 us Tx slice: Est. Total Time: < 5 ms Est. Total Time: < 5 ms CPU Load: L=(500 us + 400 us + 5 ms)/.25 s* = 2.5% CPU Load (Leaves lots of room for more averaged samples) L=(500 us + 400 us + 5 ms)/.25 s* = 2.5% CPU Load (Leaves lots of room for more averaged samples) *Excludes Interrupts *Excludes Interrupts

21 Module List (1 of 4) Module NameTasksPublic Functions & Data MCU1.cStart Task RxIn Update Data tRxPacket rx_packet rx_data_buffer[x] gu8RTxMode gu8Channel MCU2.c-main(); GetAccel(); GetStrain(); SendData(); WaitForSlice(); gu8RTxMode; UINT8 gu8Channel; tTxPacket tx_packet; byte tx_data_buffer[x]; Start08.c- mcu_hw_config.c Has initialization and clock routines -GPIOInit() UseExternalClock() UseMcuClock() MCUInit() UINT8 IRQPinLow()

22 Module List (2 of 4) simple_mac.c -The highest layer of SMAC code -UINT8 MCPSDataRequest(tTxPacket); UINT8 MLMERXEnableRequest(tRxPacket, Timeout); UINT8 MLMERXDisableRequest(void); UINT8 MLMEHibernateRequest(); UINT8 MLMEDozeRequest(Timeout); UINT8 MLMEWakeRequest(); UINT8 MLMESetChannelRequest(u8Channel); UINT8 MLMESetMC13192ClockRate(u8Freq); UINT8 MLMESetMC13192TmrPrescale (u8Freq); UINT8 MLMEMC13192XtalAdjust(u8reqValue); UINT8 MLMEEnergyDetect(); UINT8 MLMEMC13192SoftReset(); UINT8 MLMELinkQuality (); UINT8 MLMEMC13192FEGainAdjust(u8GainValue); UINT8 MLMEMC13192PAOutputAdjust(u8PaValue); UINT8 MLMEGetRficVersion(); void MLMETestMode (tTxPacket, u8mode); UINT8 MLMEScanRequest(flags, *pu8ChannelScan); drivers.c Controls the interface between MCU & radio unit via SPI. Also has IRQ interrupt (lowest layer of SMAC code) -gu8IRQValue void SPIDrvWrite(u8Addr, u16Content); UINT16 SPIDrvRead(u8Addr); UINT16 SPIDrvRead2(u8Addr); void RAMDrvWriteTx(tTxPacket); UINT8 RAMDrvReadRx(tRxPacket); IRQIsr();

23 Module List (3 of 4) simple_phy.c Houses the PHY layer of the SMAC protocol. This is the second highest layer of the SMAC code. -UINT8 PDDataRequest(tTxPacket *); void PDDataIndication(); UINT8 PLMEHibernateRequest(); UINT8 PLMEDozeRequest(u32Timeout); UINT8 PLMEWakeRequest(); UINT8 PLMESetChannelRequest(u8Channel); UINT8 PLMESetTrxStateRequest(u8ReqMode); UINT8 PLMEEnergyDetect(); UINT8 PLMECCARequest(); UINT8 PLMELinkQuality(); UINT32 PLMEGetTimeRequest(); UINT8 PLMESetMC13192ClockRate(u8Freq); UINT8 PLMESetMC13192TmrPrescale (u8Freq); void PLMESetTimeRequest(u32RequestedTime); UINT8 PLMEEnableMC13192Timer1(u32CounterValue); UINT8 PLMEDisableMC13192Timer1(); void PLMEMC13192ResetIndication(); UINT8 PLMEMC13192SoftReset(); UINT8 PLMEMC13192XtalAdjust(u8TrimValue); UINT8 PLMEMC13192FEGainAdjust(i8GainValue); UINT8 PLMEPAOutputAdjust(u8RequestedPAValue); UINT8 PLMEGetRficVersion(); void PLMELoadPRBS9 (tTxPacket *); UINT8 PLMEPhyReset(); UINT8 PLMEEnablePromiscuousMode(); UINT8 PLMEDisablePromiscuousMode();

24 Module List (4 of 4) MC1321XSRB.c-void RadioInit() kbi.c-KBIIsr() KBIInit() timer.c-void delay(UINT16 count); interrupt void IRQTimer1(void); SCI.c-interrupt void Vscirx() void SCIInit(void); void SCIStartTransmit(UINT8 cData); void SCITransmitStr(UINT8 *pStr); void SCITransmitArray(UINT8 *pStr, UINT8 length); UINT8 SCIgets(char *pPrompt, char *pBuffer, UINT8 u8Size); void SCIInitGeneric(u32BusClock,u32BaudRate,u8ComNumber); void SCITransmitFormattedArray(char *pStr, UINT8 length); mc13213.c-- Delay.c-void OCDelay(INT16U ms) void OCDlyInit(void); INT16U GetmSCnt(void); *This List Excludes the list of modules associated with uC/OS


Download ppt "System Software Design Dan Sweet May 6 th, 2008 Western Washington University Bicycle Power Meter."

Similar presentations


Ads by Google