University Programs Knowledge Base

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

University Programs Knowledge Base

Discussions

Sort by:
1. Overview   This article is the umbrella entry point for a series of automotive embedded workshops built on the FRDM-A-S32K3xx microcontroller family. It groups together five hands-on modules — Lights, Brakes, Steering, Comfort, and Transmission — each demonstrating a different real-world automotive function that a modern Body Control Module (BCM), Chassis ECU, or Powertrain ECU would implement in production vehicles. All five modules share the same educational philosophy: they take a simple, low-risk hardware setup (FRDM board + FRDM-K64 Click Shield + a few MikroE Click modules) and use it to teach the core embedded concepts that underlie automotive software: analog and digital signal acquisition, real-time processing, actuator control, and safety-aware system design. Together they cover the most common peripherals of the S32K3 family — ADC, GPIO, PWM, FlexIO, LPI2C, eMIOS — and expose students to the same tool-chain used by NXP customers: S32 Design Studio 3.6.5, the S32K3 Real-Time Drivers (RTD), the Application Code Hub (ACH), and the underlying Automotive Software Package. Learning philosophy — Eat-Sleep-Code-Repeat The whole workshop series is designed around the Eat-Sleep-Code-Repeat initiative — a learn-by-doing culture where students continuously iterate on real hardware, break things, fix them, refactor, and re-flash until the concepts stick. Every module is small enough to be completed in one lab session, yet rich enough to leave room for extensions (state machines, filtering, CAN networking, closed-loop control, safety fall-backs). Concepts covered across the series Analog sensing: potentiometers, force sensors, resistor-ladder buttons → ADC conversion, scaling, debouncing. Digital I/O: GPIO input handling (buttons, switches), GPIO output sequencing (stepper coils). Actuation: PWM-based motor speed control (DC motors, fans), PWM-based servo positioning, WS2812 LED driving through FlexIO. Communication: I²C configuration of external PWM drivers (Servo Click / PCA9685). Control patterns: continuous mapping, threshold-based decisions, state machines, safety interlocks. Automotive concepts: Body Control Module (BCM) behavior, functional safety (ISO 26262), fail-safe defaults, redundancy considerations. What this article gives you Each of the next five sections provides a short summary of one module — what it demonstrates, which hardware it uses, which peripherals are involved, and a direct link to the full detailed workshop article. Students should read this page first to understand where each module fits in the bigger picture, then dive into the individual articles for step-by-step instructions.   2. Vehicle Lighting Control   The Lights module implements a simplified automotive lighting system that mirrors the behavior of a real vehicle Body Control Module. Six buttons on the Analog Key Click command different lighting functions — low beam, high beam, left/right turn signals, brake lights, and hazard lights — all displayed in real time on a 16-LED 4x4 RGB Click matrix. Key learning points Multi-button decoding on a single ADC channel (resistor-ladder input). Software debouncing and command decoding. Driving WS2812 LEDs through FlexIO (precise sub-microsecond timing without CPU load). BCM safety interlocks: high beam requires low beam ON; hazards synchronize left + right turn signals; high beam state preserved between blink cycles. Peripherals used: ADC0, FlexIO, GPIO. Boards: FRDM-A-S32K312 or FRDM-A-S32K344. Reference project:Automotive Lighting Control Using FRDM-A-S32K3XX Microcontrollers - NXP Community Demo: Vehicle Lighting Control on FRDM-A-S32K344 Automotive relevance: lighting is one of the most safety-critical driver-visibility functions in modern vehicles — this module teaches how a real BCM manages dependencies, blinking patterns, and fail-safe defaults.   3. Brake Status Monitoring   The Brakes module implements a simplified brake status monitoring system where a Force Click sensor simulates the driver's brake-pedal pressure. As pressure increases, the ADC value grows and the application progressively lights up the 4x4 RGB Click LEDs in green → yellow → orange → red, providing immediate visual feedback of the current braking level. Key learning points Continuous analog sensor acquisition through ADC. Threshold-based decision logic: converting a raw ADC value into discrete alert levels. Driving the RGB LED matrix through FlexIO to reflect the current system state. Introduction to real-time monitoring and safety-oriented visual feedback. Peripherals used: ADC0, FlexIO. Boards: FRDM-A-S32K312 or FRDM-A-S32K344. Reference project: Automotive Brake Control Using FRDM-A-S32K3XX Microcontrollers - NXP Community Demo: Brake Status Monitoring on FRDM-A-S32K344 Automotive relevance: brake status is a core input for many downstream ECUs (ABS, ESC, hill-hold, brake lights). This module teaches the fundamental pattern of sensor → threshold → visual/electrical output that appears everywhere in automotive software.   4. Assisted Steering Control   The Steering module demonstrates a simplified Electric Power Steering (EPS) / steer-by-wire concept. A POT Click potentiometer simulates the steering-wheel angle; the MCU reads it through ADC, scales it linearly, and generates a PWM command through the Servo Click (configured over I²C) that positions a Micro Servo SG 180° in real time. Key learning points Analog input scaling and linear mapping (ADC range → servo angle range). Using an external PWM controller configured over I²C (LPI2C1) — a common embedded pattern that offloads timing-critical work. Working with the Output Enable (OE) pin for safe-stop behavior. Understanding the actuation chain sensor → MCU → PWM → actuator. Peripherals used: ADC0, LPI2C1, GPIO. Boards: FRDM-A-S32K312 or FRDM-A-S32K344. Reference projects: Automotive Steering Control Using FRDM-A-S32K3XX Microcontrollers - NXP Community Demo: PWM-Based Steering Control on FRDM-A-S32K344 Automotive relevance: steering is a strictly safety-relevant function (ISO 26262 typically classifies it as ASIL C or D). This module introduces the concepts behind EPS and steer-by-wire and lays the foundation for future work with redundant sensors and fault detection.   5. Vehicle Comfort Control   The Comfort module implements two independent comfort functions typical of vehicle body electronics: cabin cooling (a 5 V fan driven through a DC Motor 2 Click using PWM) and electric window control (a NEMA17 stepper motor driven through an H-Bridge Click using full-step GPIO sequencing). On-board push-buttons act as the driver's HVAC and window switches. Key learning points PWM motor speed control (fan simulation). Stepper motor full-step sequencing (A → B → C → D and reverse) through four GPIO outputs. Handling multiple independent actuators from a single MCU without blocking. Introduction to window anti-pinch and other real BCM safety concepts. Peripherals used: GPIO, eMIOS (PWM). Boards: FRDM-A-S32K344 (only). Reference project: Automotive Comfort Control Using FRDM-A-S32K344 Microcontrollers - NXP Community Demo: Vehicle Comfort Control on FRDM-A-S32K344 Automotive relevance: comfort systems (HVAC, windows, mirrors, seats) form a huge share of modern body electronics. This module shows how one ECU can coordinate multiple actuators of different types (rotational-speed and positional) using the same S32K3 platform.   6. Transmission Control   The Transmission module demonstrates a continuous, proportional transmission control concept. A POT Click potentiometer represents the driver's acceleration command; the MCU samples it, applies linear scaling, and simultaneously drives two actuators: a Servo Click + Micro Servo that simulates the transmission selector position, and a DC Motor 2 Click + DC motor whose speed reflects the powertrain response. Key learning points Dual-actuator control from a single analog input (one MCU commands both servo angle and DC motor speed in parallel). Linear signal mapping to two different PWM ranges simultaneously. Combining I²C-configured PWM (Servo Click) and eMIOS-generated PWM (DC Motor 2 Click) in the same application. Understanding continuous vs. discrete control and how continuous mapping better mirrors real automotive behavior. Peripherals used: ADC0, LPI2C1, eMIOS. Boards: FRDM-A-S32K344 (only). Reference project: Automotive Transmission Control Using FRDM-A-S32K344 Microcontrollers - NXP Community Demo: Transmission Control on FRDM-A-S32K344 Automotive relevance: transmission control is part of the powertrain domain and requires deterministic response and safety-aware design. This module introduces the concepts and prepares students for more advanced topics such as closed-loop control, transmission-mode logic (P/R/N/D), and CAN networking with the engine ECU.   7. Conclusion   Together, these five modules give students a complete tour of what a modern Body Control Module, Chassis ECU, and Powertrain ECU actually do in a vehicle — from reading sensors and buttons, through processing and safety interlocks, to driving lights, motors, and actuators. Each module can be studied independently, but the real value emerges when they are viewed as pieces of one coherent picture: the same MCU family (S32K3), the same tool-chain (S32 Design Studio + Application Code Hub), the same hardware base (FRDM-A-S32Kxxx + FRDM-K64 Click Shield + MikroE Click modules), applied to five different automotive domains. The series is intentionally aligned with the Eat-Sleep-Code-Repeat philosophy: start with a working example, then experiment — add filtering, replace polling with interrupts, introduce a state machine, add CAN communication, or refactor for functional safety. Every extension is a step closer to the way production automotive software is actually written. Recommended learning path: Lights — simplest, teaches ADC, FlexIO and BCM logic. Brakes — introduces continuous sensor thresholds. Steering — adds I²C-controlled PWM and actuator positioning. Comfort — multi-actuator, dual-technology control (PWM + stepper). Transmission — combines everything into a proportional, dual-actuator system.   If you have questions, suggestions for improvement, or ideas for new modules that could extend this series, please leave a comment below — feedback from students and instructors is what keeps the workshops relevant and up to date.  
View full article
The course serves as a foundation for the Eat-Sleep-Code-Repeat learning initiative, encouraging a hands-on approach where students continuously learn, develop, test, and improve automotive embedded applications using real hardware and practical examples.
View full article
The course serves as a foundation for the Eat-Sleep-Code-Repeat learning initiative, encouraging a hands-on approach where students continuously learn, develop, test, and improve automotive embedded applications using real hardware and practical examples.
View full article
1. Overview   This module demonstrates how to implement a steering control system using Pulse Width Modulation (PWM) on NXP S32K3 microcontrollers. The application reads an analog input from a potentiometer (simulating a steering wheel) and converts it into a servo motor position. As the input changes, the servo motor reacts in real time, mimicking how steering systems work in modern vehicles. This example is based on Application Code Hub demonstrations for: PWM-Based Steering Control for FRDM-A-S32K344 PWM-Based Steering Control for FRDM-A-S32K312 In this workshop, a POT Click simulates the steering wheel position. When the student rotates it, an analog voltage proportional to the angle is read by the MCU through the ADC, scaled in software, and converted into a PWM duty cycle. The PWM is generated by the Servo Click (configured by the MCU over I²C) and drives a Micro Servo motor SG 180°, whose angle tracks the potentiometer in real time. Beyond the technical implementation, the course serves as a foundation for the Eat-Sleep-Code-Repeat learning initiative, encouraging a hands-on approach where students continuously learn, develop, test, and improve automotive embedded applications using real hardware and practical examples.   2. Learning Scope   After completing this course, participants should be able to:   Understand a basic steering control system and the ideas behind EPS and steer-by-wire. Use the POT Click as a simulated steering-wheel input. Acquire analog values (0–3.3 V) using the ADC and understand analog-to-digital conversion. Perform signal scaling from the ADC range to a servo angle / PWM duty cycle. Generate PWM signals to drive a servo motor. Configure the Servo Click over I²C using the OE (Output Enable) pin. Recognize the actuation data flow: sensor input → MCU processing → PWM actuation. Import, build, flash, and debug an ACH project in S32 Design Studio 3.6.5. Understand why steering functions are relevant for functional safety. 3. System Architecture   The three elements capture exactly the basic idea of the system in the demo: Input: Potentiometer (POT Click simulates the steering-wheel position) Processing: S32K3 MCU (reads the ADC, scales the value, commands the actuator) Output: Servo motor controlled via PWM (Micro Servo SG 180°) This matches the classic flow of an embedded actuation system: sensor → processing → actuator. Functional Flow The system operates continuously as follows: The potentiometer generates an analog voltage based on its position The ADC converts this voltage into a digital value The application scales this value into a steering angle The system generates a PWM signal based on the angle The servo motor moves accordingly This loop runs continuously to ensure real-time control. Steering Monitoring Application Architecture 4. Key Concepts   4.1 ADC (Analog-to-Digital Converter) The POT Click outputs 0–3.3 V depending on the wiper position. The ADC samples this voltage at regular intervals and quantizes it into a digital code (a 12-bit ADC produces values between 0 and 4095). The further the potentiometer is turned, the higher (or lower) the digital sample. ADC acquisition is the foundation of automotive sensing — used for torque, throttle, battery voltage, and many others. 4.2 Signal Scaling — From ADC to Servo Angle The ADC range (for example 0–4095) and the servo range (0°–180°, expressed as a PWM duty cycle) are different. The application performs a linear mapping so that one end of the potentiometer corresponds to one steering extreme and the other end to the opposite. This is the same scaling used in real EPS systems, where a hardware reading is converted into a normalized control command. 4.3 PWM — Pulse-Width Modulation and Servo Control PWM switches a digital output on and off at a fixed frequency, varying the duty cycle (the fraction of time the signal is high). A hobby servo such as the SG 180° interprets this duty cycle as a position command. In this demo, the PWM is not generated by the MCU itself but by the Servo Click's dedicated PWM controller, which the MCU configures over I²C — a typical embedded pattern that offloads time-critical signal generation and keeps the CPU free for application logic. 4.4 I²C — Configuring the Servo Click I²C — Inter-Integrated Circuit is a two-wire serial bus made of SDA (data) and SCL (clock). The S32K3 uses LPI2C1 on PTC6 (SDA) and PTC7 (SCL) to configure the Servo Click — PWM frequency, channel, and duty cycle. The OE — Output Enable pin on PTB17 is an additional control line that enables or disables the PWM outputs without reconfiguring the chip, which is also useful for a quick "safe stop" behavior. 4.5 POT Click as Steering Wheel The POT Click is a simplified, safe stand-in for a real steering sensor. The student rotates it by hand, the voltage changes, the MCU reads it through the ADC, scales it, and the servo reacts. 4.6 Data Flow at a Glance Physical rotation → analog voltage → ADC sample → scaled command (angle / duty cycle) → I²C configuration of the Servo Click → PWM signal → servo angle. This direct chain from the student's hand to the servo shaft is the main educational value of the demo. 5. Hardware and Software Setup   Required Hardware Component Image Purpose FRDM-A-S32K312 Alternative MCU platform used to run the steering application and process steering inputs. FRDM-A-S32K344 Alternative MCU platform used to run the steering application and control connected peripherals. FRDM-K64 Click Shield mikroBUS expansion board used to connect Click modules to the FRDM platform. Servo Click PWM driver board used to control the servo motor position. POT Click   Potentiometer module used to simulate steering wheel input. Micro Servo SG 180°                     Actuator used to convert control signals into steering movement. USB-C / 12 V supply — Provides power and enables programming and debugging of the system.   The example applications demonstrate how these peripherals are connected to the MCU pins and used to simulate steering wheel input and actuator control.   Steering Control Monitoring on FRDM-A-S32K312 Steering Control Monitoring on FRDM-A-S32K344       Software Environment S32 Design Studio IDE S32K3 Automotive Software Package Application Code Hub project import PWM-Based Steering Control for FRDM-A-S32K344 PWM-Based Steering Control for FRDM-A-S32K312 6. Implementation Guide   Step Action Sub-steps Expected Result 1 Import the Project Open S32 Design Studio Select “Import project from Application Code Hub” Search for the steering demo Use the GitHub link for automatic configuration Select main branch Import project Project successfully appears in workspace 2 Build the Application Right-click project Select “Update Code and Build Project” Confirm SDK component management Build completes with no errors and generates .elf file 3 Connect Hardware Connect USB cable (and 12V supply for S32K312) Attach click boards Verify wiring Board is powered and detected by IDE 4 Flash and Run Open Debug Configurations Select “debug_flash_pemicro” Start debugging Application runs continuously 5 Functional Validation Rotate the potentiometer Observe servo movement Servo follows potentiometer position in real time   7. Signal Behavior and Control Logic     Figure: Steering control signal mapping. The 12-bit ADC value (0–4095) is linearly mapped to a servo angle (0°–180°) and a matching PWM duty cycle (1.0–2.0 ms), with reference points at Left, Center and Right. At startup the servo moves to the neutral position; during operation, any input change produces an immediate, proportional reaction — implementing a basic steer-by-wire behavior.   8. Troubleshooting   Issue Possible Actions Board Not Detected Check USB cable and drivers Verify debugger connection Restart IDE No Servo Movement Verify PWM configuration Check servo wiring Ensure correct power supply Incorrect Behavior Check ADC configuration Validate scaling function Ensure PWM duty cycle mapping is correct Unstable Movement Add signal filtering Check power stability   9. Extending the Application   The basic implementation can be extended in several ways: Steering Range Control Restrict or extend the actuator's range of motion Define software-based limits to protect the mechanics Input Direction Inversion Reverse how the actuator responds to the input Useful for left-hand vs. right-hand drive calibration Noise Filtering Apply software filtering to stabilize readings Avoid jitter near the center position Scaling Logic Exploration Identify and analyze how the input is mapped to the output Connect software math with hardware behavior Fault-Handling Behavior Add a mechanism that reacts to a detected fault Transition the system into a safer state State Machine Implementation A more advanced approach is to implement a state machine: Idle Active Fault 10. Safety Context   This example reflects key automotive principles: Continuous monitoring of driver input Immediate response to control signals Reliable actuator control In real systems: Redundancy is required Fault detection mechanisms are implemented Systems must comply with ISO 26262 (functional safety standard) Steer-by-wire systems require high reliability since there is no direct mechanical link. 11. Conclusion   This module demonstrates how a simple embedded system can implement steering control using ADC input and PWM output. It shows how: Analog input is acquired Data is processed in real time Actuators are controlled using PWM   Result on FRDM-A-S32K312 Result on FRDM-A-S32K344   The course provides a strong foundation for more advanced systems, including filtering, state machines, and safety-oriented designs.
View full article
The course serves as a foundation for the Eat-Sleep-Code-Repeat learning initiative, encouraging a hands-on approach where students continuously learn, develop, test, and improve automotive embedded applications using real hardware and practical examples.
View full article
1. Overview   This module demonstrates how to implement a vehicle lighting control system using analog input acquisition and FlexIO-based LED driving on NXP S32K3 microcontrollers. The application reads analog inputs from the Analog Key Click module (six push-buttons, each generating a distinct voltage level) and converts them into commands that drive a 4x4 RGB LED matrix. Each button press activates a specific lighting function — low beam, high beam, turn signals, brake lights, or hazard lights — while safety interlocks and blinking patterns run continuously in the background, mimicking how a real automotive Body Control Module (BCM) manages vehicle lighting. This example is based on Application Code Hub demonstrations for: Vehicle Lighting Control for Daylight and Hazard Signals on FRDM-A-S32K344 Vehicle Lighting Control for Daylight and Hazard Signals on FRDM-A-S32K312 In this workshop, the Analog Key Click simulates six vehicle lighting controls. When the student presses a button, an analog voltage proportional to the pressed key is read by the MCU through the ADC (with software debouncing), decoded into a specific lighting command, and translated into an RGB pattern generated by the FlexIO peripheral. The 4x4 RGB Click then displays the corresponding automotive lighting behavior in real time — warm white for low beams, cool white for high beams, blinking amber for turn signals and hazards, and red for brake lights. Beyond the technical implementation, the course serves as a foundation for the Eat-Sleep-Code-Repeat learning initiative, encouraging a hands-on approach where students continuously learn, develop, test, and improve automotive embedded applications using real hardware and practical examples.   2. Learning Scope   After completing this course, participants should be able to:   Understand a basic vehicle lighting control system and the ideas behind an automotive Body Control Module (BCM). Use the Analog Key Click as a simulated multi-button user interface (six inputs on a single analog line). Acquire analog values (0–3.3 V) using the ADC and understand how multiple buttons share one channel through voltage division. Perform software debouncing and decode which button was pressed based on ADC value ranges. Drive an RGB LED matrix using the FlexIO peripheral, generating precise timing for WS2812-style LEDs. Implement safety interlocks between lighting functions (e.g., high beam requires low beam ON). Implement continuous background patterns such as blinking turn signals and synchronized hazards. Recognize the actuation data flow: analog input → ADC → command decoding → FlexIO LED output. Import, build, flash, and debug an ACH project in S32 Design Studio 3.6.5. Understand why lighting functions are relevant for automotive safety and driver visibility. 3. System Architecture   The three elements capture exactly the basic idea of the system in the demo: Input: Analog Key Click (six buttons T1–T6, each generating a distinct analog voltage level) Processing: S32K3 MCU (reads the ADC, decodes the button, applies BCM logic, updates the LED state) Output: 4x4 RGB Click (16-LED matrix driven by FlexIO to display lighting patterns) This matches the classic flow of an embedded body-control system: sensor → processing → actuator. Functional Flow The system operates continuously as follows: The user presses a button on the Analog Key Click (T1–T6) Each button generates a distinct analog voltage on the shared output line The ADC samples the voltage and converts it into a digital value The application decodes which button was pressed (with debouncing) The BCM logic applies interlocks and dependencies (e.g., high beam requires low beam) The FlexIO peripheral drives the RGB Click LEDs with the corresponding color pattern This loop runs continuously to ensure real-time lighting control, with blinking patterns and safety interlocks maintained in the background. Vehicle Lighting Control Application Architecture    4. Key Concepts   4.1 ADC (Analog-to-Digital Converter) The Analog Key Click outputs 0–3.3 V on a single analog line, with each button generating a specific voltage step. The ADC samples this voltage on ADC0_P0 (pin PTD1) at regular intervals and quantizes it into a digital code (a 12-bit ADC produces values between 0 and 4095). Each button corresponds to a specific value range, allowing six digital inputs to be read through a single ADC channel. ADC acquisition is the foundation of automotive sensing — used for switches, buttons, sensors, and many others. 4.2 Analog Multi-Button Decoding Instead of using six separate GPIO pins, the Analog Key Click uses a resistor ladder that produces a different voltage for each button press. The application performs software debouncing (multiple ADC samples must agree before a press is confirmed) and then compares the ADC value against predefined thresholds to identify which button (T1–T6) was pressed. This technique is common in automotive steering-wheel controls, where many buttons share a single analog line to save wiring and pins. 4.3 FlexIO — Driving the RGB Click LEDs FlexIO is a highly flexible peripheral on S32K3 that can emulate serial protocols like WS2812/NeoPixel. The RGB Click uses individually addressable LEDs that require precise timing (~800 kHz with strict pulse widths). FlexIO on PTA13 (FlexIO_D8) generates this waveform in hardware, without loading the CPU. Each of the 16 LEDs receives its color data through a serial stream, allowing independent control of color and brightness per LED. 4.4 RGB LED Mapping and Lighting Zones The 16 LEDs of the RGB Click are logically grouped into automotive lighting zones: LEDs 13, 14 → Low Beam Headlights (warm white) LEDs 8, 9, 10, 11 → High Beam Headlights (cool white) LEDs 0, 12 → Left Turn Signal (blinking amber) LEDs 3, 15 → Right Turn Signal (blinking amber) LEDs 1, 2, 5, 6 → Brake Lights (red) LEDs 0, 3, 12, 15 → Hazard Lights (synchronized blinking amber) 4.5 BCM Safety Interlocks and State Dependencies The application implements safety logic typical of a real Body Control Module: high beam can only be activated when low beam is already ON; turning OFF the low beam automatically disables the high beam; hazard lights synchronize left and right turn signals simultaneously; high beam state is preserved during hazard blinking and restored between cycles. These interlocks illustrate how real automotive lighting logic prevents unsafe combinations and preserves driver intent. 4.6 Data Flow at a Glance Button press → analog voltage on shared line → ADC sample → software debouncing → button decoding → BCM logic (interlocks + dependencies) → FlexIO WS2812 output stream → RGB LED color update. This direct chain from the student's finger to the LEDs is the main educational value of the demo. 5. Hardware and Software Setup   Required Hardware Component Image Purpose FRDM-A-S32K312 Alternative MCU platform used to run the lighting application and process user inputs. FRDM-A-S32K344 Alternative MCU platform used to run the lighting application and control connected peripherals. FRDM-K64 Click Shield mikroBUS expansion board used to connect Click modules to the FRDM platform. Analog Key Click Six-button analog module used to simulate the vehicle lighting controls (headlights, indicators, brakes, hazards). 4x4 RGB Click 16-LED RGB matrix used to display the automotive lighting patterns in real time. USB-C / 12 V supply — Provides power and enables programming and debugging of the system through a single USB-C connection.   The example applications demonstrate how these peripherals are connected to the MCU pins and used to simulate a complete vehicle lighting control system.   Vehicle Lighting Control on FRDM-A-S32K312 Vehicle Lighting Control on FRDM-A-S32K344   Software Environment S32 Design Studio IDE S32K3 Automotive Software Package Application Code Hub project import Vehicle Lighting Control for Daylight and Hazard Signals on FRDM-A-S32K344 Vehicle Lighting Control for Daylight and Hazard Signals on FRDM-A-S32K312 6. Implementation Guide   Step Action Sub-steps Expected Result 1 Import the Project Open S32 Design Studio 3.6.5 Select “Import project from Application Code Hub” Search for “Lighting” Select the desired project for your FRDM board Use the GitHub link for automatic configuration Select main branch Import project Project successfully appears in workspace 2 Build the Application Right-click project Select “Update Code and Build Project” Confirm SDK component management Build completes with no errors and generates .elf file 3 Connect Hardware Connect USB-C cable (and 12 V supply for FRDM-A-S32K312) Attach FRDM-K64 Click Shield, Analog Key Click and 4x4 RGB Click Verify wiring on PTA13 (FlexIO) and PTD1 (ADC) Board is powered and detected by IDE 4 Flash and Run Open Debug Configurations Select “debug_flash_pemicro” Start debugging Application runs continuously; LEDs perform startup test sequence 5 Functional Validation Press buttons T1–T6 on the Analog Key Click Observe corresponding LED patterns on the RGB Click Verify safety interlocks (high beam requires low beam) Verify continuous blinking on turn signals and hazards RGB LEDs display the correct automotive lighting patterns for each button   7. Signal Behavior and Control Logic   The following diagram illustrates how each user input on the Analog Key Click is mapped to a specific lighting function and to the individual LEDs of the 4×4 RGB Click matrix. Each button (T1–T6) triggers a unique combination of LEDs, colors, and patterns, reproducing the behavior of a simplified automotive lighting system.    The MCU continuously monitors the analog input from the Analog Key Click and decodes which button is pressed. Based on the detected input, the application activates the corresponding lighting function by driving the assigned LEDs on the 4×4 RGB Click through the FlexIO serial interface. Steady functions (Low Beam, High Beam, Brake) keep the associated LEDs constantly ON, while directional functions (Left Turn, Right Turn, Hazard) toggle the LEDs at approximately 1 Hz to reproduce the blinking behavior of real vehicle indicators. Additional control rules — such as High Beam requiring Low Beam to be active, or Hazard Lights preserving and restoring the High Beam state — reflect the interdependencies found in a real automotive body control module.   8. Troubleshooting   Issue Possible Actions Board Not Detected Check USB-C cable and drivers Verify debugger connection Restart IDE No LEDs Lighting Up Verify FlexIO configuration on PTA13 Check 3.3 V and GND wiring on RGB Click Confirm data-line wiring to IN1 Buttons Not Detected Verify ADC0_P0 configuration on PTD1 Check 3.3 V and GND wiring on Analog Key Click Confirm software debouncing thresholds Wrong Button Triggered Recalibrate ADC value ranges for each button Verify power supply stability (3.3 V) Check for noise on the analog line Incorrect LED Colors or Timing Verify FlexIO clock configuration (WS2812 timing) Check LED index → color mapping in code Ensure RGB order (GRB vs. RGB) matches the LED type High Beam Not Activating Ensure low beam (T1) is ON first — BCM interlock Check application logic for beam dependencies   9. Extending the Application   The basic implementation can be extended in several ways: Additional Lighting Functions Add fog lights, parking lights, or daytime running lights (DRL) Simulate reverse lights that activate when a specific input is triggered Adaptive Front Lighting Integrate a steering angle input (e.g., POT Click) to swivel the headlights Simulate cornering lights that turn on when indicators are active Ambient Light Sensing Add a light sensor to automatically enable low beams at dusk Implement smooth dimming between day and night modes Brake Light Enhancements Add an emergency brake flashing pattern for hard braking Implement a third brake light (single LED, always ON with brakes) CAN Communication Enable communication with other vehicle ECUs (e.g., BCM master, doors) Receive lighting commands over the vehicle network State Machine Implementation A more advanced approach is to implement a formal state machine covering: Off DRL / Parking Low Beam High Beam Hazard / Fault 10. Safety Context   This example reflects key automotive principles: Continuous monitoring of driver input Immediate response to control signals Reliable actuator (LED) control with predictable timing Safety interlocks between lighting functions (high beam requires low beam) In real systems: Redundancy is required for safety-relevant functions (e.g., brake lights, hazards) Fault detection mechanisms are implemented (open lamp, short circuit, overcurrent) Systems must comply with ISO 26262 (functional safety standard) Vehicle lighting is one of the most safety-critical automotive functions because it directly affects driver visibility and vehicle conspicuity. Modern Body Control Modules implement extensive diagnostics, backup lighting strategies, and fail-safe defaults (e.g., hazard lights activated on power-loss recovery). 11. Conclusion   This module demonstrates how a simple embedded system can implement complete vehicle lighting control using ADC input and FlexIO output on the S32K3 platform. It shows how: Multiple digital inputs can share a single analog line through resistor-ladder decoding Analog data is acquired, debounced and processed in real time Complex automotive lighting patterns are controlled through FlexIO-driven WS2812 LEDs Safety interlocks and background blinking patterns are managed by BCM-style logic   Result on FRDM-A-S32K312 Result on FRDM-A-S32K344 FRDM-A-S32K312 FRDM-A-S32K344   The course provides a strong foundation for more advanced systems, including adaptive lighting, CAN networking, ambient sensing, and safety-oriented designs typical of automotive body-control modules.
View full article
Click Here : https://community.freescale.com/servlet/JiveServlet/downloadBody/102170-102-1-18605/OpenSDA.zip To download the file with the files mentioned on the presentation.
View full article
All information can be found in this document
View full article
This tutorial covers the details of Turning A Servo on the Kinetis K40 using TWR-K40x256-KIT evaluation board. Overview In this exercise you will build a “bare metal” (no RTOS) application which turns a servo, targeting a Freescale K40 board. You will: Create the Servo code in CodeWarrior Build the Servo project Download and run the code on a Kinetis K40 Tower System board Learn how to utilize the FlexTimer module to control a Servo   To successfully complete this exercise you need the following board and development environment. The K40 Tower card, TWR-K40x256 Tower Elevator Panels Servo Prototyping Board Power to your servo - either utilize the 7.2v Nicad Battery or a DC power supply CodeWarrior for Microcontrollers 1. Hardware 2. Create a New CodeWarrior Project 3. Build the Code 4. Download/Debug/Run 5. Learning Step: Servo Code Description Example Code Variables Init_PWM_Servo PWM_Servo PWM_Servo_Angle Set Up a Look-Up Table for Servo Angles Other K40 Tutorials: Links 1. Hardware   The first step of this tutorial requires you read the Turn A Servo article for background information on servo's, timer modules, PWM signals and counters. You will need to connect your servo to the microcontroller and also to a separate power source. 2. Create a New CodeWarrior Project The next step is to create a new project (or add this code to an existing project). 3. Build the Code If you have more than one project in your project view, make sure the proper project is the focus. The most reliable way to do this is to right click the project and choose Build Project as shown below. You can also go to the Project menu and choose the same command. If you encounter errors, look in the Problems view and resolve them. You can ignore any warnings. 4. Download/Debug/Run This link shows a video of the servo turning the wheels from left to right in small increments http://www.youtube.com/watch?v=QgwASk9DHvU&feature=relmfu 5. Learning Step: Servo Code Description Your code will sweep your servo from max to minimum angular position, and then back again continuously. Example Code This code sets up the Pulse Width Modulation Timer Module for use by a servo. It is set to utilize Edge-Aligned PWM, and this file properly configures the period, and pulse width for use by the other modules Several important functions are contained in this file: 1. Init_PWM_Servo () - initializes the timer module 2. PWM_Servo (double duty_Cycle) - enter the desired duty cycle setting for the servo 3. PWM_Servo_Angle (int Angle) - enter the desired angle for the servo Straight forward - PWM_Servo_Angle (45) Full left - PWM_Servo_Angle (90)Full right - PWM_Servo_Angle (0)   4. Servo_Tick - interrupt routine which executes once/servo period PWM_Servo (double duty_Cycle) Init_PWM_Servo () PWM_Servo_Angle (float Angle) void ServoTick() Variables FTM0_CLK_PRESCALE TM0_OVERFLOW_FREQUENCY Pulse_Width_Low Pulse_Width_High Total_Count Low_Count Scale_Factor Angle Init_PWM_Servo Void Init_PWM_Servo () { //Enable the Clock to the FTM0 Module SIM_SCGC6 |= SIM_SCGC6_FTM0_MASK;  //Pin control Register (MUX allowing user to route the desired signal to the pin.  PORTC_PCR4  = PORT_PCR_MUX(4)  | PORT_PCR_DSE_MASK; //FTM0_MODE[WPDIS] = 1; //Disable Write Protection - enables changes to QUADEN, DECAPEN, etc.  FTM0_MODE |= FTM_MODE_WPDIS_MASK; //FTMEN is bit 0, need to set to zero so DECAPEN can be set to 0 FTM0_MODE &= ~1; //Set Edge Aligned PWM FTM0_QDCTRL &=~FTM_QDCTRL_QUADEN_MASK;  //QUADEN is Bit 1, Set Quadrature Decoder Mode (QUADEN) Enable to 0,   (disabled) // Also need to setup the FTM0C0SC channel control register FTM0_CNT = 0x0; //FTM Counter Value - reset counter to zero FTM0_MOD = (PERIPHERAL_BUS_CLOCK/(1<<FTM0_CLK_PRESCALE))/FTM0_OVERFLOW_FREQUENCY ;  // Count value of full duty cycle FTM0_CNTIN = 0; //Set the Counter Initial Value to 0 // FTMx_CnSC - contains the channel-interrupt status flag control bits FTM0_C3SC |= FTM_CnSC_ELSB_MASK; //Edge or level select FTM0_C3SC &= ~FTM_CnSC_ELSA_MASK; //Edge or level Select FTM0_C3SC |= FTM_CnSC_MSB_MASK; //Channel Mode select //Edit registers when no clock is fed to timer so the MOD value, gets pushed in immediately FTM0_SC = 0; //Make sure its Off! //FTMx_CnV contains the captured FTM counter value, this value determines the pulse width FTM0_C3V = FTM0_MOD; //Status and Control bits FTM0_SC =  FTM_SC_CLKS(1); // Selects Clock source to be "system clock" or (01) //sets pre-scale value see details below FTM0_SC |= FTM_SC_PS(FTM0_CLK_PRESCALE); /******begin FTM_SC_PS details **************************** * Sets the Prescale value for the Flex Timer Module which divides the * Peripheral bus clock -> 48Mhz by the set amount * Peripheral bus clock set up in clock.h *  * The value of the prescaler is selected by the PS[2:0] bits.  * (FTMx_SC field bits 0-2 are Prescale bits -  set above in FTM_SC Setting) *  *  000 - 0 - No divide *  001 - 1 - Divide by 2 *  010 - 2 - Divide by 4 *  011 - 3 - Divide by 8 *  100 - 4 - Divide by 16 *  101 - 5 - Divide by 32 *  110 - 6 - Divide by 64 - *  111 - 7 - Divide by 128 *  ******end FTM_SC_PS details*****************************/ // Interrupts FTM0_SC |= FTM_SC_TOIE_MASK; //Enable the interrupt mask.  timer overflow interrupt.. enables interrupt signal to come out of the module itself...  (have to enable 2x, one in the peripheral and once in the NVIC enable_irq(62);  // Set NVIC location, but you still have to change/check NVIC file sysinit.c under Project Settings Folder } PWM_Servo Void PWM_Servo (double duty_Cycle) {          FTM0_C3V =  FTM0_MOD*(duty_Cycle*.01); } PWM_Servo_Angle //PWM_Servo_Angle is an integer value between 0 and 90 //where 0 sets servo to full right, 45 sets servo to middle, 90 sets servo to full left void PWM_Servo_Angle (float Angle) {    High_Count = FTM0_MOD*(Pulse_Width_High)*FTM0_OVERFLOW_FREQUENCY;    Low_Count = FTM0_MOD*(Pulse_Width_Low)*FTM0_OVERFLOW_FREQUENCY;    Total_Count = High_Count - Low_Count;    Scale_Factor = High_Count -Total_Count*(Angle/90);     FTM0_C3V = Scale_Factor; //sets count to scaled value based on above calculations } Set Up a Look-Up Table for Servo Angles int main(void) {   //Servo angles can be stored in a look-up table for steering the car.   float table[n] = { steering_angle_0;    steering_angle_1;    steering_angle_2;   ……    steering_angle_n-1    };   Steering_Angle = table[x];   PWM_Servo_Angle (Steering_Angle); // Call PWM_Servo_Angle function. } Other K40 Tutorials: K40 Blink LED Tutorial K40 DC Motor Tutorial Kinetis K40: Turning A Servo K40 Line Scan Camera Tutorial Links Kinetis K40 TWR-K40X256-KIT
View full article
This tutorial will introduce you to I 2 C and provide a framework that you can use to start communicating with various devices that use I 2 C. This tutorial is meant for the Kinetis K40 and will probably not work on any other Kinetis chip. DISCLAIMER: This has not been fully tested and may not work for you and for all devices. The header file provided does not handle errors and should not be used for critical projects. 2C signaling I2C header file Example of I2C communication using Freescale MMA8452Q 3-axis accelerometer Introduction to I 2 C signaling I 2 C is a simple two wire communication system used to connect various devices together, such as Sensory devices and microprocessors using 8 bit packets. I 2 C requires two wires: the first is called SDA and is used for transferring data, the second is called SCL and it is the clock used to drive the data to and from devices. I 2 C uses an open drain design which requires a pull up resistor to logic voltage (1.8,3.3,5) on both SDA and SCL for proper operation. I 2 C is a master-slave system where the master drives the clock and initiates communication. The I 2 C protocol has 5 parts. The Start signal which is defined as pulling the SDA line low followed by pulling SCL low. The slave device address including the Read/Write bit The register address that you will be writing to/ reading from the data The acknowledgement signal which is sent from the receiving device after 8 bits of data has been transferred successfully. the Stop signal, which is defined by SDA going high before SCL goes high. 1. The start signal is sent from the Master to intiate communication on the bus. The start and stop signals are the only time that SDA can change out of sync with SCL. Once the start signal is sent no other device can talk on the bus until the stop signal is sent. If for whatever reason another device tries to talk on the bus then there will be an error and the K40 can detect this. 2. The slave device is a 7 bit (sometimes 10bit but this will not be covered in this tutorial) address provided by the device and is specific to the device. The type of data operation (read/write) is determined by the 8 th bit. A 1 will represent a write and a 0 a read operation. 3. The register addresses are provided by the device's specifications. 4. The data you will send to a device if you are writing or the data that you receive from the device when reading. This will always be 8 bits. 5. After 8 bits of data has been transferred successfully the receiving device will pull the SDA line low to signify that it received the data. If the transmitting device does not detect an acknowledgement then there will be an error. The K40 will be able to detect this. 6. The stop signal is sent from the Master to terminate communication on the bus. Some devices require this signal to operate properly but it is required if there will be more than one master on the bus (which will not be covered in this tutorial) I2C header file This header file only has functions for reading and writing one byte at a time. Most devices support reading and writing more than one byte at a time without sending the Stop signal. Typically the device will keep incrementing the register's address to the next one during read/writes when there is no stop signal present. See your device's user manual for more information. /* * i2c.h * * Created on: Apr 5, 2012 * Author: Ian Kellogg  * Credits: Freescale for K40-I2C example */  #ifndef I2C_H_  #define I2C_H_  #include "derivative.h"  #define i2c_EnableAck() I2C1_C1 &= ~I2C_C1_TXAK_MASK #define i2c_DisableAck() I2C1_C1 |= I2C_C1_TXAK_MASK  #define i2c_RepeatedStart() I2C1_C1 |= I2C_C1_RSTA_MASK  #define i2c_Start() I2C1_C1 |= I2C_C1_TX_MASK;\    I2C1_C1 |= I2C_C1_MST_MASK  #define i2c_Stop() I2C1_C1 &= ~I2C_C1_MST_MASK;\    I2C1_C1 &= ~I2C_C1_TX_MASK  #define i2c_EnterRxMode() I2C1_C1 &= ~I2C_C1_TX_MASK;\    I2C1_C1 |= I2C_C1_TXAK_MASK  #define i2c_write_byte(data) I2C1_D = data  #define i2c_read_byte() I2C1_D  #define MWSR 0x00 /* Master write */  #define MRSW 0x01 /* Master read */  /* * Name: init_I2C * Requires: nothing * Returns: nothing * Description: Initalizes I2C and Port E for I2C1 as well as sets the I2C bus clock */  void init_I2C()  {    SIM_SCGC4 |= SIM_SCGC4_I2C1_MASK; //Turn on clock to I2C1 module    SIM_SCGC5 |= SIM_SCGC5_PORTE_MASK; // turn on Port E which is used for I2C1    /* Configure GPIO for I2C1 function */    PORTE_PCR1 = PORT_PCR_MUX(6) | PORT_PCR_DSE_MASK;    PORTE_PCR0 = PORT_PCR_MUX(6) | PORT_PCR_DSE_MASK;    I2C1_F = 0xEF; /* set MULT and ICR This is roughly 10khz See manual for different settings*/    I2C1_C1 |= I2C_C1_IICEN_MASK; /* enable interrupt for timing signals*/  }  /* * Name: i2c_Wait * Requires: nothing * Returns: boolean, 1 if acknowledgement was received and 0 elsewise  * Description: waits until 8 bits of data has been transmitted or recieved */  short i2c_Wait() {    while((I2C1_S & I2C_S_IICIF_MASK)==0) {    }     // Clear the interrupt flag    I2C1_S |= I2C_S_IICIF_MASK;  }  /* * Name: I2C_WriteRegister * Requires: Device Address, Device Register address, Data for register * Returns: nothing * Description: Writes the data to the device's register */  void I2C_WriteRegister (unsigned char u8Address, unsigned char u8Register, unsigned char u8Data) {    /* shift ID in right position */    u8Address = (u8Address << 1)| MWSR;    /* send start signal */    i2c_Start();    /* send ID with W/R bit */    i2c_write_byte(u8Address);    i2c_Wait();    // write the register address    i2c_write_byte(u8Register);    i2c_Wait();    // write the data to the register    i2c_write_byte(u8Data);    i2c_Wait();    i2c_Stop();  }  /* * Name: I2C_ReadRegister_uc * Requires: Device Address, Device Register address * Returns: unsigned char 8 bit data received from device * Description: Reads 8 bits of data from device register and returns it */  unsigned char I2C_ReadRegister_uc (unsigned char u8Address, unsigned char u8Register ){    unsigned char u8Data;    unsigned char u8AddressW, u8AddressR;    /* shift ID in right possition */    u8AddressW = (u8Address << 1) | MWSR; // Write Address    u8AddressR = (u8Address << 1) | MRSW; // Read Address    /* send start signal */    i2c_Start();    /* send ID with Write bit */    i2c_write_byte(u8AddressW);    i2c_Wait();    // send Register address    i2c_write_byte(u8Register);    i2c_Wait();    // send repeated start to switch to read mode    i2c_RepeatedStart();    // re send device address with read bit    i2c_write_byte(u8AddressR);    i2c_Wait();    // set K40 in read mode    i2c_EnterRxMode();    u8Data = i2c_read_byte();    // send stop signal so we only read 8 bits    i2c_Stop();    return u8Data;  }  /* * Name: I2C_ReadRegister * Requires: Device Address, Device Register address, Pointer for returned data * Returns: nothing * Description: Reads device register and puts it in pointer's variable */  void I2C_ReadRegister (unsigned char u8Address, unsigned char u8Register, unsigned char *u8Data ){    /* shift ID in right possition */    u8Address = (u8Address << 1) | MWSR; // write address    u8Address = (u8Address << 1) | MRSW; // read address    /* send start signal */    i2c_Start();    /* send ID with W bit */    i2c_write_byte(u8Address);    i2c_Wait();    // send device register    i2c_write_byte(u8Register);    i2c_Wait();    // repeated start for read mode    i2c_RepeatedStart();    // resend device address for reading    i2c_write_byte(u8Address);    i2c_Wait();    // put K40 in read mode    i2c_EnterRxMode();    // clear data register for reading    *u8Data = i2c_read_byte();    i2c_Wait();    // send stop signal so we only read 8 bits    i2c_Stop();    }  #endif  Example of I2C communication using Freescale MMA8452Q 3-axis accelerometer This example is very simplistic and will do nothing more than read the WHO AM I register to make sure that I 2 C is working correctly. To see more check out the Freescale MMA8452Q Example /* Main. C */ #include <stdio.h> #include "derivative.h" /* include peripheral declarations */ #include "i2c.h" int main(void) {      // checking the WHO AM I register is a great way to test if communication is working      // The MMA8452Q has a selectable address which is either 0X1D or 0X1C depending on the SA0 pin      // For the MMA8452Q The WHO AM I register should always return 0X2A      if (I2C_ReadRegister_uc (0x1D,0x0D) != 0x2A {           printf ("Device was not found\n");      } else {           printf ("Device was found! \n");      } }
View full article
This tutorial is meant to introduce you to the use of a push button. It will give an explanation and example code of how you could implement a push button. Push buttons can be a great way to set a number of different states. Push buttons are advantageous because you can change your code physically versus pulling up the debugger every time you want to make a little change. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ Usage A button can have many different functions on your autonomous vehicle. Most notably the button has been used for testing to start, stop, or put your car in a configuration mode. Configuration mode would let you test to see if all the peripherals except the motors are working. This would help you test your camera data and servo angles without always having to run after your car. During your race you can even set your button to different speed states. Since you have two chance to traverse the track you may have a slower safer speed on one state and a faster speed the pushes the limit on another state. In the end, what you do with the button is up to you and the choices are unlimited. Description of Example Code Below there will be an example of how to implement a push button. This push button will be connected to PTA16. When reading this pin a high, "1" or 5V, is considered "OFF" and a low, "0" or 0V, is considered "ON." To reduce the effects of bounce and/or the chance of a false press, additional code has been added to filter the signal. This is done by checking the button every 10ms for 50ms. If the button has been pressed for 3 or more of the 5 times we will change the state, otherwise it will not be considered a "press." Button Initialization Here is the initialization code that can be put in a header such as "Button.h." #define BUTTONLENGTH 5   // Button's Defined State   // 0 means button not pressed   // 1 means button pressed short fButton = 0; short iButtonCount=0; short iButtonTimer=0;   // Button Triggered Start time short iButtonTime; void initButton() {   //turn on clock to Port A   SIM_SCGC5 |= SIM_SCGC5_PORTA_MASK;   // configure pin to be GPIO   PORTA_PCR16 = PORT_PCR_MUX(1) | PORT_PCR_DSE_MASK;   // configure PTA16 to be input   GPIOA_PDDR &= (0<<16);  } See GPIO for explanation of how these specific commands work. Button Implementation Below is an example of a function that implements the button function. This function can be stored in a header file "Button.h" along with the initialization code. To call this function you would just place "readButton();" in your 10ms Flextimer source code. Read comments for description of each line Void readButton () {                  short fButtonState  = 0;   // initializes the button state to "OFF"           iButtonCount++;            // increments button count      if (GPIOA_PDIR & (1<<16)) {                    // if button read as high then its off otherwise its on           fButtonState = 0;      } else {           fButtonState = 1;      }      if (fButtonState && ! fButton) {                          // if the button is pushed and it previously wasn't then start a count           iButtonTimer++;           if (iButtonTimer <= 1) {                                                             iButtonCount = 0;                                 // Reset the Button Count if the timer is less or equal to 1           }      } else if (! fButtonState && fButton) {           iButtonTimer++;           if ( iButtonTimer <= 1) {                iButtonCount = 0;                               // Reset the Button count if the timer is less or equal to 1           }      }      if ( iButtonCount > BUTTONLENGTH && iButtonTimer >0) {     // if button has been read for 50ms check to see if we passed the test!           if ( iButtonTimer > (3*BUTTONLENGTH/4) && fButton) {                // fButton = 0;           } else if (iButtonTimer > (3*BUTTONLENGTH/4) && ! fButton) {                fButton = 1;           }           iButtonCount = 0;           iButtonTimer = 0;     } }
View full article
This tutorial covers the specific details of obtaining data from the line scan camera on the Qorivva TRK-MPC5604B board. This tutorial will help students familiarize themselves with how to interface the camera with the microcontroller, how to configure GPIO pins to create clock signals and also how to utilize the microcontroller's ADC to read the data from the camera. Outside of control algorithms, configuring the camera is one of the more complex tasks necessary to create a Freescale Cup Vehicle. 1. Overview 2. Hardware 3. Set up the Hardware: Line Scan Camera/Microcontroller Hardware Setup 4. Build the Code 5. Download/Debug/Run 6. Learning Step Functions Calling the Function Variables Setting threshold. (This can give you a simple view of what your camera sees without connecting it to a scope) Sample Code Download Link Alternative Examples Other Qorivva Tutorials: Links External 1. Overview In this exercise students will access the line scan camera, create a clock signal and create the initialization pulse which tells the camera to begin the exposure period. This tutorial will not describe line recognition or line following algorithms - these concepts are beyond its scope. Students will: Open the example file using Codewarrior Build a project Download the code to the board connect the microcontroller to the camera via the motor control board Run the program view the camera data, clock and Si pulse on an oscilloscope To successfully complete this exercise, students will need the following board and development environment: TRK-MPC5604B Motor Drive Board Version A Freescale Cup TRK-MPC5604B compatible Car Kit CodeWarrior for Microcontrollers v 2.8 P&E Micro Toolkit Freescale Line Scan Camera USB Cord Knowledge of how Pointers and arrays are utilized in C 2. Hardware   Read the Obtain Data From Line Scan Camera overview article for general information on the camera, ADC, and GPIO microcontroller configuration settings. Connect the sensors, motor drive board and microcontroller of your car according to the TRK-MPC5604B chassis build instructions 3. Set up the Hardware: Line Scan Camera/Microcontroller Hardware Setup It is crucial for an engineer to have the proper test equipment and tools for the job. In this case, without an oscilloscope, students will not be able to verify whether the proper signals are being sent to the camera, or that the camera is working properly. 4. Build the Code If there is more than one project in your project view, make sure the proper project is the focus. The most reliable way to do this is to right click the project and choose Build Project as shown below. You can also go to the Project menu and choose the same command. If errors are encountered, look in the Problems view and resolve them. For now ignore any warnings. 5. Download/Debug/Run Download the code to your board, once this process is complete resume the project so that the code runs. 6. Learning Step What will happen: the function ImageCapture() is called in main.c with a pointer to the first element in the array. This function completes the processes necessary to capture images using the camera. To become more familiar with Pointers and Arrays - navigate to the C Programming Tutorial. Knowledge of Pointers and Arrays is a pre-requisite for understanding the Camera Code. Functions void CAMERA(void) {   TransmitData("****Line Sensor Test****\n\r");   SIU.PCR[27].R = 0x0200; /* Program the Sensor read start pin as output*/   SIU.PCR[29].R = 0x0200; /* Program the Sensor Clock pin as output*/   for(j=0;j<2;j++)   //for(;;)   {   SIU.PCR[27].R = 0x0200; /* Program the Sensor read start pin as output*/   SIU.PCR[29].R = 0x0200; /* Program the Sensor Clock pin as output*/   SIU.PGPDO[0].R &= ~0x00000014; /* All port line low */   SIU.PGPDO[0].R |= 0x00000010; /* Sensor read start High */   Delay();   SIU.PGPDO[0].R |= 0x00000004; /* Sensor Clock High */   Delay();   SIU.PGPDO[0].R &= ~0x00000010; /* Sensor read start Low */   Delay();   SIU.PGPDO[0].R &= ~0x00000004; /* Sensor Clock Low */   Delay();   for (i=0;i<128;i++)   {   Delay();   SIU.PGPDO[0].R |= 0x00000004; /* Sensor Clock High */   ADC.MCR.B.NSTART=1; /* Trigger normal conversions for ADC0 */   while (ADC.MCR.B.NSTART == 1) {};   adcdata = ADC.CDR[0].B.CDATA;   Delay();   SIU.PGPDO[0].R &= ~0x00000004; /* Sensor Clock Low */   Result[i] = (uint8_t)(adcdata >> 2);    }   Delaycamera();   //printlistall();   }   printlistall(); } Calling the Function within the main for loop in main.c, call the camera function using the following code: for (;;)   {   CAMERA();   } Variables Creates an 128x1 array for camera data information volatile uint8_t Result[128]; /* Read converstion result from ADC input ANS0 */   Setting threshold. (This can give you a simple view of what your camera sees without connecting it to a scope) #define THRESHOLD (2.0 /*volts*/ / 0.03125) // 8-bit A/D = 31.25mV/bit CAMERA(); // read line sensor, 128x1 pixel result returned in Result[128] array // print result for (i = 16; i < 112; ++i) // ignore the first and last 16 bits in the camera frame   if (Result[i] < THRESHOLD)   TransmitCharacter('1'); // black (low intensity)   else   TransmitCharacter('0'); // white (high intensity) Sample Code Download Link Qorivva Sample Code Download Link Alternative Examples Application Note 4244 and Software. Other Qorivva Tutorials: 1. Qorivva: Blink LED 2. Qorivva: Drive DC Motor Tutorial 3. Qorivva: Turning A Servo 4. Qorivva: Line Scan Camera Tutorial Links Qorivva Overview https://community.nxp.com/docs/DOC-1019 External TRK-MPC5064B Freescale Webpage TRK-MPC5064B Freescale Reference Manual TRK-MPC5064B Freescale Schematic
View full article
Project Summary Skills Developed: Materials: Step 0: Prerequisite Videos Step 1: Get a FRDM-JAM Step 2: Put it Together Step 3: Download Step 4: Hack and Slash! Sound Samples Utilities, etc: Project Summary MonkeyJam will use the FRDM-K20D50 board (which has a Cortex M4 core with DSP instructions) along with the FRDM-JAM shield so you can  make your very own guitar /bass  stomp box.  The end result will be a functional DSP system that will allow you to do high quality amplifier simulation and effects. The FRDM-JAM does not limit you to DSP on musical instruments!  There are 3.5mm stereo jacks to DSP filtering any type of audio signal.    You could even use the USB interface to create a USB-MIDI Synthesizer!  Lastly,  no need to bring the house down.....  a headphone amplifier circuit is provided so you can jam out without bothering the neighbors. MBED Support coming *very soon* Skills Developed: Real Time Processing DSP Algorithms Fixed Point Mathematics 24-bit I2S Data Converter Interfacing Soldering SOIC8 and 1206 Surface mount devices Cortex CMSIS DSP Library Materials: FRDM-K20D50 FRDM-JAM Development Tools Install Codewarrior 10.5 for Microcontrollers (Eclipse) Special Edition to your  machine Example Code Get the latest copy from Github Step 0: Prerequisite Videos The videos are organized into a nice YouTube playlist: H.I.T 1: Monkey Jam - YouTube https://www.youtube.com/playlist?list=PLWM8NW5LEukgM-D5eRMtKZ8R2WfXnqKGp MonkeyJam Watch Me 1st FRDM-JAM Hardware Overview MonkeyJam Software Overview Introduction to Fixed Point Math for Embedded Systems - Part 1 of 3 Introduction to Fixed Point Math for Embedded Systems - Part 2 of 3 Introduction to Fixed Point Math for Embedded Systems - Part 3 of 3 Real Time Signal Processing Part 1 of 3 Real Time Signal Processing Part 2 of 3 Real Time Signal Processing Part 3 of 3 q31_t (Q0.31) Number Format for the CMSIS DSP Libraries and the MonkeyJam Software Guitar physics in a nutshell Ideas for hacking the MonkeyJam Step 1: Get a FRDM-JAM MonkeyJam Build Package on the FRDM-JAM site.    Please let us know if you are interested in a pre-assembled version.  If there is enough demand we will get some preassembled for purchase, I will get a Kickstarter going!   Don't be afraid to build it yourself,  Soldering is fun!  There is plenty of good stuff on the web on how to do SMT soldering.  All of the parts on the board are fairly simply once you get the hang of it and everything can be hand soldered  The key is having some decent tools. Step 2: Put it Together Attach the FRDM-JAM to the FRDM-K20D50.  The FRDM-K20D50 comes with female headers that you can solder on so the boards can be easily separated.  Note that as of Rev Gamma (current version),   it is possible to connect to a K64F.    The software isn't quite there but it hardware connections are available.   If you are unsure,  stick with the FRDM-K20D50 Step 3: Download Download the Example Software from Github.  The video "Loading and Configuring the MonkeyJam Example Software" will step you though downloading the program and doing some basic configuration. Step 4: Hack and Slash! Plug In and jam! Sound Samples Each sound sample was my Carvin Ultra-V guitar plugged direct into the MonkeyJam Board.  The output was fed to a Zoom Handy Recorder H4n (Thanks to Brandin Claar of Remodulate LLC for the recorder).  The H4N recorded the signal at 44.1KHz Sample rate @16-bit.  The sound files were converted to mono format via Goldwave.  No processing (other than a  volume boost on the files) was performed.   I listen to the recording in real-time via a line out on the H4N.  File (See Attachments) Patch Notes STE-003-Neck-a12b12g12-mlike.wav PATCH_TUBEY_CLEAN Neck Pickup Alpha Pot - 12 O'Cock Beta Pot - 12 O'Cock Gamma Pot - 12 O'Cock Pattern Similar to Metallica Sanitarium STE-005-Neck-a7b5g5-mlike.wav PATCH_TUBEY_CLEAN Neck Pickup Alpha Pot - 7 O'Cock Beta Pot - 5 O'Cock Gamma Pot - 5 O'Cock Pattern Similar to Metallica Sanitarium STE-006-Neck-a12b7g5-mlike.wav PATCH_TUBEY_CLEAN Neck Pickup Alpha Pot - 12 O'Cock Beta Pot - 7 O'Cock Gamma Pot - 5 O'Cock Pattern Similar to Metallica Sanitarium STE-007-Neck-VariousSettings-d-g-em_strum.wav PATCH_TUBEY_CLEAN Neck Pickup The pots were moved around throughout the file Strummed D-Major, G-Major and E-Minor STE-008-Neck+Bridge-VariousSettings-d-g-em_strum.wav PATCH_TUBEY_CLEAN Neck + Bridge Pickup The pots were moved around throughout the file Strummed D-Major, G-Major and E-Minor STE-009-Bridge-VariousSettings-d-g-em_strum.wav PATCH_TUBEY_CLEAN Bridge + Bridge Pickup The pots were moved around throughout the file Strummed D-Major, G-Major and E-Minor STE-010-Neck-VariousSettings-Jammy.wav PATCH_TUBEY_CLEAN Neck + Bridge Pickup The pots were moved around throughout the file B-Minor Type Jam STE-011- Bridge - Various Settings - On-Off Demo-RandomDroppedD.wav PATCH_OVERDRIVE Bridge Pickup Alpha Pot - 5 O'Cock Beta Pot - 12 O'Cock Gamma Pot - 12 O'Cock Random Dropped D twiddling STE-012- Neck - Various Settings - On-Off Demo-Jammy.wav PATCH_OVERDRIVE Neck Pickup Alpha Pot - 5 O'Cock Beta Pot - 7 O'Cock Gamma Pot - 7 O'Cock Random B-Minor twiddles (bluesy) PATCH_OVERDRIVE             +––––––––––––––––––+      +––––––––––––––––––––––––––+      +–––––––––––––––––––––+                               |                  |      |                          |      |                     |                    Signal In  |    IIR BiQuad    |      |      Hard Overdrive      |      |      IIR BiQuad     |  Signal Out       +–––––––––+>|                  +––––+>|                          +––––+>|                     +–––––––––––––+>                |   [Peaking EQ]   |      | [atan24pi Look Up Table] |      |  [Low Pass Filter]  |                               |                  |      |                          |      |                     |                               +––––––––––––––––––+      +––––––––––––––––––––––––––+      +–––––––––––––––––––––+                                                                                                                                                     0.1 < Q < 1.5    [Pot Alpha]                                     Q = 0                                                                                                                                                              50 < Fs < 750    [Pot Gamma]                                   Fs = 2000                                                                                                                                                          -20 < dbGain < 20  [Pot Beta]                                                                                                                                                                                        PATCH_TUBEY_CLEAN              +––––––––––––––––––+      +––––––––––––––––––––––––––+      +–––––––––––––––––––––+                               |                  |      |                          |      |                     |                    Signal In  |    IIR BiQuad    |      |      Soft Overdrive      |      |      IIR BiQuad     |  Signal Out       +–––––––––+>|                  +––––+>|                          +––––+>|                     +–––––––––––––+>                |     [LowShelf]   |      | [atan4pi Look Up Table]  |      |  [Low Pass Filter]  |                               |                  |      |                          |      |                     |                               +––––––––––––––––––+      +––––––––––––––––––––––––––+      +–––––––––––––––––––––+                                                                                                                                                     0.05 < Q < 2.58   [Pot Alpha]                                     Q = 2.0                                                                                                                                                             1000 < Fs < 4000    [Pot Beta]                                   Fs = 2500                                                                                                                                                      -15 < dbGain < 15  [Pot Gamma]                                                                                                                                                                                    Utilities, etc: Biquad Filter View - A IIR Biquad Filter Design &amp; Visualization Tool
View full article
This tutorial covers the details of Driving a motor on the Qorivva TRK-MPC5604B: MPC5604B StarterTRAK evaluation board. Overview 1. Put together the Car Chassis: Motor Controller Board Version A. 2. Import the Sample Project 3. Build the Code 4. Download/Debug/Run 5. Learning Step: DC Motor Code Description Functions Motor_Right () & Motor_Left() Motor_Right_Current () & Motor_Left_Current() Sample Code Download Link Alternative Examples: Other Qorivva Tutorials: Useful Technical Links Overview In this exercise students will utilize the sample project to turn a DC motor on an off using the Qorivva TRK-MPC5604B board. Students will: Put together the car chassis Open the Sample Project Make changes to main.c to call the motor functions Build the Motor function code Download and run the code on a Qorivva TRK-MPC5604B board. Learn how the code works To successfully complete this exercise students will need the following board and development environment. Qorivva TRK-MPC5604B board. Freescale Cup Chassis (connector for the motor/board) Motor Drive Version A board Kit Cables and interconnects 7.2v Nicad Battery CodeWarrior for Microcontrollers V2.8 Recommend completing the the Blink LED Tutorial Motor Example code 1. Put together the Car Chassis:   There are several steps in this process: Build the Freescale Cup Car Chassis Add the Qorivva-Mpc560xb version components to the chassis The first step of this tutorial is to gain background information on background information on motors, timer modules, PWM signals and counters. To learn more about these general topics read the Drive A DC Motor overview article. You will need to connect your motor to the microcontroller via the Motor Drive board. This board is connected to the battery, and serves to power the motors. separate power source. This is an easy process using the provided Motor Controller Board. Motor Controller Board Version A. The Freescale Cup Motor Drive VA board uses the following connector type: white 3 pin connectors (for motor) (Molex 3-pin .100") white 2 pin connector (for battery) (Molex 2-pin .100") Schematics Wiring Connections for the TRK-MPC5604B 2. Import the Sample Project The next step is to import an existing project into your Workspace. in this case, the TRK-MPC5604B Sample project. Follow the instructions on the codewarrior project import page if you can't remember how to to import the project into CodeWarrior. 3. Build the Code If you have more than one project in your project view, make sure the proper project is the focus. The most reliable way to do this is to right click the project and choose Build Project as shown below. You can also go to the Project menu and choose the same command. If you encounter errors, look in the Problems view and resolve them. You can ignore any warnings. 4. Download/Debug/Run 5. Learning Step: DC Motor Code Description What will happen: This demo is setup for two motors (one left and one right). You will then independently turn on and off each motor Functions This file sets up the Pulse Width Modulation Timer Module for use by a DC Motor. It is set to utilize Edge-Aligned PWM, and this file properly configures the period, and pulse width for use by the other modules Motor_Right () & Motor_Left() void MOTOR_LEFT(void) {   TransmitData("****Left Drive Motor Test****\n\r");   SIU.PCR[16].R = 0x0200; /* Program the drive enable pin of Left Motor as output*/   SIU.PGPDO[0].R = 0x00008000; /* Enable Left the motors */   Delaywait();   SIU.PGPDO[0].R = 0x00000000; /* Disable Left the motors */ } void MOTOR_RIGHT(void) {   TransmitData("****Right Drive Motor Test****\n\r");   SIU.PCR[17].R = 0x0200; /* Program the drive enable pin of Right Motor as output*/   SIU.PGPDO[0].R = 0x00004000; /* Enable Right the motors */   Delaywait();   SIU.PGPDO[0].R = 0x00000000; /* Disable Right the motors */ } Motor_Right_Current () & Motor_Left_Current() void RIGHT_MOTOR_CURRENT(void) {   TransmitData("****Right Motor Current****\n\r");   SIU.PGPDO[0].R = 0x00004000; /* Enable Right the motors */   Delaywait();   for (i=0;i <10;i++)   {   ADC.MCR.B.NSTART=1; /* Trigger normal conversions for ADC0 */   while (ADC.MSR.B.NSTART == 1) {};   curdata = ADC.CDR[2].B.CDATA;   printserialsingned(curdata);    }   SIU.PGPDO[0].R = 0x00000000; /* Disable Right the motors */ } void LEFT_MOTOR_CURRENT(void) {   TransmitData("****Left Motor Current****\n\r");   SIU.PGPDO[0].R = 0x00008000; /* Enable Right the motors */   Delaywait();   for (i=0;i <10;i++)   {   ADC.MCR.B.NSTART=1; /* Trigger normal conversions for ADC0 */   while (ADC.MSR.B.NSTART == 1) {};   curdata = ADC.CDR[1].B.CDATA;   printserialsingned(curdata);    }   SIU.PGPDO[0].R = 0x00000000; /* Disable Right the motors */ } Sample Code Download Link Qorivva Sample Code Download Link Alternative Examples: Application Note 4251 and Software. Other Qorivva Tutorials: Qorivva: Blink a Led Tutorial Qorivva: Turning a Servo Tutorial Qorivva: Line Scan Camera Tutorial Useful Technical Links TRK-MPC5064B Freescale Webpage TRK-MPC5064B Freescale Reference Manual TRK-MPC5064B Freescale Schematic
View full article
This tutorial covers the details of Blinking an LED on the TRK-MPC5604B: MPC5604B StarterTRAK evaluation board. It will introduce the evaluation board, and some basic CodeWarrior features. Overview Hardware Set up the Software Development Environment A. Download and Install Codewarrior B. Download and Install Drivers Sample Code Serial Debugging: I made the hardware modifications for serial debugging: I did not make the hardware modifications for serial debugging: Download/Debug/Run Learning Step: LED Code Description Functions Blink the LED(s): Other Qorivva Tutorials Useful Links to Technical Data Overview In this exercise students will run sample code and build an application which enables testing of the Qorivva TRK-MPC5604B board. Students will: Configure the Software Development Environment Configure the evaluation board hardware Learn how to open CodeWarrior project example files Build a project Download and run the code on TRK-MPC5604B board Learn how to utilize the GPIO Peripheral to blink a LED   To successfully complete this exercise, students will need the following board and development environment. TRK-MPC5604B evaluation board CWX-MPC-5500P-EX: Evaluation: CodeWarrior for MPC55xx/MPC56xx Microcontrollers V2.8 (Classic) RAppID initialization Tool P&E Micro Driver Software Hardware Read the MCU 101: LEDs article for general information on LED circuits. The LED's are located on the board and visible in the board schematic on page 4 as below: This schematic is found here. Set up the Software Development Environment There are several steps necessary to prepare the evaluation board and PC for microcontroller programming and development. Interfacing the evaluation board with a PC requires downloading and installing the CodeWarrior IDE, as well as the device drivers for programming the microcontroller via USB. A. Download and Install Codewarrior Before completing this example project, download and install CodeWarrior for MPC56xx 2.8 or the latest version. B. Download and Install Drivers In addition to CodeWarrior, it may (needs verified) be necessary to install one or both of the following tools: RAppID initialization tool- RAppID comes on the DVD provided with your evaluation board. In the main directory of the DVD, click on the "TRK_MPC5604B.html" file to open the DVD interface which provides user manuals, software, schematics and documentation for the evaluation board. P&E Microcomputer Systems, Inc drivers- P&E is a a computer driver for the TRK-MPC5604B device, enabling evaluation board programming via USB through the CodeWarrior debug OSJTAG interface. This driver can be downloaded here Because this isn't found on the disk. Sample Code To use the Hyperterminal communications features described in the following sections and in the attached sample code you must populate the U5 on your TRK-MPC5604B board. Qorivva Sample Code Download Serial Debugging: To use hyperterminal style debugging through the Serial port you must populate U5 with a RS232 transceiver and C55. I made the hardware modifications for serial debugging: From the Start menu Run the hyper terminal by using All programs> Accessories> Communications> HyperTerminal and make COMx properties port s ettings as Baud rate 115200, Data bits 8, Parity None, Stop bits 1 and Flow control None. 8. In the project menu select make (or F7) you will get few warning messages. I did not make the hardware modifications for serial debugging: In the project menu select MAKE (or F7) you will get few warning messages and can ignore them. Next select Debug option (or F5) from project menu. The debug window opens with few sub windows such as Code, Status and CPU etc. To run the program, select the Source GO menu button. Note: Much of the code in the sample file is utilized to send and receive messages serially. Some quick, minor changes can be applied as follows: Open main.c within the for loop, remove or comment out all the code. Now, manually call the specific function desired, in this case: for (; ; )      {           LED();      } Download/Debug/Run In sample.mcp project manager window target selection window is set to the default RAM. This means the code runs in the RAM. This target option can be changed using the drop down menu to internal_FLASH. This means the code runs in the flash and this code can run without debugger when the board is powered up. You can select either RAM target or internal_FLASH target for the following test procedure. If you select internal_FLASH target you can test the standalone operation of the board. If you encounter errors, look in the Problems view and resolve them. You can ignore any warnings. If the project builds correctly, it is time to download to the board and watch it work. Ensure that the USB cable that came with the board connects the board to the host computer’s USB port. There are multiple ways to issue the Debug command. Right click the project in the projects view and choose Debug As->CodeWarrior Download. Alternatively, y go to the Run menu and choose Debug (F11). Learning Step: LED Code Description Within the sample code, there is a for loop which calls a switch statement. With working hyper-terminal and proper serial connector interface into a PC, entering the numerical characters "1" - "9" into the hyper-terminal will call each separate function initiating the following actions Blinks Leds & outputs text strings to hyperterminal Calls the Switch function - which sends text strings to hyperterminal indicating which switch has been pressed Calls the Servo function which sweeps the servo back and forth; sends text strings to hyperterminal Calls the motor function which enables and disables the left motor; sends status text strings to hyperterminal Calls the motor function which enables and disables the right motor; sends status text strings to hyperterminal Calls the Camera function which sends the correct signals to the camera and reads the data; sends status text strings to hyperterminal Calls the Left_Motor_Current function; sends status text strings to hyperterminal Calls the Right_Motor_Current function; sends status text strings to hyperterminal   (hyperterminal code documentation needs verified ) TransmitData("\n\r**The Freescale Cup**");         TransmitData("\n\r*********************");         TransmitData("\n\r1.Led\n\r");         TransmitData("2.Switch\n\r");         TransmitData("3.Servo\n\r");         TransmitData("4.Motor Left\n\r");         TransmitData("5.Motor Right\n\r");         TransmitData("6.Camera\n\r");         TransmitData("7.Left Motor Current\n\r");         TransmitData("8.Right Motor Current");         TransmitData("\n\r**********************"); option = ReadData(); option = 1;     switch(option)         {             case '1':                 LED();             break;             case '2':                 SWITCH();             break;             case '3':                 SERVO();             break;             case '4':                 MOTOR_LEFT();             break;             case '5':                 MOTOR_RIGHT();             break;             case '6':                 CAMERA();             break;             case '7':                 LEFT_MOTOR_CURRENT();             break;             case '8':                 RIGHT_MOTOR_CURRENT();             break;             default:             break;          } As visible from the schematic - the LED's are accessed via the following ports. Hardware Chip Port/Pin Comment LED1 PE4 LED2 PE5 LED3 PE6 LED4 PE7 Functions The following function is utilized in the code to blink the LED's This function is located in main.c void LED(void) {    SIU.PCR[68].R = 0x0200;  /* Program the drive enable pin of LED1 (PE4) as output*/    SIU.PCR[69].R = 0x0200;  /* Program the drive enable pin of LED2 (PE5) as output*/    SIU.PCR[70].R = 0x0200;  /* Program the drive enable pin of LED3 (PE6) as output*/    SIU.PCR[71].R = 0x0200;  /* Program the drive enable pin of LED4 (PE7) as output*/    TransmitData("****Led Test****\n\r");    TransmitData("All Led ON\n\r");    Delayled();    SIU.PGPDO[2].R |= 0x0f000000;  /* Disable LEDs*/    SIU.PGPDO[2].R &= 0x07000000;  /* Enable LED1*/    TransmitData("Led 1 ON\n\r");    Delayled();    SIU.PGPDO[2].R |= 0x08000000;  /* Disable LED1*/    SIU.PGPDO[2].R &= 0x0b000000;  /* Enable LED2*/    TransmitData("Led 2 ON\n\r");    Delayled();    SIU.PGPDO[2].R |= 0x04000000;  /* Disable LED2*/    SIU.PGPDO[2].R &= 0x0d000000;  /* Enable LED3*/    TransmitData("Led 3 ON\n\r");    Delayled();    SIU.PGPDO[2].R |= 0x02000000;  /* Disable LED3*/    SIU.PGPDO[2].R &= 0x0e000000;  /* Enable LED4*/    TransmitData("Led 4 ON\n\r");    Delayled();    SIU.PGPDO[2].R |= 0x01000000;  /* Disable LED4*/ } Code Details: SIU - System Integration Unit PCR - Port Configuration Register PGPDO - Parallel GPIO Pad Data Output Registers : definition From viewing the user manual, under Functional port pin descriptions, it is Blink the LED(s): Within the main find the infinite for loop. for ( ; ; )      {      } loop of Main.c, remove all code, and add the LED's with the following function: for(;;) { LED(); } To alter the behavior of the LEDs, change the function itself, or pull specific code from the function and insert it within loops of a program for testing purposes. LED's are often used for testing important parts of an algorithm. By connecting an oscilloscope to a LED, it is possible to test the duration of a key algorithm, or to verify if signal timing is as expected along with the visual cue. Other Qorivva Tutorials Qorivva: Drive DC Motor Tutorial Qorivva: Turning A Servo Qorivva: Line Scan Camera Tutorial Useful Links to Technical Data TRK-MPC5064B Freescale Webpage TRK-MPC5064B Freescale Reference Manual TRK-MPC5064B Freescale Schematic
View full article
Take some time to get yourself familiar with C programming before you continue on the programming tutorial. Here is a list of topics that you should be comfortable with, and a couple of good tutorials below. Topics included: Program Structure Commenting Variables Keywords Data Types Decimal, Binary and Hexadecimal Equivalents ASCII Text/Number Conversion Math Operators Increment & Decrement Shift Logical Operators Bitwise Operators Loops If Statement Switch Statement Functions Recursion Local Variables vs. Global Arrays Pointers Typdef, struct and union Preprocessor Directives Static, const and Volatile Keywords Tutorial 1: PSU Intro to C for Embedded Design   From PSU Freescale Cup Senior Design Course Tutorial 2: Learning Programming with C This Freescale course consists of a collection of lessons that will introduce you to the fundamentals of programming using the C programming language. Coding for Readability Sometimes when a project has the ability to grow with new features, it is best to code in modules. This allows one to easily take a more modular approach to designing their program. Despite the fact that C does not support Classes like C++ does, you can create structures that can be addressed globally with little code, which is especially useful for microcontroller based projects. An example of a structure which will be made global: This goes in the globals.h file typedef struct {   unsigned char ServoPWM;   char ServoAngle;   unsigned char DrivePWM;   int TimeOut;   int Current;   int Speed; } sMotor; extern volatile sMotor Motor; This will go in any other file that we want our structure to be accessible from #include <Globals.h> volatile sMotor Motor; This is how to address the variable in the structure #include <Globals.h> volatile sMotor Motor; If you decided to have two distinguishable motors you could do this in the globals.h extern volatile sMotor Motor1; extern volatile sMotor Motor2; Then do this in the other files volatile sMotor Motor1; volatile sMotor Motor2; Helpful Hints In developing an algorithm to detect the line position, we found two basic errors in the coding practice which caused catastrophic errors in line detection. Both of these tips are very basic coding practice. First, when using C code, it usually benefits the user to initialize all variables to some value, especially if computations are involved. Often times when the value wasn't initialized it would seem to acquire a wrong value seemingly from nowhere. Secondly, when doing calculations with arrays, make sure to do calculations with array indices that actually exist. Many times we would make the mistake in our loops of trying to use an index that wasn't assigned a value. Therefore it would acquire an unknown value from memory that caused errors in our calculations.
View full article
1. Overview 2. Hardware 3. Set up the Hardware: Line Scan Camera/Microcontroller Hardware Setup 4. Build the Code 5. Download/Debug/Run 6.Example Code Functions ImageCapture(); ReadADCChannel() Initialize the ADC Header File Definitions Initialize the GPIO Other Tutorials: This tutorial covers the details of obtaining data from the line scan camera on the Kinetis K40 using the TWR-K40X256-KIT evaluation board. General details of the line scan camera not related to the Kinetis can be found in the general Line Scan Camera Theory article. This tutorial will help students familiarize themselves with how to interface the camera with the microcontroller, how to configure GPIO pins to create clock signals and also how to utilize the microcontroller's ADC to read the data from the camera. Outside of control algorithms, configuring the camera is one of the more complex tasks necessary to create a Freescale Cup Vehicle. 1.  Overview In this exercise students will access the line scan camera, create a clock signal and create the initialization pulse which tells the camera to begin the exposure period. This tutorial will not describe line recognition or line following algorithms - these concepts are beyond its scope. Students will: Create the code using Codewarrior Build a project Download the code to the board connect the microcontroller to the camera. Run the program view the camera data, clock and Si pulse on an oscilloscope view the data from the camera in the CodeWarrior Debugger for verification purposes   To successfully complete this exercise, the following software and hardware are required: The K40 Tower card, TWR-K40x256 CodeWarrior for Microcontrollers Freescale Line Scan Camera Motor Board Tower Prototyping board Soldering Iron Solder Tower Elevators USB Cord 2. Hardware   Read the Line Scan Camera Overview article for general information on the camera, ADC, and GPIO microcontroller configuration settings. 3. Set up the Hardware: Line Scan Camera/Microcontroller Hardware Setup It is crucial for an engineer to have the proper test equipment and tools for the job. In this case, without an oscilloscope, students will not be able to verify whether the proper signals are being sent to the camera. 4. Build the Code If there is more than one project in your project view, make sure the proper project is the focus. The most reliable way to do this is to right click the project and choose Build Project as shown below. You can also go to the Project menu and choose the same command. If errors are encountered, look in the Problems view and resolve them. For now ignore any warnings. 5. Download/Debug/Run Download the code to your board, once this process is complete resume the project so that the code runs. If you want more information on how to complete this step see the download debug run section of the Kinetis Blinking Led tutorial. 6.Example Code What will happen: the function ImageCapture() is called in main.c with a pointer to the first element in the array. This function completes the processes necessary to capture images using the camera. To become more familiar with Pointers and Arrays - navigate to the C Programming Tutorial. Knowledge of Pointers and Arrays is a pre-requisite for understanding the Camera Code. Functions The camera code utilizes the following function: within main.c ImageCapture(&Line.RawCameraData[0]); is called to initiate the step of capturing an image into the first position of the array. ImageCapture(); from Camerainterface.c This function captures the images by creating the SI Pulse, and clock signals, capturing the data into an Array using the ADC features of the K40. It calls the function ReadADCChannel() at the proper time which then inputs data from the camera AO line. void ImageCapture(int * ImageData){//this is a pointer to a single character in memory   unsigned char i;   TAOS_SI_HIGH;   TAOS_EXPOSURE_DELAY;   TAOS_CLK_HIGH;   TAOS_EXPOSURE_DELAY;   TAOS_SI_LOW;   TAOS_EXPOSURE_DELAY;   ImageData[0] = (int)ReadADCChannel(19);// inputs data from camera (first pixel)   TAOS_CLK_LOW;   for(i=1;i<128;i++)   {   TAOS_EXPOSURE_DELAY;   TAOS_EXPOSURE_DELAY;   TAOS_CLK_HIGH;   TAOS_EXPOSURE_DELAY;   TAOS_EXPOSURE_DELAY;   ImageData[i] = (int)ReadADCChannel(19); // inputs data from camera (one pixel each time through loop)   TAOS_CLK_LOW;   }   TAOS_EXPOSURE_DELAY;   TAOS_EXPOSURE_DELAY;   TAOS_CLK_HIGH;   TAOS_EXPOSURE_DELAY;   TAOS_EXPOSURE_DELAY;   TAOS_CLK_LOW;  } ReadADCChannel() from readADC.c this function does the analog to digital conversion and returns a value between 0 and 255. It takes the proper ADC channel, in this case 19. Channel 19 corresponds to analog input pin ADC1_DM0 (see page 117 in the K40 Sub-Family Reference Manual). unsigned char ReadADCChannel(unsigned char Channel)   {   ADC1_SC1A = Channel;   while((ADC1_SC1A & ADC_SC1_COCO_MASK) == 0)   {   }   return ADC1_RA;    } Initialize the ADC Before utilizing the ADC it must be calibrated and initialized. The details for how to do this can be found in Chapter 19 Using Peripheral Delay Block (PDB) to Schedule Analog to Digital Converter (ADC) Conversions of the Kinetis Peripheral Module Quick Reference manual. The PDB portions of the code have been removed for the Cup Car Demo Code. Header File Definitions from k40_TOWER_BOARD_SUPPORT.h The following code enables the GPIO on the two pins: #define TAOS_CLK_LOC (1<<28) #define TAOS_SI_LOC (1<<18) Initialize the GPIO From K40_TOWER_BOARD_SUPPORT.c The InitK40GPIO Function sets up the ports for use: Relevant code SIM_SCGC5 = SIM_SCGC5_PORTA_MASK | SIM_SCGC5_PORTB_MASK | SIM_SCGC5_PORTC_MASK | SIM_SCGC5_PORTD_MASK | SIM_SCGC5_PORTE_MASK; //CLK and SI signal PORTC_PCR18 = PORT_PCR_MUX(1) | PORT_PCR_DSE_MASK; PORTE_PCR28 = PORT_PCR_MUX(1) | PORT_PCR_DSE_MASK; //Make Sure the GPIO is setup to be an output GPIOC_PDDR |= LED_E1_LOC | LED_E2_LOC | LED_E3_LOC | TAOS_SI_LOC; GPIOE_PDDR |= TAOS_CLK_LOC; GPIOB_PDDR |= LED_E4_LOC; Other Tutorials: K40:Blinking LED Tutorial K40:Drive DC Motor Tutorial K40:Turning a Servo Tutorial   
View full article
This tutorial covers the details of Blinking an LED on the Kinetis K40 using the TWR-K40X256-KIT evaluation board. It will introduce the evaluation board, and some basic CodeWarrior features. Overview 1. Hardware 2. Set up the Software Development Environment A. Download and Install Codewarrior B. Download and Install Drivers 3. Set up the Hardware: Twr K40x256 Hardware Setup 4. Import the LED Project 5. Build the Code 6. Download/Debug/Run 7. Learning Step: LED Code Description Read/Write Functions Variables Header File Definitions Initialize the GPIO Blink the LED: Other K40 Tutorials: K40 Related Pages Credits / References Overview   In this exercise students will explore a Freescale Cup Car application which targets a Freescale K40 board attached to the Tower System.   Students will: Configure the Software Development Environment Configure the evaluation board hardware Learn how to import example files into a CodeWarrior project Build a project Download and run the code on a Kinetis K40 Tower System board Learn how to utilize the GPIO Peripheral to blink a LED     To successfully complete this exercise, students will need the following board and development environment. The K40 Tower card, TWR-K40x256 CodeWarrior for Microcontrollers USB Cord 1. Hardware     Read the Blink LED overview article for general information on LED circuits, GPIO pins and reference manuals.   2. Set up the Software Development Environment   There are several steps necessary to prepare the evaluation board and PC for microcontroller programming and development. Interfacing the evaluation board with a PC requires downloading and Install the CodeWarrior IDE, as well as the device drivers for programming the microcontroller via USB. A. Download and Install Codewarrior   Before completing this example project, download-and-install-codewarrior-10-1 or the latest version compatible with the twr-k40x256-kit.   B. Download and Install Drivers   In addition to CodeWarrior, it may(needs verified) be necessary to install one or both of the following tools: RAppID initialization tool- RAppID comes on the DVD provided with your evaluation board. In the main directory of the DVD, click on the "TRK_MPC5604B.html" file to open the DVD interface which provides user manuals, software, schematics and documentation for the evaluation board. P&E Microcomputer Systems, Inc drivers- P&E is a a computer driver for the TRK-MPC5604B and Kinetis Tower system device, enabling evaluation board programming via USB through the CodeWarrior debug OSJTAG interface. This driver can be downloaded here in case this isn't found on the disk.   3. Set up the Hardware: Twr K40x256 Hardware Setup   There are several Twr K40x256 hardware configuration steps. Follow the twr-k40x256-hardware-setup instructions before importing the LED Project. 4. Import the LED Project   After the software is successfully downloaded and installed, the next step is to import an existing project into your Workspace. in this case, the LED_BLINK_96MHZ Project. Follow the instructions on the codewarrior-project-import page to import the LED_BLINK_96MHZ project into CodeWarrior. If errors are encountered, look in the Problems view and resolve them. Ignore any warnings. 5. Build the Code   If there is more than one project in your project view, make sure the proper project is the focus. The most reliable way to do this is to right click the project and choose Build Project as shown below. You can also go to the Project menu and choose the same command. By default, the application is set to link to RAM. If you want your program in FLASH, make sure that you have that build configuration enabled:     Make sure you do a "Clean" operation (under the project menu) after you make the configuration change. If you encounter errors, look in the problems view and resolve them. You can ignore any warnings. 6. Download/Debug/Run   If the project builds correctly, it is time to download to the board and watch it work. Ensure that the USB cable that came with the board connects the board to the host computer’s USB port. There are multiple ways to issue the Debug command. Right click the project in the projects view and choose Debug As->CodeWarrior Download. Alternatively, y go to the Run menu and choose Debug (F11). Click the Resume button and your should see the LED blinking! Click the Pause button to stop execution. Click the Terminate button to end debugging. 7. Learning Step: LED Code Description Read/Write   If the LED was on Port C, Bit 7 we might have code like: #define LED_E1_Location(1<<7)   For example, to toggle a pin the following code might be used: GPIOC_PSOR=LED_E1_LOC     "Sets" the LED located at "E1" high.   the syntax means the following GPIOC refers to Port C   "Set" is one of three commonly utilized commands for GPIO control. There are also commands for "Clear" and "Toggle."   Command: "GPIOC_PSOR" literally means PORT SET OUTPUT REGISTER which SETS a pin high Command: "GPIOC_PCOR" clears a pin, PORT CLEAR OUTPUT REGISTER which CLEARS a pin to the "low" state Command: "GPIOC_PTOR" toggles a pin opposite of the current state   the « is a "shift" command which is discussed in the c-programming-for-embedded-systems. You can alter the raw register as well using a MASK but the dedicated set/clear/toggle registers are more straightforward.   **NEEDS UPDATED ** Hardware Chip Port/Pin Comment SW3 PT cell-content SW4 cell-content cell-content Functions   The following functions can access the LED; //Where n is the LED number LED_En_TOGGLE;  //will toggle a LED to a different state LED_En_ON; // turns the LED ON LED_En_OFF // turns the LED OFF Variables   Locations of the LED's LED_E1_LOC LED_E2_LOC LED_E3_LOC LED_E4_LOC Header File Definitions   from k40_TOWER_BOARD_SUPPORT.h //The E1 LED is on Port C, Bit 7 #define LED_E1_LOC (1<<7) #define LED_E2_LOC (1<<8) #define LED_E3_LOC (1<<9) #define LED_E4_LOC (1<<11)    //There are dedicated set and clear registers.    //Write a one to PSOR Sets the Bits, Writing to PCOR clears bits.    //Toggling a bit can be done with the PTOR register    //You can access the raw register as well -> PDOR |= My Bit    //but the dedicated bit set/clear/toggle registers are easier!    //Also, The cathode of the LEDs are towards the port pin! This means    //you have to turn the port off to get the LED to turn the pin on. #define LED_E1_OFF   GPIOC_PSOR=LED_E1_LOC #define LED_E1_ON   GPIOC_PCOR=LED_E1_LOC #define LED_E1_TOGGLE   GPIOC_PTOR=LED_E1_LOC #define LED_E2_OFF   GPIOC_PSOR=LED_E2_LOC #define LED_E2_ON   GPIOC_PCOR=LED_E2_LOC #define LED_E2_TOGGLE   GPIOC_PTOR=LED_E2_LOC #define LED_E3_OFF   GPIOC_PSOR=LED_E3_LOC #define LED_E3_ON   GPIOC_PCOR=LED_E3_LOC #define LED_E3_TOGGLE   GPIOC_PTOR=LED_E3_LOC #define LED_E4_OFF   GPIOB_PSOR=LED_E4_LOC #define LED_E4_ON   GPIOB_PCOR=LED_E4_LOC #define LED_E4_TOGGLE   GPIOB_PTOR=LED_E4_LOC Initialize the GPIO   From K40_TOWER_BOARD_SUPPORT.c void InitK40GPIO() {    SIM_SCGC5 = SIM_SCGC5_PORTA_MASK | SIM_SCGC5_PORTB_MASK | SIM_SCGC5_PORTC_MASK | SIM_SCGC5_PORTD_MASK | SIM_SCGC5_PORTE_MASK;    //To use a Port, its Clock must be enabled!!    //Lets just enable the clocks for ALL of the ports    //Important! Each IO pin has a dedicated 32-bit Register to set it up (Selection GPIO vs peripheral, IRQ, Etc.)    //Setup port C7,C8,C9 and B11 as GPIO and enable High Drive Strength    PORTC_PCR7 = PORT_PCR_MUX(1) | PORT_PCR_DSE_MASK;  //Enable GPIO on on the pin    PORTC_PCR8 = PORT_PCR_MUX(1) | PORT_PCR_DSE_MASK;  //Enable GPIO on on the pin    PORTC_PCR9 = PORT_PCR_MUX(1) | PORT_PCR_DSE_MASK;  //Enable GPIO on on the pin    PORTB_PCR11 = PORT_PCR_MUX(1) | PORT_PCR_DSE_MASK;  //Enable GPIO on on the pin    PORTC_PCR18 = PORT_PCR_MUX(1) | PORT_PCR_DSE_MASK;    PORTE_PCR28 = PORT_PCR_MUX(1) | PORT_PCR_DSE_MASK;    //Make Sure the GPIO is setup to be an output    GPIOC_PDDR |= LED_E1_LOC | LED_E2_LOC | LED_E3_LOC;    GPIOB_PDDR |= LED_E4_LOC;    LED_E1_OFF;    LED_E2_OFF;    LED_E3_OFF;    LED_E4_OFF; } Blink the LED:   Within Main.c or any other C file created, Blink the LED's using the following functions: LED_E1_TOGGLE; LED_E1_ON; LED_E2_OFF; Other K40 Tutorials:   K40 Related Pages   K40: Turning A Servo Tutorial   K40: Drive DC Motor Tutorial Kinetis K40 TWR-K40X256 K40: Blinking LED Credits / References   Some of the content from this tutorial originated from:   Shawn Moffit: Electrical Engineering, Penn State University for - K40 Code   Processor Expert Hands-On Lab Rev. 1.0, 05/2011 by Jim Trudeau, Freescale Semiconductor, Inc. for - some text descriptions of steps Original Attachment has been moved to: LED_BLINK_96MHZ.zip
View full article
The file contains the rules for The NXP Cup EMEA 2016-2017 edition of the challenge. Revision 1 dated 13-Jul-2016 For any question : [email protected]
View full article