版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、Chapter 7 Digital Camera Example太原房產(chǎn)網(wǎng) 52youju1.OutlineIntroduction to a simple digital cameraDesigners perspectiveRequirements specificationDesign Four implementations2Putting it all togetherGeneral-purpose processorSingle-purpose processorCustomStandardMemoryInterfacingKnowledge applied to designin
2、g a simple digital cameraGeneral-purpose vs. single-purpose processorsPartitioning of functionality among different processor typesIntroduction3Introduction to a simple digital cameraCaptures imagesStores images in digital formatNo filmMultiple images stored in cameraNumber depends on amount of memo
3、ry and bits used per imageDownloads images to PCOnly recently possibleSystems-on-a-chipMultiple processors and memories on one ICHigh-capacity flash memoryVery simple description used for exampleMany more features with real digital cameraVariable size images, image deletion, digital stretching, zoom
4、ing in and out, etc.4Designers perspectiveTwo key tasksProcessing images and storing in memoryWhen shutter pressed:Image capturedConverted to digital form by charge-coupled device (CCD)Compressed and archived in internal memoryUploading images to PCDigital camera attached to PCSpecial software comma
5、nds camera to transmit archived images serially5Charge-coupled device (CCD)Special sensor that captures an imageLight-sensitive silicon solid-state device composed of many cellsWhen exposed to light, each cell becomes electrically charged. This charge can then be converted to a 8-bit value where 0 r
6、epresents no exposure while 255 represents very intense exposure of that cell to light.Some of the columns are covered with a black strip of paint. The light-intensity of these pixels is used for zero-bias adjustments of all the cells.The electromechanical shutter is activated to expose the cells to
7、 light for a brief moment.The electronic circuitry, when commanded, discharges the cells, activates the electromechanical shutter, and then reads the 8-bit charge value of each cell. These values can be clocked out of the CCD by external logic through a standard parallel bus interface.Lens areaPixel
8、 columnsCovered columnsElectronic circuitryElectro-mechanical shutterPixel rows6Zero-bias errorManufacturing errors cause cells to measure slightly above or below actual light intensityError typically same across columns, but different across rowsSome of left most columns blocked by black paint to d
9、etect zero-bias errorReading of other than 0 in blocked cells is zero-bias errorEach row is corrected by subtracting the average error found in blocked cells for that rowCovered cellsBefore zero-bias adjustmentAfter zero-bias adjustmentZero-bias adjustment7CompressionStore more imagesTransmit image
10、to PC in less timeJPEG (Joint Photographic Experts Group)Popular standard format for representing digital images in a compressed formProvides for a number of different modes of operationMode used in this chapter provides high compression ratios using DCT (discrete cosine transform)Image data divided
11、 into blocks of 8 x 8 pixels3 steps performed on each blockDCTQuantizationHuffman encoding8DCT stepTransforms original 8 x 8 block into a cosine-frequency domainUpper-left corner values represent more of the essence of the imageLower-right corner values represent finer detailsCan reduce precision of
12、 these values and retain reasonable image qualityFDCT (Forward DCT) formulaC(h) = if (h = 0) then 1/sqrt(2) else 1.0Auxiliary function used in main function F(u,v)F(u,v) = x C(u) x C(v) x=0.7 y=0.7 Dxy x cos(2u + 1)u/16) x cos(2y + 1)v/16)Gives encoded pixel at row u, column vDxy is original pixel v
13、alue at row x, column yIDCT (Inverse DCT)Reverses process to obtain original block (not needed for this design)9Quantization stepAchieve high compression ratio by reducing image qualityReduce bit precision of encoded dataFewer bits needed for encodingOne way is to divide all values by a factor of 2S
14、imple right shifts can do thisDequantization would reverse process for decompressionAfter being decoded using DCTAfter quantizationDivide each cells value by 810Serialize 8 x 8 block of pixelsValues are converted into single list using zigzag patternPerform Huffman encodingMore frequently occurring
15、pixels assigned short binary codeLonger binary codes left for less frequently occurring pixelsEach pixel in serial list converted to Huffman encoded valuesMuch shorter list, thus compressionHuffman encoding step11Huffman encoding examplePixel frequencies on leftPixel value 1 occurs 15 timesPixel val
16、ue 14 occurs 1 timeBuild Huffman tree from bottom upCreate one leaf node for each pixel value and assign frequency as nodes valueCreate an internal node by joining any two nodes whose sum is a minimal valueThis sum is internal nodes valueRepeat until complete binary treeTraverse tree from root to le
17、af to obtain binary code for leafs pixel valueAppend 0 for left traversal, 1 for right traversalHuffman encoding is reversibleNo code is a prefix of another code14453210-2-1-10-5-3-4-8-96141121121224354659510511514617818152935641Pixel frequenciesHuffman treeHuffman codes12Archive stepRecord starting
18、 address and image sizeCan use linked listOne possible way to archive imagesIf max number of images archived is N:Set aside memory for N addresses and N image-size variablesKeep a counter for location of next available addressInitialize addresses and image-size variables to 0Set global memory addres
19、s to N x 4Assuming addresses, image-size variables occupy N x 4 bytesFirst image archived starting at address N x 4Global memory address updated to N x 4 + (compressed image size)Memory requirement based on N, image size, and average compression ratio13Uploading to PCWhen connected to PC and upload
20、command receivedRead images from memoryTransmit serially using UARTWhile transmittingReset pointers, image-size variables and global memory pointer accordingly14Requirements SpecificationSystems requirements what system should doNonfunctional requirementsConstraints on design metrics (e.g., “should
21、use 0.001 watt or less)Functional requirementsSystems behavior (e.g., “output X should be input Y times 2)Initial specification may be very general and come from marketing dept.E.g., short document detailing market need for a low-end digital camera that:captures and stores at least 50 low-res images
22、 and uploads to PC,costs around $100 with single medium-size IC costing less that $25,has long as possible battery life,has expected sales volume of 200,000 if market entry 6 months,100,000 if between 6 and 12 months,insignificant sales beyond 12 months15Nonfunctional requirementsDesign metrics of i
23、mportance based on initial specificationPerformance: time required to process imageSize: number of elementary logic gates (2-input NAND gate) in ICPower: measure of avg. electrical energy consumed while processingEnergy: battery lifetime (power x time)Constrained metricsValues must be below (sometim
24、es above) certain thresholdOptimization metricsImproved as much as possible to improve productMetric can be both constrained and optimization16Nonfunctional requirements (cont.)PerformanceMust process image fast enough to be useful1 sec reasonable constraintSlower would be annoyingFaster not necessa
25、ry for low-end of marketTherefore, constrained metricSizeMust use IC that fits in reasonably sized cameraConstrained and optimization metricConstraint may be 200,000 gates, but smaller would be cheaperPowerMust operate below certain temperature (cooling fan not possible)Therefore, constrained metric
26、EnergyReducing power or time reduces energyOptimized metric: want battery to last as long as possible17Informal functional specificationFlowchart breaks functionality down into simpler functionsEach functions details could then be described in EnglishDone earlier in chapterLow quality image has reso
27、lution of 64 x 64Mapping functions to a particular processor type not done at this stageserial outpute.g., 011010.yesnoCCDinputZero-bias adjustDCTQuantizeArchive in memoryMore 88 blocks?Transmit seriallyyesnoDone?18Refined functional specificationRefine informal specification into one that can actua
28、lly be executedCan use C/C+ code to describe each functionCalled system-level model, prototype, or simply modelAlso is first implementationCan provide insight into operations of systemProfiling can find computationally intensive functionsCan obtain sample output used to verify correctness of final i
29、mplementationimage file101011010110101010010101101.CCD.CCNTRL.CUART.Coutput file1010101010101010101010101010.CODEC.CCCDPP.CExecutable model of digital camera19CCD moduleSimulates real CCDCcdInitialize is passed name of image fileCcdCapture reads “image from fileCcdPopPixel outputs pixels one at a ti
30、mechar CcdPopPixel(void) char pixel; pixel = bufferrowIndexcolIndex; if( +colIndex = SZ_COL ) colIndex = 0; if( +rowIndex = SZ_ROW ) colIndex = -1; rowIndex = -1; return pixel;#include #define SZ_ROW 64#define SZ_COL (64 + 2)static FILE *imageFileHandle;static char bufferSZ_ROWSZ_COL;static unsigned
31、 rowIndex, colIndex;void CcdInitialize(const char *imageFileName) imageFileHandle = fopen(imageFileName, r); rowIndex = -1; colIndex = -1;void CcdCapture(void) int pixel; rewind(imageFileHandle); for(rowIndex=0; rowIndexSZ_ROW; rowIndex+) for(colIndex=0; colIndexSZ_COL; colIndex+) if( fscanf(imageFi
32、leHandle, %i, &pixel) = 1 ) bufferrowIndexcolIndex = (char)pixel; rowIndex = 0; colIndex = 0;20CCDPP (CCD PreProcessing) modulePerforms zero-bias adjustmentCcdppCapture uses CcdCapture and CcdPopPixel to obtain imagePerforms zero-bias adjustment after each row read in#define SZ_ROW 64#define SZ_COL
33、64static char bufferSZ_ROWSZ_COL;static unsigned rowIndex, colIndex;void CcdppInitialize() rowIndex = -1; colIndex = -1;void CcdppCapture(void) char bias; CcdCapture(); for(rowIndex=0; rowIndexSZ_ROW; rowIndex+) for(colIndex=0; colIndexSZ_COL; colIndex+) bufferrowIndexcolIndex = CcdPopPixel(); bias
34、= (CcdPopPixel() + CcdPopPixel() / 2; for(colIndex=0; colIndexSZ_COL; colIndex+) bufferrowIndexcolIndex -= bias; rowIndex = 0; colIndex = 0;char CcdppPopPixel(void) char pixel; pixel = bufferrowIndexcolIndex; if( +colIndex = SZ_COL ) colIndex = 0; if( +rowIndex = SZ_ROW ) colIndex = -1; rowIndex = -
35、1; return pixel;21UART moduleActually a half UARTOnly transmits, does not receiveUartInitialize is passed name of file to output toUartSend transmits (writes to output file) bytes at a time#include static FILE *outputFileHandle;void UartInitialize(const char *outputFileName) outputFileHandle = fopen
36、(outputFileName, w);void UartSend(char d) fprintf(outputFileHandle, %in, (int)d);22CODEC moduleModels FDCT encodingibuffer holds original 8 x 8 blockobuffer holds encoded 8 x 8 blockCodecPushPixel called 64 times to fill ibuffer with original blockCodecDoFdct called once to transform 8 x 8 blockExpl
37、ained in next slideCodecPopPixel called 64 times to retrieve encoded block from obufferstatic short ibuffer88, obuffer88, idx;void CodecInitialize(void) idx = 0; void CodecDoFdct(void) int x, y; for(x=0; x8; x+) for(y=0; y8; y+) obufferxy = FDCT(x, y, ibuffer); idx = 0;void CodecPushPixel(short p) i
38、f( idx = 64 ) idx = 0; ibufferidx / 8idx % 8 = p; idx+;short CodecPopPixel(void) short p; if( idx = 64 ) idx = 0; p = obufferidx / 8idx % 8; idx+; return p;23CODEC (cont.)Implementing FDCT formula C(h) = if (h = 0) then 1/sqrt(2) else 1.0F(u,v) = x C(u) x C(v) x=0.7 y=0.7 Dxy x cos(2u + 1)u/16) x co
39、s(2y + 1)v/16)Only 64 possible inputs to COS, so table can be used to save performance timeFloating-point values multiplied by 32,678 and rounded to nearest integer32,678 chosen in order to store each value in 2 bytes of memoryFixed-point representation explained more laterFDCT unrolls inner loop of
40、 summation, implements outer summation as two consecutive for loopsstatic const short COS_TABLE88 = 32768, 32, 30273, 27245, 23170, 18204, 12539, 6392 , 32768, 27245, 12539, -6392, -23170, -32, -30273, -18204 , 32768, 18204, -12539, -32, -23170, 6392, 30273, 27245 , 32768, 6392, -30273, -18204, 2317
41、0, 27245, -12539, -32 , 32768, -6392, -30273, 18204, 23170, -27245, -12539, 32 , 32768, -18204, -12539, 32, -23170, -6392, 30273, -27245 , 32768, -27245, 12539, 6392, -23170, 32, -30273, 18204 , 32768, -32, 30273, -27245, 23170, -18204, 12539, -6392 ;static int FDCT(int u, int v, short img88) double
42、 s8, r = 0; int x; for(x=0; x8; x+) sx = imgx0 * COS(0, v) + imgx1 * COS(1, v) + imgx2 * COS(2, v) + imgx3 * COS(3, v) + imgx4 * COS(4, v) + imgx5 * COS(5, v) + imgx6 * COS(6, v) + imgx7 * COS(7, v); for(x=0; x8; x+) r += sx * COS(x, u); return (short)(r * .25 * C(u) * C(v);static short ONE_OVER_SQR
43、T_TWO = 23170;static double COS(int xy, int uv) return COS_TABLExyuv / 32768.0; static double C(int h) return h ? 1.0 : ONE_OVER_SQRT_TWO / 32768.0;24CNTRL (controller) moduleHeart of the systemCntrlInitialize for consistency with other modules onlyCntrlCaptureImage uses CCDPP module to input image
44、and place in buffer CntrlCompressImage breaks the 64 x 64 buffer into 8 x 8 blocks and performs FDCT on each block using the CODEC moduleAlso performs quantization on each blockCntrlSendImage transmits encoded image serially using UART modulevoid CntrlSendImage(void) for(i=0; iSZ_ROW; i+) for(j=0; j
45、SZ_COL; j+) temp = bufferij; UartSend(char*)&temp)0); /* send upper byte */ UartSend(char*)&temp)1); /* send lower byte */ #define SZ_ROW 64#define SZ_COL 64#define NUM_ROW_BLOCKS (SZ_ROW / 8)#define NUM_COL_BLOCKS (SZ_COL / 8)static short bufferSZ_ROWSZ_COL, i, j, k, l, temp;void CntrlInitialize(vo
46、id) void CntrlCaptureImage(void) CcdppCapture(); for(i=0; iSZ_ROW; i+) for(j=0; jSZ_COL; j+) bufferij = CcdppPopPixel();void CntrlCompressImage(void) for(i=0; iNUM_ROW_BLOCKS; i+) for(j=0; jNUM_COL_BLOCKS; j+) for(k=0; k8; k+) for(l=0; l8; l+) CodecPushPixel( (char)bufferi * 8 + kj * 8 + l); CodecDo
47、Fdct();/* part 1 - FDCT */ for(k=0; k8; k+) for(l=0; l= 6; 25Putting it all togetherMain initializes all modules, then uses CNTRL module to capture, compress, and transmit one imageThis system-level model can be used for extensive experimentationBugs much easier to correct here rather than in later
48、modelsint main(int argc, char *argv) char *uartOutputFileName = argc 1 ? argv1 : uart_out.txt; char *imageFileName = argc 2 ? argv2 : image.txt; /* initialize the modules */ UartInitialize(uartOutputFileName); CcdInitialize(imageFileName); CcdppInitialize(); CodecInitialize(); CntrlInitialize(); /*
49、simulate functionality */ CntrlCaptureImage(); CntrlCompressImage(); CntrlSendImage();26DesignDetermine systems architectureProcessorsAny combination of single-purpose (custom or standard) or general-purpose processorsMemories, busesMap functionality to that architectureMultiple functions on one pro
50、cessorOne function on one or more processorsImplementationA particular architecture and mappingSolution space is set of all implementationsStarting pointLow-end general-purpose processor connected to flash memoryAll functionality mapped to software running on processorUsually satisfies power, size,
51、and time-to-market constraintsIf timing constraint not satisfied then later implementations could:use single-purpose processors for time-critical functionsrewrite functional specification27Implementation 1: Microcontroller aloneLow-end processor could be Intel 8051 microcontrollerTotal IC cost inclu
52、ding NRE about $5Well below 200 mW powerTime-to-market about 3 monthsHowever, one image per second not possible12 MHz, 12 cycles per instructionExecutes one million instructions per secondCcdppCapture has nested loops resulting in 4096 (64 x 64) iterations100 assembly instructions each iteration409,
53、000 (4096 x 100) instructions per imageHalf of budget for reading image aloneWould be over budget after adding compute-intensive DCT and Huffman encoding28Implementation 2: Microcontroller and CCDPPCCDPP function implemented on custom single-purpose processorImproves performance less microcontroller
54、 cyclesIncreases NRE cost and time-to-marketEasy to implementSimple datapathFew states in controllerSimple UART easy to implement as single-purpose processor alsoEEPROM for program memory and RAM for data memory added as well8051UARTCCDPPRAMEEPROMSOC29MicrocontrollerSynthesizable version of Intel 80
55、51 availableWritten in VHDL Captured at register transfer level (RTL)Fetches instruction from ROMDecodes using Instruction DecoderALU executes arithmetic operationsSource and destination registers reside in RAMSpecial data movement instructions used to load and store externallySpecial program genera
56、tes VHDL description of ROM from output of C compiler/linkerTo External Memory BusController4K ROM128RAMInstruction DecoderALUBlock diagram of Intel 8051 processor core30UARTUART in idle mode until invokedUART invoked when 8051 executes store instruction with UARTs enable register as target addressM
57、emory-mapped communication between 8051 and all single-purpose processorsLower 8-bits of memory address for RAMUpper 8-bits of memory address for memory-mapped I/O devicesStart state transmits 0 indicating start of byte transmission then transitions to Data stateData state sends 8 bits serially then
58、 transitions to Stop stateStop state transmits 1 indicating transmission done then transitions back to idle modeinvokedI = 8I 8Idle:I = 0Start: Transmit LOWData: Transmit data(I), then I+Stop: Transmit HIGHFSMD description of UART31CCDPPHardware implementation of zero-bias operationsInteracts with e
59、xternal CCD chipCCD chip resides external to our SOC mainly because combining CCD with ordinary logic not feasibleInternal buffer, B, memory-mapped to 8051Variables R, C are buffers row, column indicesGetRow state reads in one row from CCD to B66 bytes: 64 pixels + 2 blacked-out pixelsComputeBias st
60、ate computes bias for that row and stores in variable BiasFixBias state iterates over same row subtracting Bias from each elementNextRow transitions to GetRow for repeat of process on next row or to Idle state when all 64 rows completedC = 64C 64R = 64C = 66invokedR 64C 66Idle:R=0C=0GetRow:BRC=PxlC=
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 領(lǐng)導(dǎo)力與商務(wù)禮儀培訓(xùn)
- 《跨接導(dǎo)壓技術(shù)創(chuàng)新》課件
- 提升營收的多元化策略計劃
- 地質(zhì)勘查技術(shù)服務(wù)行業(yè)相關(guān)投資計劃提議
- 財務(wù)科預(yù)算與成本控制計劃
- 丙型肝炎抗體檢測試劑盒相關(guān)行業(yè)投資規(guī)劃報告范本
- 寶石、玉石礦相關(guān)行業(yè)投資方案范本
- 《液壓與氣動》課件 2過濾器
- 日用織物制品相關(guān)行業(yè)投資方案
- 《信客公開》課件
- 汽車吊安全教育培訓(xùn)
- 浙江省寧波市慈溪市2023-2024學(xué)年高二上學(xué)期期末考試 物理 含解析
- 2024七年級數(shù)學(xué)上冊第4章相交線與平等線項目學(xué)習(xí)2包裝中的智慧習(xí)題課件新版華東師大版
- 碼頭安全生產(chǎn)知識培訓(xùn)
- 老年科護(hù)理查房護(hù)理病歷臨床病案
- Python語言基礎(chǔ)與應(yīng)用學(xué)習(xí)通超星期末考試答案章節(jié)答案2024年
- 消除“艾梅乙”醫(yī)療歧視-從我做起
- 古代名劇鑒賞學(xué)習(xí)通超星期末考試答案章節(jié)答案2024年
- 2024年廣西公需科目一帶-路題庫參考答案
- GB/T 35136-2024智能家居自動控制設(shè)備通用技術(shù)要求
- 腕管綜合征護(hù)理常規(guī)
評論
0/150
提交評論