From d5a5b17770c3768ef3b355ac1fd407d4683fa45f Mon Sep 17 00:00:00 2001 From: Cynopolis Date: Tue, 25 Oct 2022 11:56:29 -0500 Subject: [PATCH] Frequency Modulation now works --- src/main.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 4e60472..67214aa 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -129,11 +129,11 @@ void setPWMFrequency(uint32_t frequency, uint32_t pwmPin) { TC_SetRC(chTC, chNo, TC); TC_SetRA(chTC, chNo, 127*TC/255); - // read counter value - uint32_t ulValue = TC_GetCV(chTC, chNo); - - // reset the counter - // TC_Start(chTC, chNo); + // if the current reset value is less than the current counter value... + if(TC < TC_ReadCV(chTC, chNo)){ + // counter overflowed, so reset it + TC_Start(chTC, chNo); + } } @@ -171,7 +171,7 @@ void loop() { // Read the message signal and map it to a value from 90 to -90 us. // 90 microseconds corresponds to half of 22 kHz (an audio input signal). FM_factor = fastAnalogRead(ADC_CHANNEL_0); - FM_factor = map(FM_factor, 0, 4095, 1000, -1000); + FM_factor = map(FM_factor, 0, 4095, 10000, -10000); //modulate the carrier signal with the message signal by changing the reset value of the timer // TC_SetRC(TC2, 0, 997 + FM_factor); sig_frequency = 42000 + FM_factor;