1 / 28

Theory behind the control of Embedded System Peripherals Programming the McVASH device

Theory behind the control of Embedded System Peripherals Programming the McVASH device. M. Smith University of Calgary. McVASH (Advert). Many people like to sing in the shower. However, its rather boring as there is no accompaniment .

lamya
Download Presentation

Theory behind the control of Embedded System Peripherals Programming the McVASH device

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Theory behind the control of Embedded System PeripheralsProgramming the McVASH device M. SmithUniversity of Calgary

  2. McVASH (Advert) • Many people like to sing in the shower. • However, its rather boring as there is no accompaniment . • The McVASH device solves this program.Microprocessor controlled Voice Activated Shower Head • Water propelled electrical turbine for safety • Your voice is DSP analysed (Lab. 5) and the rhythm detected. • This controls the water level from the shower head. • The beat of the water on the side of the shower walls provides the accompaniment to your singing!

  3. Peripheral device registers needed to control device behaviour • Every thing must be as small as possible to reduce cost. 1 cent / device saving over 1 million devices is a lot of extra profit! • Device control register – is a bit pattern • Bit to “turn on” McVASH device (read and write) • Bit to “turn on” Sound part (read and write) • Sound being recognized bit (microphone working bit)(READ ONLY RO) NOTE: Written R Oh not R zero– in data booksEtc • 16 bits (1 half-word, unsigned short int) can act as 16 different software switches to activate 16 different hardware operations.

  4. Peripheral device registers needed • Every thing must be as small as possible to reduce cost. 1 cent / device saving over 1 million devices is a lot of profit! • Water temperature – value bit pattern • McVASH device has a TMP03 device (Part of ENCM511Lab. 2) • Range -- Temperatures between 0C to 70 C • Accuracy – Report temperature to within 0.5C • Typical value are 6 C, 15.5 C • 15.5 C is not an integer value • Floating point processors $400 each • Need cheaper approach. • Use integer number to represent a limited number of floating point values • Use ideas from ENCM369 on number representation

  5. Peripheral device registers needed • Water temperature – value bit pattern • Range -- Temperatures between 0C to 70 C • Accuracy – 0.5C is sufficient for a shower • Store 0 C as value 0x00 b 0000 0000 • Store 0.5C as value 0x01 b 0000 0001 • Store 1 C as value 0x02 b 0000 0010 • Store 6 C as value 12 (0x0C) b 0000 1100 • Store 6.5 C as value 13 (0x0D) b 0000 1101 Store temperature X C as hex value 2X – now all temperatures stored as integer values on a $2 integer processor rather than a $400 floating point processor • Note – integer processors CAN do floating point operations (e.g. Blackfin); just not as quickly as FP processors

  6. Water Temperature register • Numerical representation • Biggest value 70C = 140 • Smallest value 0C = 0 • Choices of how to store this value • Use unsigned byte (8 -bit) value: min 0 to max 255 • Use signed byte value :– min -128 to +127 – NO • Use signed word value :- min -32000 to +32000 • Useful in Canadian markets when out-door camping • Cheapest solution that works – unsigned byte value

  7. McVASH is a Green product! • Need timer to turn off the water • Need to count in seconds • We have a processor that has a clock that runs at 1 MHz • Would need divide logic to turn 1MHz clock into 1 second clock. • Cheaper to have 32 bit register that counts the 1 MHz clock • How many seconds can be counted this way? • Should we use a signed 32 bit register or an unsigned 32 bit register? • Which register type stores the largest count? (Quiz hint)

  8. Timer registers needed • Save more money by having the “turn the timer on” control bit as one of the bits in existing “Processor control register”. • Need 32 bit counter register TCOUNT • Counts how many “ticks” have occurred since time turned on • Need 32 bit “finish” register (TPERIOD). • When the TCOUNT reaches TPERIOD, tell the system to do an interrupt service routine. This ISR turns the water off. • Need 64 bit CYCLES register which counts how long the processor has been turned on • Cheaper to build as “2” 32 bit registers CYCLES and CYCLES2 • Design of McVASH timer very similar to Blackfin CORE TIMER

  9. McVASH registers • Each McVASH device has • 3 32-bit timer registers • 8-bit temperature register (temp *2 is stored) • 16-bit control register • Sell on market – two products. Try to minimize total cost • Blackfin controlling 1 McVASH for small summer cottages with only one shower • Blackfin controlling many McVASH for big houses with many showers • How do these ideas fit in with the Microcontroller discussed in Monday’s lecture?

  10. McVASH -- Summer Cottage version CONTROL BUS ADDRESSBUS DATA BUS CPU contains CCUALUdata registersand pointer registers BOOTROM Used at startup Instruction(program)ROM McVASHMemoryAddress0x20??? DataRAM

  11. McVASH -- Big House version CONTROL BUS ADDRESSBUS DATA BUS CPU contains CCUALUdata registersand pointer registers BOOTROM Used at startup Instruction(program)ROM McVASHMemoryAddress0x20???PLUG and Play McVASHMemoryAddress0x30???PLUG and Play DataRAM

  12. Typical function for McVASH • Over a period of 5 seconds, keep the temperature of the water at 37C • PSEUDO CODEFor ever Record temperature values at regular intervals For the last 5 seconds, work out temperature if below 36.5C add less cold water, more hot if above 37.5C add more cold water, less coldend

  13. C/C++ code – First attempt #define TEMPERATURE37C 74 // PROTOTYPES OF FUNCTIONS TO BE DEVELOPED void WaitTenthSecond( void);unsigned ReadTemperatureASM( void);unsigned intAverageTemperature(unsigned int *temperature); // temperature array passedOR unsigned intAverageTemperature(unsigned int temperature[ ] ); SAME CODE NEEDED other prototypes as needed void ControlWaterTemperature(void) { unsigned int temperature[50]; for (count = 0 to 50) {WaitTenthSecond( ); temperature[count] = ReadTemperatureASM( );  The code to be developed this lecture }unsigned intaverageTemperature = AverageTemp(temperature); THIS FUNCTION CAN’T POSSIBLY BE USED TO CALCULATE AVERAGE TEMPERATURE FROM AN ARRAY OF TEMPERATURES – WHY NOT? if (averageTemperature != TEMPERATURE37C )AdjustWaterTemperature(averageTemperature); };

  14. Writing / Reading values • temperature[count] = writes to a memory array – stored on the processor stack – SDRAM • The processor is started up with a stack (ENCM369) already placed in memory • Easy to access this sort of array using “Standard C” • ReadTemperature – reads from a memory array of registers that belong to the McVASH device • Where is this peripheral device register array? • Must know location of the peripheral device register array in order to be able to read and write values to it! • There might be more than one memory array (one for each McVASH peripheral device)

  15. MONDAY’s lecture:Every external device needs this amount of support “glue logic” to work ADDRESS BUS DECODE LOGIC • Address strobe • Data strobe • Read/Write control • CS – chip select Device itself with all necessary internal logic to do the things it needs to do External Device OEOutput Enable other signals such as interrupt signals, etc DATA BUS

  16. System design – decides on control logic McVASH 1 – control logic built to recognize addresses on the processor address bus in the range 0x300000 to 0x30001F. • Why not the range 0x200000 to 0x2FFFFF? • Why not the range 0x500000 to 0x50001F? • McVASH 2 – control logic build to have the device register memory array start at address 0x400000 • McVASH 3 – control logic build to have the device register memory array start at address 0x500000

  17. McVASH #1 registers start at0x300000 • Each McVASH device decode logic permit • 3 32-bit timer registers Address are 0x300000, 0x300004, 0x300008 • 8-bit temperature register (temp *2 is stored) Address is 0x30000C • 16-bit control register Address is ?????? Next location available is 0x30000D (address is not even – look at bit 0 -- 0xD = 1101) but processors CAN NOT access 16-bit peripheral registers (or memory locations) whose address is “odd” (unless you want to pay more for the processor) Control register therefore designed to have address 0x30000E (address is even – look at bit 0 )

  18. McVASH #2 registers start at0x400000 • Each McVASH device has • 3 32-bit timer registers Address are 0x400000, 0x400004, 0x400008 • 8-bit temperature register (temp *2 is stored) Address is 0x40000C • 16-bit control register Next location available is 0x40000D (address is not even) but processors CAN NOT access 16-bit registers whose memory address is “odd” (unless you want to pay more for the processor) control register therefore designed to have address 0x40000E

  19. Here is the code from Monday’s tutorial to add two values in an array …. Other code .section L1_data; .byte4 _fooArray[2]; .section program; .global _AddArrayValuesASM; _AddArrayValuesASM: #define sum_R0 R0 // register int sum; sum_R0 = 0; // sum = 0; #define pointer_to_array_P1 P1 // register int * pointer_to_array P1.L = lo(_fooArray); P1.H = hi(_fooArray); // pointer_to_array = &fooArray[0];R1 = [pointer_to_array_P1]; // int temp = fooArray[0]; sum_R0 = sum_R0 + R1; // sum = sum + temp R1 = [pointer_to_array_P1 + 4]; // temp = fooArray[1]; sum_R0 = sum_R0 + R1; // sum = sum + temp _AddArrayValuesASM .END: RTS;

  20. Here is the first attempt at code for unsigned intReadTemperatureASM( ); .section program; .global _ ReadTemperatureASM; _ ReadTemperatureASM; : #define temperature_R0 R0 #define pointerMcVASHDevice_P1 P1 #define ADDRESS_McVASH_DEVICE 0x30000 P1.L = lo(ADDRESS_McVASH_DEVICE); P1.H = hi(ADDRESS_McVASH_DEVICE); // Need to read 8-bit temperature value – B for Byte – zero-extend to 32-bits temperature_R0= B[pointerMcVASHDevice_P1 + 0xC] (Z); _ReadTemperatureASM;.END: RTS;

  21. Here is the first attempt to code to read Device 2 temperature sensor .section program; .global _ReadTemperatureDevice2ASM; _ReadTemperatureDevice2ASM: #define temperature_R0 R0 #define pointerMcVASHDevice_P1 P1 #define ADDRESS_McVASH_DEVICE2 0x40000 P1.L = lo(ADDRESS_McVASH_DEVICE2); P1.H = hi(ADDRESS_McVASH_DEVICE2); // Need to read 8-bit temperature value – B for Byte – zero-extend to 32-bits temperature_R0 = B[pointerMcVASHDevice_P1 + 0xC] (Z); _ReadTemperatureDevice2ASM.END: RTS;

  22. Add code to a test project to check syntax 0x40000

  23. What would the code look if written in “C++”? unsigned intReadTemperatureDeviceCPP(void) { unsigned char temperatureValue; (byte)Somehow read a byte value from a specific register from a device located some where on the external address bus of the microcontrollerreturn (unsigned int) temperatureValue; } That “somehow read” operation is difficult to do with most “C/C++” compilers – which is why most interfaces to hardware are done in assembly code and nor written in “C” or “C++”

  24. What would the code look written in Blackfin “C++” #define ADDRESS_McVASH_DEVICE0x30000 unsigned intReadTemperatureDeviceCPP(void) { unsigned char temperatureValue; // “byte” in “C” is unsigned char // Use the key word “volatile” to tell embedded C” that this is an external device location unsigned char *pointerToDeviceRegister = (volatile unsigned char *) ADDRESS_McVASH_DEVICE; // Point to device temperature register pointerToDeviceRegister = pointerToDeviceRegister + 0xC; // get the temperature value using a “pointer to a peripheral device register location” temperatureValue = *pointerToDeviceRegisterreturn (unsigned int) temperatureValue; }

  25. 0x30000 0x30000

  26. Additional slides with hints for speeding up labs and assignments • Use “print screen” to do a “VDSP screen capture” and then paste into a “.doc” file • After you have developed “C” code and linked it (without error)s, then “right click” on the source code window and select “MIXED” • You can now see the assembly language code that the “C” compiler generated • You can cut and paste “example code” from the Powerpoint slides into VDSP is you know this trick • Starting point for my “Tests” on the McVASH device

  27. Compare our code and “C” codeproduced by the VDSP compiler P1 = HI_16 bits + lo_16bits= 0x2 * 0x10000 + 12 (0xC) We have optimized the code (NO LINK or UNLINK, since we KNOW this is a LEAF function

  28. You are welcome to cut-and-paste code from my slidesBUT -- When cutting and pasting code from Powerpoint into VDSP • Code has extra “strange characters” -- remove them

More Related