===== Description =====
This demo shows how to:
- Read the value of a potentiometer connected to an analog input
- Read buttons and control LEDs on the DB66DEV1 development board (using DB66DEV1 driver located in nz_db66dev1.h)
- Output a frequency with varying duty cycles to a PWM channel. The PWM output is connected to a buzzer, and the duty cycle is used to set the volume.
This demo uses a DB66DEV1 development daughter board. It has 4 buttons, 8 LEDs, a potentiometer and a buzzer.
The potentiometer is used to set the frequency of the buzzer to a value between 255 to 2795 Hz.
Buttons 1 and 2 are used to set the volume to a level between 0 to 8. The volume is represented on the LEDs, with volume 0=all LEDs of, and volume 8 all LEDs on.
The PWM duty cycle is set to a value between 0 to 0.33 depending on the current volume setting.
Additionally this demo also implements debugging via the USB port and the Netcruzer USB Terminal App. During the program various debug messages are written, which will be displayed on the "Netcruzer USB Terminal" (running on a PC connected to the target board's USB port). This demo also monitors the USB port for Debug messages send to us.
- If "hi" is received, it replies with "Hello"
- If "adc" is received, it replies with the analog value of the potentiometer
Use the "Netcruzer USB Terminal" App to send and receive USB Debug messages. It can be downloaded here: https://netcruzer.com/usbterminal/
===== Required Hardware =====
The project requires a SBC66 Netcruzer board with an USB Port (not USB Host), AND a DB66DEV1 development board. The DB66DEV1 is plugged into the daughter board connector of the SBC66 board.
===== Building Project =====
This project is located in the "src/demos/db66dev1/db66dev1_debug_demo" folder of the Netcruzer Download. To compile for Netcruzer Board, open this project in MPLAB X, and select the "Project Configuration" for desired board. For example "SBC66ZL_R1" for the SBC66ZL Revision 1 board. For details click here
===== Programming Board =====
After compiling (build), the board can be programmed via the USB Bootloader or a PIC Programmer. USB Programming is simplified when using the SBC board together with a Prototype Board.
===== File History =====
2013-07-22, David H. (DH):
#define THIS_IS_MAIN_FILE //Uniquely identifies this as the file with the main application entry function main()
#include "HardwareProfile.h"
#if !defined(DEBUG_CONF_MAIN)
#define DEBUG_CONF_MAIN DEBUG_CONF_DEFAULT //Default Debug Level, disabled if DEBUG_LEVEL_ALLOFF defined, else DEBUG_LEVEL_ERROR
#endif
#define MY_DEBUG_LEVEL DEBUG_CONF_MAIN
static WORD potValue = 0, newPotValue = 0;
static BYTE volume = 0, newVolume = 0;
static BYTE buttons;
static WORD tmrFlashLed = 0;
static WORD tmrServiceDB66DEV1 = 0;
int main(void) {
DEBUG_PUT_STR(DEBUG_LEVEL_INFO,
"\nThis is a test debug message from db66dev1 demo");
DIR_SYSLED = OUTPUT_PIN;
db66dev1_Init();
adcOpen(ADC_OPEN_A3);
pwm1OpenDefault(PPS_OUT_34, 0);
while(1)
{
db66dev1_Service();
buttons = db66dev1_ReadLatchedButtons();
if(buttons & 0x02) {
if (newVolume < 8)
newVolume++;
}
if(buttons & 0x01) {
if (newVolume != 0)
newVolume--;
}
newPotValue = adcReadChan8BitForIndex(0);
if ( (potValue!=newPotValue) || (newVolume!=volume) ) {
WORD pwmPeriod;
float dcRatio;
potValue = newPotValue;
volume = newVolume;
db66dev1_WriteLeds(0xff >> (8-volume));
pwmPeriod = 0xffff - (potValue * 250);
pwmSetPeriod(1, pwmPeriod);
dcRatio = (((float)(volume*volume)) / 192.0);
pwmSetDutyCycle(1,((float)pwmPeriod)*dcRatio);
printf(
"\nSetting f=%.0fHz and dc=%.2f", (
double)pwmGetFrequency(1), (
double)dcRatio);
}
}
LAT_SYSLED = !LAT_SYSLED;
}
}
}
#if defined(HAS_NZ_DEBUGGING)
void debugService(void) {
debugPutString("\nHello");
}
debugPutString("\nADC = ");
debugPutWord(adcReadChan8BitForIndex(0));
}
}
}
#endif