Home
Search
Search Keyword: Ordering
Tag: Programming Techniques Total 13 results found.
Recovering from a Watchdog Reset
Many times in applications using the Watchdog timer, there may be a requirement to detect if a reset occurred due to Watchdog or POR / XRES and the application may either start fresh in case of POR / XRES or recover and start executing from the state when the watchdog reset occurred.DETECT THE SOURCE OF RESETThe first requirement is to find out the source of reset.  This can be done by checking the WDRS bit in the CPU_SCR0 register.  This bit is set in case of a watchdog reset event.  The below code in the beginning of main.c can be used.if(CPU_SCR0 & CPU_SCR0_WDRS_MASK)PRESERVE GLOBAL VARIABLESIn order to recover from a watchdog reset and resume the application, it is necessary that the Global variables be preserved when the watchdog reset occurs.  This can be done by setting the IRAMDIS bit in the CPU_SCR1 register.  When this bit is set, all the cells marked “??” in the below table are preserved during a Watchdog reset (taken from Technical Reference Manual Section 3).
Code Optimization Techniques for ImageCraft Compiler
In a micro controller like PSoC 1 where the maximum Flash size is 32K, code optimization plays a very important role in creating compact code that fits the small flash size of the device.  Following are some of the optimization techniques that can be used on PSoC1 projects with the ImageCraft compiler.Relocatable start code addressThis is the address from where the compiler starts placing relocatable code.  It has to be set to a value after the end of boot.asm code. The optimal ‘Relocatable start code address’ is right after the end of boot.asm code. When this address is greater than what it needs to be,
Questions: 1. I would like to place a constant variable in an absolute address in Flash.  I will place information like version and serial number in this absolute address. How do I do this?2. I would like to place a function in an absolute address in Flash.  How do I do this?Answer:  You can place either a constant variable or a function in absolute address in flash using the #pragma abs_address directive.For example, to place constant variables in absolute address 0x3FC0:#pragma abs_address 0x3FC0const BYTE Version = 0x01;  // This byte is placed in address 0x3FC0const char SerialNumber[] = "1234567890";  // This string is placed from address 0x3FC1#pragma end_abs_addressTo place a function "MyFunction" at address 0x1000, the same approach may be used.#pragma abs_address 0x1000void MyFunction(void)#pragma end_abs_address
Question: How do I place a RAM variable in an absolute RAM address?Answer: A RAM variable may be placed in an absolute RAM address using three methods.Option-A: Using the #pragma directiveLet us say, we need to allocate a variable ‘myByte’ at an address 0x78 in RAM and another variable ‘myByte1’ at address 0x104 , then the process would be:
Changing Drive Mode Of PSoC1 GPIO On The Fly

Question: How do I change the drive mode of a PSoC 1 GPIO on the fly?

Answer: The drive mode of the GPIO pin can be changed on the fly by changing the PRTxDMx registers.  There are three drive mode registers for each port that control the drive mode of the pins in a particular port.  These are the PRTxDM0, PRTxDM1 and PRTxDM2 registers. The combination of the bits of these three registers decide the drive mode of a particular pin.  The following table shows the various combinations of the PRTxDMx bits and the corresponding drive modes.
Question: I would like to call a C function from inside an ISR.  How do I do this?Answer: You can call a C function from inside an ISR by using "lcall _FunctionName".  Any C function when called from assembly requires an underscore before the function name.  So, if you have a C function called MyFunction, in assembly you would call this by using "lcall _Myfunction".  But just calling the function from inside an ISR does not work.  There are a few very important things to remember when calling a C function from inside an ISR
Question: How do I write an ISR in C for PSoC 1?Answer:  Let us write a C ISR called MyCounterISR to be called to process the interrupt from a counter user module named Counter16_1.1. Define the C function as an ISR using the #pragma interrupt_handler directive.  This should be placed in the beginning of main.c or any other source file along with other function prototypes.#pragma interrupt_handler MyCounterISR
Question: How do I write to a PSoC3 GPIO using firmware?Answer: There are many options to control a PSoC3 GPIO in firmware.  Let us take a look at some of these options and their pros and cons.Option-1: Use Port in APIsWhen a Digital Output Port component is placed in the project, the PSoC Creator generates API functions to control the port pin.  The function used to write to the pin is <Pin Name>_Write.  For example, for a Port Pin component named Out1,
Question: I would like to implement delay functions in my project.  How do I create delay functions for the PSoC?Answer: The LCD user module in the PSoC Designer has two functions called LCD_Delay50u and LCD_Delay50uTimes.  Using these functions, you can implement delays in multiples of 50uS.  However, you will have to place the LCD user module in the project to use these functions.  This would be a huge code overhead in projects that do not use LCD.  The attached zip file has two files delay.asm and delay.h.  These files have been created using the delay functions from LCD user module.  The following is the procedure to use these files in your project.
Question:When should I use a Shadow Register to write to a Port? What are Read/Modify/Write Instructions?When I have an input pin configured as pullup, the value of the input gets stuck to 0 irrespective of the state of the input pin.  What could be the problem?Answer: When you have input pins configured as Pull Up or Pull Down and if there are other pins on the same port that are configured as outputs, an instruction that is used to update an output pin may accidentally set or clear the input pin thus latching the input.  For example let us consider the following scenario.
  • «
  •  Start 
  •  Prev 
  •  1 
  •  2 
  •  Next 
  •  End 
  • »