rumore di fondo
- Login o registrati per inviare commenti
Ciao come posso eliminre un fastodioso rumore di fondo, su questo codice riesco a visualizzare l'onda (è quadra con le creste arrotondate, la vorrei sinusoidale), purtroppo ho un rumore di fondo, tutte le volte che rilascio il pulsante , come faccio ad eliminarlo?
Ecco il codice:
#include #pragma config FOSC = HS //OSC = HS Set to work for high speed //************************************************************ //************************************************************ //Samples // Repeat the sample for x time //************************************************************ #pragma code high_vector = 0x08 #pragma code void High_Int_Event (void) { static unsigned char sample = 0; if (PIR1bits.TMR2IF == 1) { if (PORTBbits.RB0 == 0) { repeat++; } } if (repeat == REPEATING_FACTOR) { if (sample > 31) { } //Clear Timer 2 Interrupt Flag } //************************************************************ void main (void){ // PORTA settings // PORTB settings // PORTC settings // PORTD settings // PORTE settings //************************************* // Set the PWM frequency to set_duty_cycle (250); // Turn ON TMR2 and set Prescaler to 0 turn_on_PWM1 (); // Enable Timer 2 Interrupt // Standrd interrupt (by default is already 0) // Enable global interrupt // Enable Peripheral Interrupt // just loop for nothing... //************************************ void set_duty_cycle (int duty_cycle) { CCPR1L = (unsigned char) (duty_cycle >> 2); if (duty_cycle & 0x0001) if (duty_cycle & 0x0002) //************************************ CCP1CON = CCP1CON | 0b00001100; }
#pragma config WDT = OFF
#pragma config LVP = OFF
#pragma config PBADEN = OFF
//WDT = OFF watchdog timer is off
//LVP = OFF LVP programming is off
//PBADEN = OFF Analog input on PORTB are off
// Functions Prototypes
//************************************************************
void set_duty_cycle (int duty_cycle);
void turn_on_PWM1 (void);
void High_Int_Event (void);
// Global variables
//************************************************************
int sine[] = {250,299,346,389,427,458,481,495,500,495,481,458,427,389,346,299,250,201,154,111,73,42,19,5,0,5,19,42,73,111,154,201};
// sampling frequency must be changed to keep analog signal frequency costnat
const unsigned char REPEATING_FACTOR = 3;
// Interrupt Handler
//************************************************************
void high_interrupt (void) {
// go to the interrupt handler
_asm GOTO High_Int_Event _endasm
}
#pragma interrupt High_Int_Event
static unsigned char repeat = 0;
set_duty_cycle (sine[sample]);
else {
set_duty_cycle (0);
repeat = 0;
sample++;
sample = 0;
}
}
PIR1bits.TMR2IF = 0;
// Main program
//************************************************************
LATA = 0x00;
TRISA = 0xFF;
LATB = 0x00;
TRISB = 0xFF;
LATC = 0x00;
TRISC = 0b11111010;
LATD = 0x00;
TRISD = 0x00;
LATE = 0x00;
TRISE = 0xFF;
// Modules Initializaion
//*************************************
PR2 = 198;
T2CON = 0x04;
PIE1bits.TMR2IE = 1;
RCONbits.IPEN = 0;
INTCONbits.GIE = 1;
INTCONbits.PEIE = 1 ;
while (1){
}
}
// Set the Diuty Cicle
//************************************
CCP1CONbits.DC1B0 = 0x0001;
else
CCP1CONbits.DC1B0 = 0x0000;
CCP1CONbits.DC1B1 = 0x0001;
else
CCP1CONbits.DC1B1 = 0x0000;
}
// Turn ON the PWM module
//************************************
void turn_on_PWM1 (void) {
Ciao, e ti ringrazio, temo che il problema sia causato dal codice, mi spiego: la frequenza che osservo e sento dallo speaker c'è sempre, quando premo il pulsante visulizzo la forma d'onda (quadra con le creste arrotondate, la vorrei sinusoidale) e sento la freq. impostata nel codice, lo rilascio e torna come prima, mi serve di capire quale parte del codice continua a girare quando non schiaccio il pulsante, ho provato a fare delle prove, e l'unico risultato è stato che non funzionava niente.
- Login o registrati per inviare commenti

















3 ore 56 min fa
Un condensatore di antirimbalzo sul pulsante?
Un filtro firmware per eliminare un rumore di fondo, non è una cosa molto banale da realizzare, forse è meglio intervenire con un filtraggio prima dell'ingresso nel micro.
(se il banale condensatore non è sufficiente :)