7 years ago.

Create an rising edge interrupt from an input voltage and calculate the period of waveform

I am a complete newbie to programming and I am trying to create a rising edge interrupt from an input voltage waveform and then to calculate the period of the waveform. I have the following program so far which basically acts as an ADC and displays a voltage value back to my PC. Any help or example programs would be greatly appreciated.

  1. include "mbed.h"

Serial pc(USBTX, USBRX);

AnalogIn AinV(p15); sets pin15 as the analogue input pin and names it AinV

float ADC_Voltage_data; defines ADC_Voltage_data as float

int main() { pc.printf("ADC Data Values... \n\r"); creates an opening message while (1) {

ADC_Voltage_data=AinV*3.3;multiplyed by 3.3 to give the correct voltage reading

pc.printf("Voltage %f",ADC_Voltage_data); prints voltage data to the terminal pc.printf("V\n\r"); adds the V after number

wait (0.5); waits 0.5 seconds before reading anolg input pins 15 and 16 } }

2 Answers

Alan Carson
poster
7 years ago.

I have a breadboard set up where a sinusoidal input voltage is input via pin 15 and then it is displayed on the PC which is the above code. But from the original input I have also designed a Schimtt trigger to create a square wave from the original sinusoidal wave I was hoping to input this into the mbed via a different pin and then create a rising edge interrupt to calculate the period and eventually the frequency of the waveform which is going into pin 15.

Thanks any help would be greatly appreciated.

Accepted Answer

Then just check out InterruptIn: http://mbed.org/handbook/InterruptIn

posted by Erik - 21 Oct 2013

Thanks that is a lot of useful info, I can now create an interrupt but do you know if the mbed has a specific function for calculating the period of a waveform?

posted by Alan Carson 21 Oct 2013

I believe someone once made a library for it on the LPC1768 using specific timer inputs. But generally just use a Timer object to measure the time.

posted by Erik - 21 Oct 2013
7 years ago.

Is it a full-scale signal? In that case just use InterruptIn instead of AnalogIn, which can give you a rising edge interrupt.

I have a breadboard set up where a sinusoidal input voltage is input via pin 15 and then it is displayed on the PC which is the above code. But from the original input I have also designed a Schimtt trigger to create a square wave from the original sinusoidal wave I was hoping to input this into the mbed via a different pin and then create a rising edge interrupt to calculate the period and eventually the frequency of the waveform which is going into pin 15.

Thanks any help would be greatly appreciated.

posted by Alan Carson 21 Oct 2013