Giter Site home page Giter Site logo

microchip-pic-avr-examples / pic18f57q43-audio-record-playback Goto Github PK

View Code? Open in Web Editor NEW
4.0 5.0 2.0 2.7 MB

This is a demo code for Q43 devices that uses CIPs to perform audio recording and playback operations.

Makefile 0.95% C 99.05%
audio cip digital-audio dma flash mcc

pic18f57q43-audio-record-playback's Introduction

MCHP

Audio Recording and Playback using DMA and CIPs

This demo is based on the PIC18F57Q43 Curiosity Nano platform. It details the usage of ADC for sound recording, SPI for interfacing with the external memory module, DAC for playback, DMA for data transfers, and the use of timers to define sampling frequency. The application also demonstrates the use of Timer2 HLT and CLC for switch debouncing, and the Comparator and PWM for class D power amplification.

Related Documentation

  • Audio Recording and Playback Using Direct Memory Access and Core Independent Peripherals (AN3548)

Software Used

Hardware Used

Hardware Setup

The necessary connections between the PIC18F57Q43 Curiosity Nano board and the required click boards are shown below:

  • The Click 1 expansion connects to the Mic click board. This uses the AN1 pin to transfer analog voice signal to the ADC on-board the PIC18F57Q43. The Mic click has a signal conditioning and filtering circuit on board
  • The Click 2 expansion connects to the Flash 2 click board. This board has the SST26VF064B Flash memory chip by Microchip and uses SPI to communicate with the microcontroller
  • The Click 3 expansion connects to a custom made Class D power amplifier circuit on a PROTO Click

Curiosity Nano Board Connections

Curiosity Nano Board Connections

PROTO Click Circuit

PROTO Click Circuit

Full System Setup

Full System Setup

Proto Click

Proto Click

Software Setup

MCC is used to configure the following. Refer to the MPLAB X project for details and settings for each component.

  • System setup - CPU and Interrupts
  • TMR0 - used to generate 10 kHz sampling timer
  • ADCC - used for sampling and quantization of analog audio signal
  • DAC1 - used to output the analog audio signal
  • SPI1 - used to communicate with external memory module
  • DMA (DMA1, DMA2, DMA3, DMA4, DMA5, DMA6) - data transfer operations
  • PWM1 - used to create a sawtooth waveform for the audio amplifier
  • CMP1 - used to compare sawtooth waveform with DC-offset DAC output to produce PWM signal to drive the audio speaker
  • TMR2/4 - along with CLC1/2, are used to debounce buttons
  • CLC1/2 - along with TMR2/4, are used to debounce buttons
  • UART1 - used for sending and receiving debug messages

Operation

To run the application, use the button on the Curiosity Nano board.

  • By default, the application is in "Idle" mode.
  • Double press the button to enter "Record" mode. The system will keep recording until the button is pressed again to stop, or it runs out of memory. If an external memory is present, recording will be stored there. Otherwise the recording will be stored in internal flash memory.
  • Press the button once to enter "Playback" mode. The system will keep playing the recorded audio stored in the memory until the button is pressed again to stop, or if the entire recording is played.
  • Long press the button to enter "Erase" mode and erase the entire recording from the memory.

A special button is available on the PROTO Click along with the amplifier. Long press this button to enter "Passthrough" mode in which the system acts as a simple amplifier and does not record and store the audio. Press this special button again to leave the "Passthrough" mode.

The audio will be played through the class D amplifier on PROTO Click. There are two jumpers onboard the PROTO Click:

  • Jumper J1 selects the audio input source between Mic Click and Headphone Mic. (Always select Mic Click when headphone mic is not connected to the 3.5mm audio jack)
  • Jumper J2 selects the audio output between external speaker and 3.5mm audio jack. An external speaker or a headphone can be connected to the 3.5mm audio jack.

Note: It is recommended to avoid selecting headphones for both audio output and mic input together in "Passthrough" mode to avoid noise induction.

Summary

The DMA is a great way to transfer data between registers, RAM and Flash in different configurations. It allows for speed and ease of use, in addition to freeing up the CPU to perform other tasks.

The DAC allows for much better reproduction of sampled audio signals because of the higher 8-bit resolution. The buffered output of the DAC forms a great connection to different peripherals directly, without degrading the signal. This can be used along with the PWM and Comparator to form an excellent class D power amplifier.

Timer2 HLT can be combined with CLC for an excellent code-free switch debouncing technique.

pic18f57q43-audio-record-playback's People

Contributors

aku-work avatar ashishmakthal avatar dmtc76375 avatar gauranggunde avatar prasad-aradhya avatar shaimahusain avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

pic18f57q43-audio-record-playback's Issues

Problem with MPLAB X IDE debugger with FLASH erase and write MCC library

first thank for your help.

I am using MPLAB X IDE and MPLAB Code Configurator (MCC).

i generated the library of the flash read/write and erase with MCC.

then when i used "FLASH_ReadPage" built in function created from the MCC its not working, and after debugging i found it stucked in a while loop that is checking for "NVMCON0bits.GO" to be cleared and its never cleared thats why its stucked.

here is the function:

void FLASH_ReadPage(uint32_t flashAddr) { uint8_t GIEBitValue = INTCON0bits.GIE; // Save interrupt enable

//Set NVMADR with the target word address
NVMADRU = (uint8_t) ((flashAddr & 0x00FF0000) >> 16);
NVMADRH = (uint8_t) ((flashAddr & 0x0000FF00) >> 8);
NVMADRL = (uint8_t) (flashAddr & 0x000000FF);

//Set the NVMCMD control bits for Page Read operation
NVMCON1bits.NVMCMD = 0b010;

//Disable all interrupt
INTCON0bits.GIE = 0;

//Perform the unlock sequence
NVMLOCK = 0x55;
NVMLOCK = 0xAA;

//Start page read and wait for the operation to complete
NVMCON0bits.GO = 1;
while (NVMCON0bits.GO); <----- Stucked here

//Restore the interrupts
INTCON0bits.GIE = GIEBitValue;

//Set the NVMCMD control bits for Word Read operation to avoid accidental writes
NVMCON1bits.NVMCMD = 0b000;
}

please any help. because i found in you code you are using the same MCC library i want to know did u face any issues during debug in MPLAB???

thanks and please if you can supply me with your email. thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.