12 bit linear frequency change

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
Lord Grezington
Flowcode V4 User
Posts: 288
Joined: Wed Nov 02, 2011 11:15 pm
Has thanked: 29 times
Been thanked: 30 times
Contact:

12 bit linear frequency change

Post by Lord Grezington »

Hello

I am looking to use a 12 bit ADC input to vary a frequency of an output between 0 and around 45Khz.

I have chosen to use the PIC18f4423 and I thought that the PWM component may be able to do this. I was hoping not to go down the bit banging route.

The issue I am having is that T=1/f, so trying to get a linear frequency output is difficult.

Any help on this would be appreciated - example V5 codes would be useful too,

thanks

Spanish_dude
Posts: 594
Joined: Thu Sep 17, 2009 7:52 am
Location: Belgium
Has thanked: 63 times
Been thanked: 102 times
Contact:

Re: 12 bit linear frequency change

Post by Spanish_dude »

Doing 45000 / 4096 gives you 11Hz (approx).
Calculate the frequency set by the ADC by doing ADC_val * 45000 / 4096.

The next thing to do is set the PWM so that the frequency output is the same as the one calculated, but I'm not sure the PWM can output all frequencies, especially the lower ones.

There are a lot of website that will calculate the different values to set the PWM register. Search how they calculate the values for the registers and implement it to your code. Your pretty much done if you do this.

PS : If you have Flowcode v5, then I suggest you go to the v5 section of the forum.

Post Reply