Projekte
workwind
BGX1 firmware
pwm.c
Projekte
Forum
Doku
Öffentliche Projekte
Startseite
Beispielprogramme
Projekte von anderen
Welcome
Username
Passwort
Eingeloggt bleiben
Zugangsdaten vergessen?
Registrieren
Projektverwaltung
⇨ Please choose! ⇦
——————————————————
✎ Create new project...
★ Browse existing projects...
——————————————————
⚬ MotorTest#1
⚬ C Tutorial 8#1
⚬ NIBO2 C Project#1
⚙ C Tutorial 15#1
⚬ 2010_11_18_el_test001#1
BGX1 firmware
adc.c
adc.h
battery.xbm
bgx1_protocol.h
Biene.xbm
display.c
display.h
exclamation.xbm
gfx.c
gfx.h
i2c.c
i2c.h
i2cconf.h
images.c
images.h
iodefs.h
iodefs_bgx1.h
main.c
MarsRover.xbm
Nase.xbm
nicai_logo.xbm
pwm.c
pwm.h
question.xbm
smily1.xbm
smily2.xbm
Project details
Compiler settings
Nachrichten
Sie sind nicht eingeloggt.
Neuigkeiten
★
NiboRoboLib 3.6
2017-01-17: Neue Version 3.6
★
NiboRoboLib 3.4.1
2016-04-16: Neue Version 3.4.1
★
Coding Tutorial
2015-11-22: Jetzt auch für den NIBO burger!
Site-Statistic
7433 private projects
378 public projects
16180353 lines compiled
58212 builds
NIBO
@
bgx1_firmware/pwm.c [read only]
/* BSD-License: Copyright (c) 2007 by Nils Springob, nicai-systems, Germany All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name nicai-systems nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /*! @file pwm.c * @brief Modul zur Erzeugung der Pwm-Signale und Zeitberechnung * @author Nils Springob (nils@nicai-systems.de) * @date 2007-01-05 */ #include <avr/interrupt.h> #include <stdlib.h> #include "pwm.h" #include "iodefs.h" #ifdef __cplusplus extern "C" { #endif #define PWM_SIGNAL_OV TIMER1_OVF_vect #define PWM_TIMER_CNT TCNT1 #define PWM_TIMER_CCRA TCCR1A #define PWM_TIMER_CCRA_INIT _BV(WGM11) | _BV(COM1A1) | _BV(COM1A0) #define PWM_TIMER_CCRB TCCR1B #define PWM_TIMER_CCRB_INIT _BV(CS11) | _BV(WGM13) #define PWM_TIMER_OCRA OCR1A #define PWM_TIMER_IMSK _BV(TOIE1) #define PWM_TIMER_ICR ICR1 #define PWM_TIMER_ICR_INIT 1024 /* Der Timer läuft mit einer Frequenz von 2 MHz und zählt bis 2048. Dadurch wird die Interruptroutine alle 1.024 ms aufgerufen. */ // diese Variablen enthalten die Soll-Werte: uint16_t pwm_channel_A; uint16_t pwm_timer_sub; // zählt bis 1000 (1ms) in 1us Schritten uint16_t pwm_timer_ms; // zählt bis 1000 (1s) in 1ms Schritten uint32_t pwm_timer_sec; // zählt die Sekunden seit Systemstart void pwm_init(void) { pwm_timer_sub = 0; pwm_timer_ms = 0; pwm_timer_sec = 0; pwm_channel_A = 0; clear_output_bit(IO_DISP_LIGHT); activate_output_bit(IO_DISP_LIGHT); PWM_TIMER_CNT = 0; PWM_TIMER_CCRA = PWM_TIMER_CCRA_INIT; PWM_TIMER_CCRB = PWM_TIMER_CCRB_INIT; PWM_TIMER_ICR = PWM_TIMER_ICR_INIT; TIMSK1 |= PWM_TIMER_IMSK; } SIGNAL(PWM_SIGNAL_OV) { pwm_timer_sub+=24; if (pwm_timer_sub>=1000){ pwm_timer_sub-=1000; pwm_timer_ms++; } pwm_timer_ms++; if (pwm_timer_ms>=1000){ pwm_timer_ms-=1000; pwm_timer_sec++; } if (pwm_channel_A>=1023) PWM_TIMER_OCRA = 1024; else PWM_TIMER_OCRA = pwm_channel_A; } #ifdef __cplusplus } // extern "C" #endif
Compiler results:
Werbung
Online
ggT
gilbertosladen335
warrenhinder6456
yongpippin56611594