예제 #1
0
파일: analog.c 프로젝트: rzzzwilson/teensy
void setup()
{
    Serial.begin(38400);
    pinMode(ledPin, OUTPUT);
    pinMode(analogOutPin, OUTPUT);
    analogWriteResolution(8);
}
예제 #2
0
bool PololuMC33926::init()
{
	pinMode(_in1, OUTPUT);
	pinMode(_in2, OUTPUT);
	if((_D1&_D2)==0xFF){
#ifdef CORE_TEENSY
		//increase pwm frequency to 20kHz
		analogWriteFrequency(_in1, 20000); //only works when compiling for teensy... TODO: set teensy flag
		analogWriteFrequency(_in2, 20000); //only works when compiling for teensy... TODO: set teensy flag
#endif
	}
	
	if(_D1!=0xFF){
		pinMode(_D1, OUTPUT);
#ifdef CORE_TEENSY
		analogWriteFrequency(_D1, 20000);
#endif
	}
	else if(_D2!=0xFF){
		pinMode(_D2, OUTPUT);
#ifdef CORE_TEENSY		
		analogWriteFrequency(_D2, 20000);
#endif
	}
	
#ifdef CORE_TEENSY				
	analogWriteResolution(8);
#endif		

	return _battery_voltage_sensor->init();
}
예제 #3
0
파일: LEDs.cpp 프로젝트: saikoLED/TeensyLED
void RGBWLamp::begin(void) {
  for (std::vector<int>::iterator i=_pins.begin(); i != _pins.end(); ++i) {
    pinMode(*i, OUTPUT);
    analogWrite(*i, 0);
    analogWriteFrequency(*i, _PWMfrequency);
  }
  analogWriteResolution(_resolution);
}
예제 #4
0
void FPR_control::set_precision(int pwmBits, int adcBits)
{
	_pwmBits = pwmBits;
	_adcBits = adcBits;
	
	//ADC and PWM precision
	analogWriteResolution(_pwmBits);
	analogReadResolution(_adcBits);
	
}
예제 #5
0
static void startAudioStandard()
{
	//backupPreMozziTimer1(); // not for Teensy 3.1
	
	analogWriteResolution(12);
	adc->setAveraging(0);
	adc->setConversionSpeed(ADC_MED_SPEED); // could be ADC_HIGH_SPEED, noisier
	timer1.begin(teensyAudioOutput, 1000000UL/AUDIO_RATE); 

	//backupMozziTimer1(); // // not for Teensy 3.1
}
예제 #6
0
void setupFlags() {
  analogWriteResolution(PWM_BITS);
  for(uint8_t i = 0; i < FLAG_COUNT; ++i) {
    setupFlagPins(flags[0]);
  }
  
  //TODO: how to deal with other flags?
  attachFlag0Interrupts(flags[0]);

  //TODO: move flags to correct position
}
AudioDestinationNode_T3DAC::AudioDestinationNode_T3DAC()
    : AudioNode(), AudioDestinationNode() {

    _outputSample = 0;

    analogWriteResolution(12);

    cli();
    synthTimer.begin(synth_isr, 1000000.0 / SAMPLE_RATE);
    sei();

}
예제 #8
0
Motor::Motor(int pin1, int pin2) : pin1(pin1), pin2(pin2)
{
    pinMode(pin1, OUTPUT);
    pinMode(pin2, OUTPUT);
    
    // Set up PWM
    analogWriteFrequency(pin1, 20000);
    analogWriteFrequency(pin2, 20000);
    analogWriteResolution(16);
    analogWrite(pin1, 0);
    analogWrite(pin2, 0);
}
예제 #9
0
Motor::Motor() {

  digitalWrite(MOTOR_DRIVER_ENABLE, LOW);
  digitalWrite(MOTOR_DRIVER_GROUND, LOW);
  digitalWrite(MOTOR_DRIVER_LEFT_PWM, LOW);
  digitalWrite(MOTOR_DRIVER_RIGHT_PWM, LOW);

  pinMode(MOTOR_DRIVER_ENABLE, OUTPUT);
  pinMode(MOTOR_DRIVER_GROUND, OUTPUT);
  pinMode(MOTOR_DRIVER_LEFT_PWM, OUTPUT);
  pinMode(MOTOR_DRIVER_RIGHT_PWM, OUTPUT);

  analogWriteFrequency(MOTOR_DRIVER_LEFT_PWM, MOTOR_PWM_FREQUENCY);
  analogWriteFrequency(MOTOR_DRIVER_RIGHT_PWM, MOTOR_PWM_FREQUENCY);
  analogWriteResolution(MOTOR_PWM_RESOLUTION);
}
void setup()
{
    // Configure PWM
    analogWriteResolution(13);
    for (int i = 0; i < 4; i++) {
        pinMode(PINS[i], OUTPUT);
        analogWriteFrequency(PINS[i], ESC_FREQ);
        analogWrite(PINS[i], MIN);
    }

    // Configure Max sonar
    pinMode(MAX_SONAR_PIN, INPUT);
    attachInterrupt(MAX_SONAR_PIN, max_sonar_pin_change, CHANGE);

    // Configure Serial
    Serial.begin(9600);
}
예제 #11
0
static void startAudioStandard()
{
	//backupPreMozziTimer1(); // not for arm
	
#if IS_TEENSY3()
	adc->setAveraging(0);
	adc->setConversionSpeed(ADC_CONVERSION_SPEED::MED_SPEED); // could be HIGH_SPEED, noisier

	analogWriteResolution(12);
	timer1.begin(teensyAudioOutput, 1000000UL/AUDIO_RATE); 
#elif IS_STM32()
        audio_update_timer.pause();
	audio_update_timer.setPeriod(1000000UL/AUDIO_RATE);
	audio_update_timer.setChannel1Mode(TIMER_OUTPUT_COMPARE);
	audio_update_timer.setCompare(TIMER_CH1, 1);  // Interrupt 1 count after each update
	audio_update_timer.attachCompare1Interrupt(pwmAudioOutput);
	audio_update_timer.refresh();
	audio_update_timer.resume();
        
	pinMode(AUDIO_CHANNEL_1_PIN, PWM);
#if (AUDIO_MODE == HIFI)
	pinMode(AUDIO_CHANNEL_1_PIN_HIGH, PWM);
#endif

#define MAX_CARRIER_FREQ (F_CPU/(1<<AUDIO_BITS_PER_CHANNEL))
#if MAX_CARRIER_FREQ < AUDIO_RATE
#error Configured audio resolution is definitely too high at the configured audio rate (and the given CPU speed)
#elif MAX_CARRIER_FREQ < (AUDIO_RATE * 3)
#warning Configured audio resolution may be higher than optimal at the configured audio rate (and the given CPU speed)
#endif

#if MAX_CARRIER_FREQ < (AUDIO_RATE * 5)
	// Generate as fast a carrier as possible
	audio_pwm_timer.setPrescaleFactor(1);
#else
	// No point in generating arbitrarily high carrier frequencies. In fact, if there _is_ any headroom, give the PWM pin more time to swing from HIGH to LOW and BACK, cleanly
	audio_pwm_timer.setPrescaleFactor((int) MAX_CARRIER_FREQ / (AUDIO_RATE * 5));
#endif
	audio_pwm_timer.setOverflow(1 << AUDIO_BITS_PER_CHANNEL);   // Allocate enough room to write all intended bits

#endif
	//backupMozziTimer1(); // // not for arm
}
예제 #12
0
// pwm setup function
void pwmSetup(){
	// set output pins
        pinMode(PWMA, OUTPUT);
        pinMode(DIRA, OUTPUT);
        pinMode(SLPA, OUTPUT);
        pinMode(PWMB, OUTPUT);
        pinMode(DIRB, OUTPUT);
        pinMode(SLPB, OUTPUT);

        // change pwm frequency, PWMA and PWMB are on the same timer
        analogWriteFrequency(PWMA, 20000);

        // set resolution to 10 bits
        analogWriteResolution(10);

        // set pwm to 0
        analogWrite(PWMA, 0);
        analogWrite(PWMB, 0);
}
void setup()
{
    pinMode(IO13, OUTPUT);          /* LED fixed on board */

    analogReadResolution(10);
    analogWriteResolution(8);

#ifdef ENABLE_GROVE_KIT
    Wire.begin();
    lcd.begin(16,2);                /* set LCD to 16 columns, 2 lines */
    lcd.setRGB(0x10, 0x10, 0xe0);   /* LCD backlight goes blue */
#endif   /* ENABLE_GROVE_KIT */

#ifdef ENABLE_BLUEMIX
/* Connect to IBM Watson IoT */
    BluemixClient.connect();
#ifndef ENABLE_BLUEMIX_REGISTERED
    Serial.println((char *)"Connected to IBM Watson IoT (Quickstart mode)");
#else
    Serial.println((char *)"Connected to IBM Watson IoT (Registered mode)");
#endif   /* ENABLE_BLUEMIX_REGISTERED */
#endif   /* ENABLE_BLUEMIX */
}
예제 #14
0
TeensyUnit::TeensyUnit(): Wire(0),
	FPWM_pin {FPWM_1_pin, FPWM_2_pin, FPWM_3_pin, FPWM_4_pin, FPWM_5_pin, FPWM_6_pin},
	SPWM_pin {SPWM_1_pin, SPWM_2_pin, SPWM_3_pin, SPWM_4_pin, SPWM_5_pin, SPWM_6_pin}, 
	Analog_pin {Analog_1_pin, Analog_2_pin, Analog_3_pin, Analog_4_pin, Analog_5_pin, Analog_6_pin},
	sound0(*this, 0),
	sound1(*this, 1),
	sound2(*this, 2),
	sound3(*this, 3),
	sound4(*this, 4),
	sound5(*this, 5),
	sound{sound0, sound1, sound2, sound3, sound4, sound5}
{

	
	//===============================================
	//==== pin initialization ====
	//===============================================

	uint8_t num_ports = 0;
	uint8_t num_pins = 0;
	
	//--- Teensy On-Board ---
	pinMode(indicator_led_pin, OUTPUT);

	//--- Programming Pin ---
	pinMode(PGM_DO_pin, OUTPUT);
	
	//--- FPWM pins ---
	num_ports = sizeof(FPWM_pin)/sizeof(FPWM_pin[0]);
	for (uint8_t j = 0; j<num_ports; j++){
		num_pins = sizeof(FPWM_pin[j])/sizeof(FPWM_pin[j][0]);
		for (uint8_t i = 0; i<num_pins; i++){
			pinMode(FPWM_pin[j][i], OUTPUT);
		}
	}
	
	//--- Analogue pins ---
	num_ports = sizeof(Analog_pin)/sizeof(Analog_pin[0]);
	for (uint8_t j = 0; j<num_ports; j++){
		num_pins = sizeof(Analog_pin[j])/sizeof(Analog_pin[j][0]);
		for (uint8_t i = 0; i<num_pins; i++){
			pinMode(Analog_pin[j][i], INPUT);
		}	
	}
	
	//--- Analogue settings ---
	analogReadResolution(12);
	analogReadAveraging(32);
	analogWriteResolution(8);
	analogWriteFrequency(0, 1600);
	analogWriteFrequency(1, 1600);
	analogWriteFrequency(2, 1600);
	
	//--- Slow PWM driver ----
	spwm = PWMDriver(0x40);

	//--- Multiplexer pins ---
	num_pins = sizeof(I2C_MUL_ADR_pin)/sizeof(I2C_MUL_ADR_pin[0]);
	for (uint8_t i = 0; i<num_pins; i++){
		pinMode(I2C_MUL_ADR_pin[i], OUTPUT);
	}	

	//--- I2C initialization ----
	Wire.begin(I2C_MASTER,0x00, I2C_PINS_18_19, I2C_PULLUP_EXT, I2C_RATE_400);


}
예제 #15
0
/**
 * Configures the DAC in event triggered mode.
 *
 * Configures the DAC to use the module's default configuration, with output
 * channel mode configured for event triggered conversions.
 */
void ZerodioClass::dacConfigure(void){
	analogWriteResolution(10);
	analogWrite(A0, 0);
}
예제 #16
0
파일: hexa2.cpp 프로젝트: raplin/HexaWS2811
void OctoWS2811::begin(void)
{
    uint32_t frequency;


    // set up the buffers
    memset(frameBuffer[0], 0, bufSize);
    memset(frameBuffer[1], 0, bufSize);

    // configure the 8 output pins
    GPIOD_PCOR = 0xFF;
    pinMode(2, OUTPUT);	// strip #1
    pinMode(14, OUTPUT);	// strip #2
    pinMode(7, OUTPUT);	// strip #3
    pinMode(8, OUTPUT);	// strip #4
    pinMode(6, OUTPUT);	// strip #5
    pinMode(20, OUTPUT);	// strip #6
    pinMode(21, OUTPUT);	// strip #7
    pinMode(5, OUTPUT);	// strip #8

#ifdef TWOPORT
#ifdef C8SYNC //don't use pin 15-16 loopback, use something else. You still pretty much need to use pin16 as it has FTM1_CH0 muxed on it. Instead of B0 you could also use A12 (see datasheet)
    GPIOC_PCOR = 0xFF;
    pinMode(28, OUTPUT);	// C8(pin28) -> B0 for sync instead of C0-B0 to free up C0 for an extra LED strip.
#else
    //reserve C0 for pwm (this is default setup of the Octo2811 buffer board, but you can't use C0 for strip output so you only get 15 usable channels)
    GPIOC_PCOR = 0xFE;
#endif
    pinMode(22, OUTPUT);	// PC1 strip #9
    pinMode(23, OUTPUT);	// PC2 strip #10
    pinMode(9, OUTPUT);	// PC3 strip #11
    pinMode(10, OUTPUT);	// PC4 strip #12
    pinMode(13, OUTPUT);	// PC5 strip #13
    pinMode(11, OUTPUT);	// PC6 strip #14
    pinMode(12, OUTPUT);	// PC7 strip #15
#endif

#ifdef DEBUGSYNC
    pinMode(0, OUTPUT);	// B16 sync for scope testing
#endif

    // create the two waveforms for WS2811 low and high bits
    frequency = 800000;
    analogWriteResolution(8);
    analogWriteFrequency(3, frequency);
    analogWriteFrequency(4, frequency);
    analogWrite(3, WS2811_TIMING_T0H);
    analogWrite(4, WS2811_TIMING_T1H);

#ifdef C8SYNCxxxxx
    // Optionally use A12 (pin 3) instead of B0 -  triggers DMA(port B) on rising edge (configure for pin 3's waveform)
#else
    // pin 16 (b0) is FTM1_CH0, triggers DMA(port B) on rising edge (configure mux to output pin 3's waveform)
    CORE_PIN16_CONFIG = PORT_PCR_IRQC(1)|PORT_PCR_MUX(3);
    //pin35 (B0) , mux to FTM1_CH0  IRQC0001 = DMA on rising edge
    pinMode(3, INPUT_PULLUP); // pin 3 (A12, configured by the AnalogWrite(3..) above is no longer needed for PWM so set as input or whatever you like
#endif

#ifdef C8SYNC
    // pin 28 (C8) triggers DMA(port C) on falling edge of low duty waveform
    // pin 28 and 25 must be connected by the user: 25 is output, 28 is input
    pinMode(28, INPUT); //c8
    //PTC8 input,  IRQC0010 = DMA on rising edge
    CORE_PIN28_CONFIG = PORT_PCR_IRQC(2)|PORT_PCR_MUX(1);
#else
    // pin 15 (C0) triggers DMA(port C) on falling edge of low duty waveform
    // pin 15 and 16 must be connected by the user: 16 is output, 15 is input
    pinMode(15, INPUT); //c0
    //pin43 = PTC0 input,  IRQC0010 = DMA on rising edge
    CORE_PIN15_CONFIG = PORT_PCR_IRQC(2)|PORT_PCR_MUX(1);
#endif

    // pin 4 triggers DMA(port A) on falling edge of high duty waveform
    //pin29 = (A13) mux to FTM1_CH1 IRQC0010=DMA on falling edge
    CORE_PIN4_CONFIG = PORT_PCR_IRQC(2)|PORT_PCR_MUX(3);

    // enable clocks to the DMA controller and DMAMUX
    SIM_SCGC7 |= SIM_SCGC7_DMA;
    SIM_SCGC6 |= SIM_SCGC6_DMAMUX;
    DMA_CR = 0;
    DMA_ERQ = 0;

    // DMA channel #1 sets WS2811 high at the beginning of each cycle
#ifndef TWOPORT
    //original octo2811 8-channel DMA setup
    DMA_TCD1_SADDR = &ones;
    DMA_TCD1_SOFF = 0;
    DMA_TCD1_ATTR = DMA_TCD_ATTR_SSIZE(0) | DMA_TCD_ATTR_DSIZE(0);
    DMA_TCD1_NBYTES_MLNO = 1;
    DMA_TCD1_SLAST = 0;
    DMA_TCD1_DADDR = &GPIOD_PSOR;
    DMA_TCD1_DOFF = 0;
    DMA_TCD1_CITER_ELINKNO = bufSize;
    DMA_TCD1_DLASTSGA = 0;
    DMA_TCD1_CSR = DMA_TCD_CSR_DREQ;
    DMA_TCD1_BITER_ELINKNO = bufSize;

    // DMA channel #2 writes the pixel data at 20% of the cycle
    DMA_TCD2_SADDR = frameBuffer[1];
    DMA_TCD2_SOFF = 1;
    DMA_TCD2_ATTR = DMA_TCD_ATTR_SSIZE(0) | DMA_TCD_ATTR_DSIZE(0);
    DMA_TCD2_NBYTES_MLNO = 1;
    DMA_TCD2_SLAST = -bufSize;
    DMA_TCD2_DADDR = &GPIOD_PDOR;
    DMA_TCD2_DOFF = 0;
    DMA_TCD2_CITER_ELINKNO = bufSize;
    DMA_TCD2_DLASTSGA = 0;
    DMA_TCD2_CSR = DMA_TCD_CSR_DREQ;
    DMA_TCD2_BITER_ELINKNO = bufSize;

    // DMA channel #3 clear all the pins low at 48% of the cycle
    DMA_TCD3_SADDR = &ones;
    DMA_TCD3_SOFF = 0;
    DMA_TCD3_ATTR = DMA_TCD_ATTR_SSIZE(0) | DMA_TCD_ATTR_DSIZE(0);
    DMA_TCD3_NBYTES_MLNO = 1;
    DMA_TCD3_SLAST = 0;
    DMA_TCD3_DADDR = &GPIOD_PCOR;
    DMA_TCD3_DOFF = 0;
    DMA_TCD3_CITER_ELINKNO = bufSize;
    DMA_TCD3_DLASTSGA = 0;
    DMA_TCD3_CSR = DMA_TCD_CSR_DREQ | DMA_TCD_CSR_INTMAJOR;
    DMA_TCD3_BITER_ELINKNO = bufSize;
#else
    //DrTune's 16-channel DMA setup

//0x40 byte address gap between sequential ports (a,b,c,d)
#define PORT_SPACING 0x40  /*between ports C and D */
#define MLOFFYES  (1+1) // 2 byte tranfers per minor loop (port C then D)
#define FREEZE_DEST_ADDR_BITS 7 /*force dest address to alternate between ports C+D */

    DMA_CR = (1<<7); //EMLM minor loop enabled;

    //write port C and D in a minor loop
    DMA_TCD1_SADDR = &ones;
    DMA_TCD1_SOFF = 0;
    DMA_TCD1_ATTR = DMA_TCD_ATTR_SSIZE(0) | DMA_TCD_ATTR_DSIZE(0) | (FREEZE_DEST_ADDR_BITS<<3);
    DMA_TCD1_NBYTES_MLOFFYES = MLOFFYES;
    DMA_TCD1_SLAST = 0;
    DMA_TCD1_DADDR = &GPIOC_PSOR;
    DMA_TCD1_DOFF = PORT_SPACING;
    DMA_TCD1_CITER_ELINKNO = bufSize/2;
    DMA_TCD1_DLASTSGA = 0;
    DMA_TCD1_CSR = DMA_TCD_CSR_DREQ;
    DMA_TCD1_BITER_ELINKNO = bufSize/2;

    // DMA channel #2 writes the pixel data at 20% of the cycle
    DMA_TCD2_SADDR = frameBuffer[1];
    DMA_TCD2_SOFF = 1;
    DMA_TCD2_ATTR = DMA_TCD_ATTR_SSIZE(0) | DMA_TCD_ATTR_DSIZE(0) | (FREEZE_DEST_ADDR_BITS<<3);;
    DMA_TCD2_NBYTES_MLOFFYES = MLOFFYES;
    DMA_TCD2_SLAST = -bufSize;
    DMA_TCD2_DADDR = &GPIOC_PDOR;
    DMA_TCD2_DOFF = PORT_SPACING;
    DMA_TCD2_CITER_ELINKNO = bufSize/2;
    DMA_TCD2_DLASTSGA = 0;
    DMA_TCD2_CSR = DMA_TCD_CSR_DREQ;
    DMA_TCD2_BITER_ELINKNO = bufSize/2;

    // DMA channel #3 clear all the pins low at 48% of the cycle
    DMA_TCD3_SADDR = &ones;
    DMA_TCD3_SOFF = 0;
    DMA_TCD3_ATTR = DMA_TCD_ATTR_SSIZE(0) | DMA_TCD_ATTR_DSIZE(0) | (FREEZE_DEST_ADDR_BITS<<3);;
    DMA_TCD3_NBYTES_MLOFFYES = MLOFFYES;
    DMA_TCD3_SLAST = 0;
    DMA_TCD3_DADDR = &GPIOC_PCOR;
    DMA_TCD3_DOFF = PORT_SPACING;
    DMA_TCD3_CITER_ELINKNO = bufSize/2;
    DMA_TCD3_DLASTSGA = 0;
    DMA_TCD3_CSR = DMA_TCD_CSR_DREQ | DMA_TCD_CSR_INTMAJOR;
    DMA_TCD3_BITER_ELINKNO = bufSize/2;

#endif



#ifdef __MK20DX256__
    MCM_CR = MCM_CR_SRAMLAP(1) | MCM_CR_SRAMUAP(0);
    AXBS_PRS0 = 0x1032;
#endif

    // route the edge detect interrupts to trigger the 3 channels
    DMAMUX0_CHCFG1 = 0;
    DMAMUX0_CHCFG1 = DMAMUX_SOURCE_PORTB | DMAMUX_ENABLE;
    DMAMUX0_CHCFG2 = 0;
    DMAMUX0_CHCFG2 = DMAMUX_SOURCE_PORTC | DMAMUX_ENABLE;
    DMAMUX0_CHCFG3 = 0;
    DMAMUX0_CHCFG3 = DMAMUX_SOURCE_PORTA | DMAMUX_ENABLE;


    // enable a done interrupts when channel #3 completes
    NVIC_ENABLE_IRQ(IRQ_DMA_CH3);
    //pinMode(1, OUTPUT); // testing: oscilloscope trigger
}
예제 #17
0
void OsciCanvasInt::init(int delPoint, int delLine)
{
	analogWriteResolution(9);  // set the analog output resolution to 12 bit (512 levels)
	delayPoint = delPoint;
	delayLine = delLine;
}
예제 #18
0
void STICK::init(){
  analogWriteResolution(16);  // analogWrite value 0 to 65535
}