You are to write a program to input a signal of 10Hz/*F(Farenheit) via pin PTA13
ID: 3773802 • Letter: Y
Question
You are to write a program to input a signal of 10Hz/*F(Farenheit) via pin PTA13, determine the frequency, and output the temperature via the default serial port on pins USBTX and USBRX at 115200 baud. One method for measuring incoming frequency is to measure the period from rising edge to rising edge then reciprocating. Another possible method is to count the number of pulses in a known amount of time. Update the temperature display 5 times per second.( Must be done in C++ and mostly using a mbed.h library but others can be used. Please put which method you use.)
Explanation / Answer
#include "mbed.h"
Ticker tick;
Serial pc(USBTX, USBRX);
InterruptIn in(p8);
Timer t1;
int t_period = 5,00,000; // This is the period between interrupts in microseconds
float t_freq = 0;
void flip();
int main() {
in.mode(PullDown);
in.rise(&flip);
t1.start();
while (1) {
wait_ms(100);
pc.printf("%f Hz ", t_freq);
}
}
void flip() {
t_period = t1.read_us();
t_freq = (1/(float)t_period)*1000000;
t1.reset();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.