NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

Experiment 4

part 1:Generate 4 different
Frequencies using the 4 Timers

*T1:50HZ:RB5
*T0:200HZ:RB3
*T2:400HZ:RB4
*T3:100HZ:RB6
------
ISIS:
pin 25:with virtual terminal
oscilloscope pins :
pin A:with pin 38
pin B:with pin 39
pin C:with pin 36
pin D:with pin 37
-----
code:
#include "ee470.h"
unsigned char T0L, T0H, T1L, T1H, T2, T3L, T3H;
void main(void)
{
unsigned int X, N, pre;
unsigned char n;
float Tcyc=0.5e-6, Ttick, T, Ttoggle;
OSCCON=0x70;
ADCON1=0xF;
serial_init(51,1);
TRISB3=0;
TRISB4=0;
TRISB5=0;
TRISB6=0;
T0CON=0b00000010;
T1CON=0x30;
T2CON=0b00000011;
T3CON=0b00110100;
// T0: 200Hz calculations
pre=8; Ttick=pre*Tcyc; T=1.0/200.0; Ttoggle=T/2.0;
N=(unsigned int) (Ttoggle/Ttick); X=0xFFFF+1-N;
T0H=(X>>8); T0L=((X<<8) >> 8);
7 printf("T0: N=%u, Ttoggle=%g, X=%urn", N,Ttoggle,X);
// T1: 50Hz calculations
pre=8; Ttick=pre*Tcyc; T=1.0/50.0; Ttoggle=T/2.0;
N=(unsigned int) (Ttoggle/Ttick); X=0xFFFF+1-N;
T1H=(X>>8); T1L=((X<<8) >> 8);
printf("T1: N=%u, Ttoggle=%g, X=%urn", N,Ttoggle,X);
// T2: 400Hz calculations
pre=16; Ttick=pre*Tcyc; T=1.0/400.0; Ttoggle=T/2.0;
n=(unsigned char) (Ttoggle/Ttick);
PR2=n-1; // Timer2 is an 8-bit timer
printf("T2: n=%u, Ttoggle=%g rn", n,Ttoggle);
// T3: 100Hz calculations
pre=8; Ttick=pre*Tcyc; T=1.0/100.0; Ttoggle=T/2.0;
N=(unsigned int) (Ttoggle/Ttick); X=0xFFFF+1-N;
T3H=(X>>8); T3L=((X<<8) >> 8);
printf("T3: N=%u, Ttoggle=%g, X=%urn", N,Ttoggle,X);
TMR0IF=0;
TMR1IF=0;
TMR2IF=0;
TMR3IF=0;
TMR0ON=1;
TMR1ON=1;
TMR2ON=1;
TMR3ON=1;
while(1)
{
if(TMR0IF==1)
{
TMR0H=T0H;
TMR0L=T0L;
TMR0IF=0;
RB3=RB3^1;
}
if(TMR1IF==1)
{
TMR1H=T1H;
TMR1L=T1L;
TMR1IF=0;
RB5=RB5^1;
}
if(TMR2IF==1)
{
// TMR2=0;
TMR2IF=0;
RB4=RB4^1;
}
if(TMR3IF==1)
{
TMR3H=T3H;
TMR3L=T3L;
TMR3IF=0;
RB6=RB6^1;
}
}
}
###############
part 2:Frequency Measurement
of a Square Wave via counting
Pulses in One second

-----
ISIS:

pin 25 : to virtual terminal

RC0:connected with signal generator (sin)
then connected to osclliscope (pin A)

the other pin in signal generator (squ)
connected to gnd.
--------
code :
#include "ee470.h"
unsigned long NTicksT1;
unsigned char T1prescaler;
float freq;
void main(void) {
unsigned char pres;
OSCCON=0x70; // 8MHz, T machine cycle=4*1/8=0.5us
ADCON1=0xF;
serial_init(51,1);
TRISC0 = 1; // input to get incoming pulses
T1CON=0b00000010; // ext. clk T13CKI=RC0, T1 prescaler=1
T1prescaler=1;
TMR1H=TMR1L=0;
TMR1ON=1;
Delay10KTCYx(200);
TMR1ON=0; // stop Timer1
NTicksT1=T1prescaler*(TMR1L+(TMR1H<<8));// similat to T0 read L then H (Little E)
printf("NTicksT1=%urn",NTicksT1);
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.