S12 / MagniV Microcontrollers Knowledge Base

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

S12 / MagniV Microcontrollers Knowledge Base

Labels

Discussions

Sort by:
The S12Z MCU has linear address space therefore constant, variable, code placement is easier in compare with older S12 or S12X MCUs. But still, there are several ways and potential issues.   The object placement is made by Smart Linker. The linker configuration is defined by settings in project *.prm file and also by linker command line options (menu - Project – Properties – C/C++ Build – Settings – S12Z Linker). The detail information about linker options may be found in MCU_Build_Tools_Utilities.pdf with default path: "c:\Freescale\CW MCU v10.7\MCU\Help\PDF\MCU_Build_Tools_Utilities.pdf"   We may define memory segments in *.prm linker file. The default prm file contains segments for RAM, EEPROM, and ROM (Flash). The sizes of these segments typically reflect our MCU derivative physical memory map, but we may redefine that and use more virtual segments per our needs. The physical/virtual segments definition in prm linker file is located at: SEGMENTS // segments definition END‍‍‍‍‍‍   The general data placement may be divided into two main approaches: Manual – the programmer will specify fix address for some of the data Automatic – the placement will be driven automatically by Smart Linker   Manual placement The first option is an exact specification of specific content at a specific address. This may be managed for a small amount of data by FILL linker command in *.prm linker parameter file. For example: SEGMENTS //… ROM_CONST       = READ_ONLY   0xFE0000 TO 0xFE0000 FILL 0x5A;  //insert 0x5A value at address 0xFE0000 //… END‍‍‍‍‍‍‍‍‍‍ Such placement isn’t very comfortable, but it might be simply used for some configuration data out of project code. Note: you may use more than one bytes (e.g. FILL 0x0A 0x34). If segment size is bigger than a number of specified bytes, the bytes will be used as a pattern for filling whole target segment. Note: The potential linker placement will overlap such defined data.   The next option is using address specification by an @ qualifier directly in C code. For example: unsigned const int rom_const @0xFE0100 = 0x5AA5;‍‍ This may be used also for more complex types than simple byte – typically arrays,...   Since such type of placement is still manual, the linker parameters must be configured for avoiding possible overlapping. Be aware! The default CW project has disabled memory overlapping warnings. So, we must exclude target memory area from linker using. For example, in the *.prm file: SEGMENTS //… ROM_1           = READ_ONLY   0xFE0000 TO 0xFE00FF //ROM_CONST  = READ_ONLY   0xFE0100 TO 0xFE0101;            //we use the 0xFE0100 byte for rom_const ROM_2           = READ_ONLY   0xFE0102 TO 0xFFFDFF //… END‍‍‍‍‍‍‍‍‍‍‍‍‍‍ Note: We use qualifiers for define memory access type. READ_ONLY is used for Flash, READ_WRITE for RAM and NO_INIT for RAM where we do not want to initialize data after reset. Sections placed in an NO_INIT segment should not contain any initialized variables (variable defined as int c = 8).   Note: The manual placement may be also implemented by assembler code. For example: XDEF MyVariable MyVariable: equ $1100‍‍‍‍ However, also in this case, we must exclude target memory area from linker use like in the case of @ qualifier for avoiding memory overlapping.   Automatic placement by linker The PLACEMENT block allows us to physically place each section from the application in a specific memory area (segment). The sections specified in a PLACEMENT block may be linker-predefined sections (like DEFAULT_ROM, DEFAULT_RAM, COPY, SSTACK,…) or user sections specified in one of the source file building the application (like MY_RAM,…). PLACEMENT // section(s) INTO segment(s); MY_CODE INTO ROM_1; END‍‍‍‍‍‍‍‍ Note: Since the linker is case sensitive, the name of the section names specified in the PLACEMENT block must be valid predefined or user-defined section names. Note: There is quite mess in ELF/Freescale section/segment terminology. Please take this information as simplified as possible. Please look at MCU_Build_Tools_Utilities.pdf for more details about predefined segments/sections. Note: We may place a various number of sections into a various number of segments. The “,” is used as section/segment delimiter. Note: In general, the placement order is given by simple list order (first specified section will be allocated from first specified segment, after that next section …). But, there are still few limitations for sections list order. The error is generated in the case of wrong list order – for example: ERROR L1122: only checksum section may be behind .copy in the section list.   The default variable/constant/code placement may be changed by #pragma commands. Note: Most of these pragma commands are not limited to the single file. Therefore, we should keep it in complementary pairs. An example of placing code into specific section: #pragma CODE_SEG MY_CODE void f(void) { //… } #pragma CODE_SEG DEFAULT‍‍‍‍‍‍‍‍‍‍‍‍ The #pragma DATA_SEG modifies variable placement. For example: #pragma DATA_SEG MY_RAM unsigned int counter; //… #pragma DATA_SEG DEFAULT‍‍‍‍‍‍‍‍   The #pragma CONT_SEG modifies variable placement. For example: #pragma CONT_SEG MY_ROM const unsigned int my_parameter; //… #pragma CONT_SEG DEFAULT‍‍‍‍‍‍‍‍   Note: The shorter option for directly allocating variables in a named segment, rather than using a #pragma may be used. For example: unsigned int counter@"MY_RAM";‍‍ However, even in such case, the #pragma command like #pragma DATA_SEG MY_RAM must be used at least once prior that variable declaration.   Note: The S12Z compiler/linker allows to use also already predefined sections like DEFAULT_ROM, DEFAULT_RAM or ROM_VAR as target sections in #pragma commands (not possible in the case of older S12(X) compiler/linker).     More details about #pragma commands may be found in MCU_S12Z_Compiler.pdf with default path: "c:\Freescale\CW MCU v10.7\MCU\Help\PDF\MCU_S12Z_Compiler.pdf" Data alignment Sometimes we need to keep allocated data aligned. This is for example typical requirement for ADC command and result list where DMA is used for transfer data between ADC module and memory. The simplest method is using alignment attribute. For example: volatile unsigned long adc0_cmdlist[NR_A_CH] __attribute__ ((aligned (4))); //max 256 bytes = 64 commands per 4-byte entries volatile unsigned int adc0_results[NR_A_CH] __attribute__ ((aligned (4)));  //max 128 bytes = 64 results per 2-byte entries‍‍‍‍ I hope it helps you. Best regards Radek
View full article
The example code demonstrates MCU low power modes: STOP and WAIT. For detailed description see main.c file of the project. * - tested on X-VLG-S12ZVC board * - BUSCLK = 6.25MHz based on internal oscillator clock IRCCLK = 1MHz.The PLL set by default in PEI mode. * - Reference documentation: MC9S12ZVCRMV1.pdf (REV 1.9) VLG-MC9S12ZVC-SCH.pdf (Document Number SCH-28038, SPF-28038)
View full article
In the attached zip file you can find three software examples demonstrating clock module and PLL configuration on MagniV device MC9S12ZVM. The examples are made in CodeWarrior IDE v10.6 (Eclipse). The main.c source file of each project provides detailed description, comments and important notes.   The source code can be used with other devices within MagniV family based on S12Z core such as S12ZVL, S12ZVC, S12ZVH/Y, but the precaution must be considered about the max bus frequency of the device.   p.s. Revision 2: SYNR, REFDIV and POSTDIV values changed in PLL initialization to achieve highest PLL locking time.
View full article
Here is the example code demonstrating erase/write/read of internal EEPROM module integrated into MagniV devices such as S12ZVM, S12ZVC, S12ZVL etc.   Find detailed description in the project's main.c file.   The example project was created in CodeWarrior IDE v10.6.4 and tested on TRK-S12ZVL board.
View full article
How to get device ID and write program once field without programming application to the S12Z device in the CodeWarrior (Eclipse).   Even the datasheet does not present the device ID it can be read at address 0x1FC000. The device ID is size of 8 bytes from 1F_C000 to 1F_C007. The meaning of the field is confidential information. Of course, other "reserved" fields on higher addresses can also be read but their meaning is also confidential. The ID is not presented in the documentation because it has reason for company only. However, some users require unique identification of the device. It is possible to use this number. In order to read the ID, it is enough to create simple project in the CodeWarrior and connect to the device without programming it and run “mem” command in the debug shell window. If you do not want to remember address ranges, then it is better to prepare command file and execute it.   Of course, we can also simply use memory window.   It is a different story if we want also to see program once field. In this case we have to execute a set of commands to get it. As an example of command file which can be executed to get device ID and program the program once field I present two command files. They can be executed in the debugger window – see and test attached project. They are AAA_Read_Device_ID_And_OTPROM.cmd  and AAA_ProgramOnceField.cmd. The project which also presents reading and writing program once field is not relevant but should be created for the device we want to play with. It is not required to be code (simple code, enough to use what is generated by wizard) loaded into the MCU’s memory. However, necessary is the debugger is connected to a memory. Because of this it is enough to set:   …. And press debug   In the debug enable “Debugger Shell”:   Before continuing please modify flash clock setup in both files to value suitable for programming on the basis of the oscclk you use. In the files search for lines    Write into debugger shell command which runs the AAA_Read_Device_ID_And_OTPROM.cmd: source "c:\D\CODING & SW\ECLIPSE\S12ZVMC-FLASH-WRITEONCEFIELD-CW106\AAA_Read_Device_ID_And_OTPROM.cmd" (it is possible you have different path to the file…please change it)   The command will execute and shows: Device ID And Program field phrase 0. If you want to see another phrase you should modify AAA_Read_Device_ID_And_OTPROM.cmd line set PHRASE 1. Change 1 to the phrase you want to see and run the command presented above “source …..” again. It is enough to press arrow up on the keyboard to see and use previous commands.   In order to program selected field use and run command “source” with the file: AAA_ProgramOnceField.cmd source "c:\D\CODING & SW\ECLIPSE\S12ZVMC-FLASH-WRITEONCEFIELD-CW106\AAA_ProgramOnceField.cmd"   The same note as previosly, the path you have could be different so adjust it. The same line as in previous file should be changed to select the phrase you want to program. As a result, you will see programming algorithm and also read back of the field, example of output: %>source "c:\D\CODING & SW\ECLIPSE\S12ZVMC-FLASH-WRITEONC EFIELD-CW106\AAA_ProgramOnceField .cmd" ############################ Programming Field = 2 ############################ cmdwin::mem 0x0386 %x = 0x30 cmdwin::wait 1000 cmdwin::mem 0x0382 %x = 0x05 cmdwin::mem 0x038C %x = 0x07 cmdwin::mem 0x038D %x = 0x00 cmdwin::mem 0x038E %x = 0x00 cmdwin::mem 0x038F %x = 2 cmdwin::mem 0x0390 %x = 0xA2 cmdwin::mem 0x0391 %x = 0xB2 cmdwin::mem 0x0392 %x = 0xC2 cmdwin::mem 0x0393 %x = 0xD2 cmdwin::mem 0x0394 %x = 0xE2 cmdwin::mem 0x0395 %x = 0xF2 cmdwin::mem 0x0396 %x = 0xA3 cmdwin::mem 0x0397 %x = 0xB3 cmdwin::mem 0x0386 %x = 0x80 cmdwin::wait 1000 ############################ Read back Programmed Field = 2 ############################ cmdwin::mem 0x0386 %x = 0x30 cmdwin::wait 1000 cmdwin::mem 0x0382 %x = 0x01 cmdwin::mem 0x038C %x = 0x04 cmdwin::mem 0x038D %x = 0x00 cmdwin::mem 0x038E %x = 0x00 cmdwin::mem 0x038F %x = 2 cmdwin::mem 0x0386 %x = 0x80 cmdwin::wait 1000 cmdwin::mem 0x0390 8      390  $a2 $b2 $c2 $d2 $e2 $f2  $a3 $b3   . . . . . . . .    Now the question, where to find commands to be able to prepare such a command files, can be asked. 1) The first information source is the CodeWarrior help. For example, search for keyword DW and it could find a command list. 2) Tcl Reference Manual  3) http://www.tcl.tk/    Finally, in the attached project can be seen also approach how to write program once field by SW. Of course, mentioned cmd files are also part of the project.
View full article
Hello, Devkit-S12XE includes a bug on the PORT J2. This document shows the correct connection. The pin designation in the schematic, QSG, and pin markings on the board does not correspond to the connection on the board. Schematic: https://www.nxp.com/downloads/en/schematics/DEVKIT-S12XE-SCH.pdf  QSG: https://www.nxp.com/docs/en/quick-reference-guide/DEVKIT-S12XE-QSG.pdf  Pin markings on the board: In particular, these are the following pin numbers of PORT J2 where the bug was found: 16, 17, 18, 19 The real connection is as follows: I hope it helps, Best regards, Diana
View full article
CAN Standard ID, CAN Extended ID memories refreshment   A human is a creature forgetting things, procedures and a lot of useful principles in a very short time especially when it often jumps between different projects. I also solve the CAN interface filter setup issues occasionally and even I did it a lot of times I always have to think how to set the filter easily and fast. Because of this, on the basis of last experience, I created an excel sheet this year which provides me an easy return to my CAN filter memories. I am not sure it will be helpful for everyone as it is helpful for me, however, I am sharing..... Each of us has different thinking and ways of visualization so any idea for improvement is appreciated in advance.      
View full article
Here is the example code demonstrating erase/write/read of internal Flash module integrated into MagniV devices such as S12ZVM, S12ZVC, S12ZVL etc.   Find detailed description in the project's main.c file.   The example project was created in CodeWarrior IDE v10.6.4 and tested on TRK-S12ZVL board.
View full article
S12 FAMILY DEVICES COP RECOGNITION CONSIDERATIONS SHOULD HELP YOU TO SET HW OF THE RESET PIN TO BE COP CORRECTLY RECOGNIZED The calculator can be found at S12 FAMILY DEVICES COP RECOGNITION CONSIDERATIONS - calculator.xlsx
View full article
Hello all, sharing the latest version of MagniV Power Dissipation Calculator started by Carlos Vazquez and Anita Maliverney. With this excel sheet is possible estimate the power dissipated for any MCU of S12ZVM, S12ZVL, S12ZC family, considering: supply voltages, digital modules, gate drive unit, charge pump, communication transceivers, etc.   A few features where added, any additional comment or suggestion is appreciated. Regards.
View full article
This example shows a few possible configurations of the S12PWM8B8CV2 PWM module. Five PWM channels are configured with different clock source, polarity, alignment, period and duty-cycle.   Four clock sources (A, B, SA, SB) are derived from bus clock using dividers.   Selected polarity of PWM channel determines the duty-cycle whereas the alignment determines the period of the PWM signal.   Four 8-bit channels (4-5, 6-7) are concatenated into two 16-bit channels. Channels 4 and 6 become high-order channels while channels 5 and 7 become low-order channels. These low-order channels (5 and 7) are the output channels routed to a port  and they configure the clock, polarity, alignment and enablement of the PWM signal.  Period and duty-cycle of the signal are configured with both the low-order and high-order channels.   The period registers (PWMPERx) and the duty-cycle registers (PWMDTYx) are double buffered. When they are rewritten while the channel is enabled, the change will not take effect until one of the following occurs: 1. The effective period ends 2. Counter resets 3. The channel is disabled
View full article
The ADC measurement is always relative – relative to your voltage reference. The most of the applications don't allow to use accurate and expensive voltage reference. In that case, VDDA is used as the reference for ADC measurement. Since the operational VSUP range starts from 3.5V and accuracy of the voltage regulator is limited, we should use internal bandgap reference for compensating ADC voltage results. The bandgap voltage VBG has a narrow variation over temperature and external voltage supply. The example shows how to compensate ADC results by additional bandgap voltage measurement.
View full article
This document includes in attachment excel file calculation that might be useful for those using the S12 MagniV for motor control and proper PLL setting in their projects.   Following parameters can be set and reused for different scenarios via attached excel sheet calculation for the S12 MagniV BLDC motor control applications: #define CPMU_REFDIV // PLL setting of ref. divider #define CPMU_SYNDIV // PLL setting of multiplier #define CPMU_POSTDIV // PLL setting of the post divider #define CPMU_REFFRQ // PLL setting of ref. frequency #define CPMU_VCOFRQ // PLL setting of VCO frequency #define ADC_TIM // setting of ADC timer #define MIN_ADC_TRIGGER_FIRST // setting of ADC trigger #define MIN_ADC_TRIGGER_SECOND // setting of ADC trigger #define PWM_MODULO // PMF module config. #define PWM_DEADTIME // PMF module config. #define TIM_PRESCALER // Timer prescaler #define TIMER_1MS // Setting of timer #define SCI_BAUDRATE // setting of SCI baud rate   This is how it can look for setting either internal or external clock: // PLL settings /* /* // Internal clock 1MHz, 100/50 MHz CPU/Bus clock, 8.33 MHz ADC clock #define _INTERNAL_CLOCK                        // 1 MHz internal clock is used #define    CPMU_REFDIV        0 #define    CPMU_SYNDIV        49 #define    CPMU_POSTDIV       0 #define    CPMU_REFFRQ        0 #define    CPMU_VCOFRQ        3 #define    ADC_TIM            2 #define    MIN_ADC_TRIGGER_FIRST     24 #define    MIN_ADC_TRIGGER_SECOND    144 #define    PWM_MODULO                5000 #define    PWM_DEADTIME              50 #define    TIM_PRESCALER      6         // Timer prescaler 64; 50 MHz/64 = 1.28 us #define    TIMER_1MS          781 #define    SCI_BAUDRATE       5208 */  // External clock 4MHz, 25/12.5 MHz CPU/Bus clock, 6.25 MHz ADC clock #define _EXTERNAL_CLOCK #define    CPMU_REFDIV        3 #define    CPMU_SYNDIV        24 #define    CPMU_POSTDIV       1 #define    CPMU_REFFRQ        0 #define    CPMU_VCOFRQ        1 #define    ADC_TIM            0 #define    MIN_ADC_TRIGGER_FIRST     8 #define    MIN_ADC_TRIGGER_SECOND    48 #define    PWM_MODULO                1250 #define    PWM_DEADTIME       13 #define    TIM_PRESCALER      4         // Timer prescaler 16; 12.5MHz/16 = 1.28 us #define    TIMER_1MS          781 #define    SCI_BAUDRATE       1302     It is used in following function for Clock, Reset and Power Management Unit configuration: //Clock, Reset and Power Management Unit configuration //* //*****************************************************************************/ void initCPMU(void) {     // Wait for stable supply after power up     while (GDUF_GLVLSF)         GDUF_GLVLSF = 1;      CPMUREFDIV_REFDIV = CPMU_REFDIV;     CPMUREFDIV_REFFRQ = CPMU_REFFRQ;     CPMUSYNR_SYNDIV = CPMU_SYNDIV;     CPMUSYNR_VCOFRQ = CPMU_VCOFRQ;     CPMUPOSTDIV_POSTDIV = CPMU_POSTDIV;  #ifdef _EXTERNAL_CLOCK     CPMUOSC_OSCE = 1;     while (CPMUIFLG_UPOSC == 0) {}; // Wait for oscillator to start up (UPOSC=1) and PLL to lock (LOCK=1) #endif      while (CPMUIFLG_LOCK == 0) {};     CPMURFLG  = 0x60;     //Clear PORF and LVRF }          Or setting of ADC clock for both ADC modules in ADC module configuration function:   //ADC0CTL_1 = 0;        ADC0TIM = ADC_TIM;          // clock: clk = fbus / (2x(reg.value + 1)) [0.25 - 8MHz]        //ADC1CTL_1 = 0;        ADC1TIM = ADC_TIM;          // clock: clk = fbus / (2x(reg.value + 1)) [0.25 - 8MHz]        All the rest of the corresponding registers settings can be found in the example for the BLDC motor control of 3-pase sensorless BLDC development kit with S12 MagniV in section download: MTRCKTSBNZVM128_SW: Complete motor control application software package for MTRCKTSBNZVM128
View full article
This example simulates ECC issue by cumulative write into the same EEPROM area without an erasing.   The EEPROM erase operation set all bits into log1. The EEPROM program operation may keep bit cells in log1 state or change it into log0 state, but not in opposite way.   The S12Z MCU EEPROM is protected by 22-Bit ECC Scheme. Every word (16bits) is protected by additional 6 bits with ECC checksum. The ECC values are not accessible for users. Every EEPROM reading triggers also ECC check by internal logic. The single bit error in user data may be corrected by ECC checksum. The double bit error cannot be corrected.   The ECC protection is implemented also at flash controller commands and results are signalling by MGSTAT bits.   The first case simulates Single-bit ECC error during reading. The MGSTAT bits after the second write are 0b10 due to fact that just 1 bit is different during write verification (correctable error)   The second case simulates Single-bit ECC error during reading. The MGSTAT bits after the second write are 0b11 due to fact that more than 1 bits are different during write verification (non-correctable error)   The third case simulates Double-bit ECC error during reading. The MGSTAT bits after the second write are 0b11 due to fact that more than 1 bits are different during write verification (non-correctable error)       The EEPROM patterns are selected for highlighted described behavior and they don't have any real meaning.   The cumulative write is not allowed for normal operation!!! The code from this example should be used only for design testing - not in production!!!   Please, see the prm file. Address range 0x100000-0x100001 is excluded from default EEPROM and is used as user EEPROM memory The size of EEPROM sectors is 2 bytes. The EEPROM_Program() function may program up to 4 words in single flash command.   Note: The EEPROM_Program() function was updated - erase verification is skipped     I hope it helps you. Radek
View full article
Work with pushbuttons and 7 segment display. Write assembly (ASM) and C programs for the HCS12, as well as to work with the pushbuttons and 7-segment display on the Dragon12-JR board.  The programs find the largest and smallest numbers from an arbitrary list of eight 8-bit unsigned numbers and displays them on the 7-segment display as outlined in the following.   1. Write a program to do the following, in both ASM and C. Do not use MINA, MINM, MAXA, and MAXM instructions.            a. Load an array of eight 8-bit unsigned numbers into RAM.            b. Find the largest of these numbers and store it.            c. Find the smallest of these numbers and store it.            d. Wait for the pushbuttons (S1 or S2) to be pressed.            e. The first time S1 is pressed, display the high nibble of the largest number; the second time S1 is pressed, display the low nibble of the largest number.                For example, if the largest number is 0x3F, the 7-segment display should show “3” the first time S1 is pressed and “F” the second time it is pressed.            f. Do the same for S2, except use the smallest number.  2. Explain why debouncing is used with switches. Optional: Implement software debouncing for switch used above.   Hints: These are unsigned numbers that your program will be searching through.  Make sure you are using the unsigned branch instructions in your ASM code. Your TA will be changing the numbers in your array to make sure it works for arbitrary 8-bit values. Please make sure the array is somewhere near the top of your program file. For interfacing to LEDs, 7 segment Displays, and pushbuttons see the schematic and manual of your development board. The type of the 7-segment LED on the Dragon12-JR board is common anode. All cathodes are driven individually by an output port and all anodes are internally connected together. The Dragon12-JR board uses port H to drive 7-segment cathodes. Skeleton files are provided to help you complete the asseignment. The 7-segment display communicates with the board via Port H whose address is $0260 (PTH).  Its data direction (input or output) is controlled by writing to Data Direction H register whose address is $0262 (DDRH). In order for PTH to be output (i.e. displaying something), you must set DDRH to $FF first (all bits high, all bits output).  The skeleton code does this for you this time. Almost every I/O port on the board works similarly to PTH; that is, you must set the direction of data on a corresponding data direction register before writing to or reading from it. The two pushbuttons (S1 and S2) are connected to PM6 and PM7. S1à PM6, S2à PM7 A subroutine that displays the low nibble of register A is included with the skeleton ASM code. Just store a value in register A and issue jsr seg7_out to display the low nibble of A. You are required to understand how it works and to write a similar routine for the C version of your code.   This document was generated from the following discussion: Professional Way to solve this HCS12 Dragon12-JR,Work with pushbottons and 7 segment display
View full article
Customers are sometimes asking for reference schematics, so here is a batch of minimal configurations for main representatives of S12(X) family. Attached is also document that should answer most common questions. Hope this will help. Lukas
View full article
This simple SW example is a CodeWarrior project which demonstrates the usage of Security feature on a microcontroller. Find detailed description in the main.c file. It is also shown how to use backdoor access key to put MCU in unsecured state. The CW project is made for MC9S12ZVL device and the source code can be used on any other derivative with MagniV device family.
View full article
The example code shows how to invoke single or double bit RAM ECC error at S12Z devices.   Some basic overview about S12Z ECC codes may be found in thread AM/FLASH ECC Error handling .
View full article
******************************************************************************** Detailed Description: TIM0_Ch2 OC triggers ADC measurements on AN2 (DEVKIT S12ZVL32, potentiometer) every 50ms. ADC interrupt updates duty-cycle (0-100%) of 3 PWM signals that are shifted by 90°. ADC can work either in Trigger or Restart mode. PWM signals are routed to RGB LEDs (DEVKIT S12ZVL32). --------------------------------------------------------------------------------------------- Test HW: DEVKIT-S12ZVL32 MCU: S12ZVL32 Debugger: CW11 Target: internal_FLASH ********************************************************************************
View full article
 *******************************************************************************  * File              main.c  * Owner             LaMa-TIC-RPR  * Version           1.1  * Date              Jun/17/2016  * Classification    General Business Information  * Brief             S12Z Frequency Measurement at PT0 (IOC0_0) by TIM module  *                   in input capture mode  *******************************************************************************  * Detailed Description:  * The code measures frequency at PT0  * It demonstrates  * - It measures frequency at PT0 by means of TIM module IOC0_0.  * - The measurement is sensitive on rising edges so duty cycle has no affect  *   to the measurement  * - Constants:  *           BUSCLOCK  *           MAX_OVERFLOWS  *           TIMER_PRESCALLER  *      must be defined  * - MAX_OVERFLOWS determines minimum measurable frequency.  *   It is max. allowed number of overflows. When overflows counter reaches  *   this value it the flag FREQUENCY_TOO_LOW is set. The message  *   PERIOD BETWEEN TWO EDGES IS TO WIDE is then written to a variable "str"  *   This value gives time interval:  *     T = TIMER_PRESCALER * MAX_OVERFLOWS * 65536 / BUSCLOCK      *     For example:  *      - TIMER_PRESCALER = 1  *      - MAX_OVERFLOWS   = 1000  *      - BUSCLOCK        = 16,000,000Hz  *      T = 1 * 1000 * 65536 / 16,000,000 = 4,096s  => f=0,244140625Hz  * - TIMER_PRESCALER = { 1,2,4,8,16,32,64,128} - smaller values give more  *   precise values but it generates timer overflow more frequently  * - the physical representation of the measured frequency is stored in the  *   string "str"  *  * - The measurement precision is df which can be expressed as:  *  *    df = BUSCLK / ((n^2 + n) * PRESCALER); n = measured number of TCNT periods  *               *   For example: BUSCLK = 16MHz, n = 399, PRESCALER = 1  *     *     *             df = 16,000,000 / ((399^2 + 399) * 1) = 100.25Hz  *               *             so, count 399 means f=BUSCL/399=16,000,000/399 = 40,100.25Hz  *             so, count 400 means f=BUSCL/400=16,000,000/399 = 40,000.00Hz  *                   * So this method is not suitable for large frequencies as can be seen in  * following table (percentual error we can get is df/f):  * n   f[Hz]      df[Hz]                        n   f[Hz] df[Hz]  * 1   8000000   5333333,3           101 1553,0 30,1  * 2   2666666,6 1333333,3           102 1522,9 29,2  * 3   1333333,3  533333,3           103 1493,6 28,4  * 4    800000    266666,6             104 1465,2 27,6  * 5    533333,3  152380,9            105 1437,5 26,8  * 6    380952,3   95238,0             106 1410,6 26,1  * 7    285714,2   63492,0             107 1384,5 25,4  * 8    222222,2   44444,4             108 1359,1 24,7  * 9    177777,7   32323,2             109 1334,4 24,0  * 10   145454,5   24242,4            110 1310,4 23,4  * 11   121212,1   18648,0            111 1287,0 22,7  * 12   102564,1   14652,0            112 1264,2 22,1  * 13    87912,0   11721,6             113 1242,0 21,6  * 14    76190,4    9523,8             114 1220,4 21,0  * 15    66666,6    7843,1             115 1199,40,502  * 16    58823,5    6535,9             116 1178,8 19,9  * 17    52287,5    5503,9             117 1158,9 19,4  * 18    46783,6    4678,3             118 1139,4 18,9  * 19    42105,2    4010,0             119 1120,4 18,5  * 20    38095,2    3463,2             120 1101,9 18,0  * 21    34632,0    3011,4             121 1083,8 17,6  * 22    31620,5    2635,0             122 1066,2 17,1  * 23    28985,5    2318,8             123 1049,0 16,7  * 24    26666,6    2051,2             124 1032,2 16,3  * 25    24615,3    1823,3             125 1015,8 15,9  *  * - PCB setup:  *   - J35 is disconnected because measurement is done on PT0  *   - pulse generator is connected to the J35 pin 1. (PT0)  *    * - Reference to documentation: MC9S12ZVLMR1.pdf Rev. 1.02  * - Tested on TRK-S12ZVL  * - MCU MC9S12ZVL32 0N22G  * - OSCCLK = 4MHz  * - BUSCLK = 16MHz (set by PLL)  *  * The info about frequency and count is transmitted over the SCI0 Tx which is  * routed (MODRR) to PS1 pin  *  *******************************************************************************  Revision History:  Version Date          Author            Description of Changes  1.0     Jun/17/2016   LaMa-TIC-RPR      Initial version  ******************************************************************************/
View full article