NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

Experiment 3

part 1 :Generate Square Wave
having 50% duty cycle
using Timer1

ISIS:
RA0: connected to OSCilloscpe
(pin A)

------
code :
#include "ee470.h"
void main(void)
{
float fosc, Tosc, Tmc, f, T, Ttoggle;
unsigned int Ntoggle, ntmr1;
unsigned char t1h, t1l;
ADCON1=0xF; OSCCON=0x70; // 8MHz internal clk
TRISA0 = 0;
PORTAbits.RA0 = 0; // o/p pin
T1CON = 0x0; // T1:int. clk, no prescale, TMR1ON=0
fosc=8e6; Tmc=4*1/fosc; f=1e3; T=1.0/f; Ttoggle=T/2;
Ntoggle=(unsigned int) (Ttoggle/Tmc);
ntmr1=(0xFFFF+1)-Ntoggle;
t1h=ntmr1/256; t1l=ntmr1%256;
TMR1IF = 0;
T1CONbits.TMR1ON = 1;
while(1)
{
while (TMR1IF == 0);
PORTAbits.RA0 = ~PORTAbits.RA0;
TMR1H=t1h; TMR1L=t1l;
TMR1IF=0;
}
}
############
part 2 :
Generate Variable Duty Cycle
Square Wave using Timer1
**produce on pin RA0 a
periodic signal of period 1ms and duty
cycle=70%.

ISIS:
RA0:with pin A on OScilloscope

------
code:
#include "ee470.h"
void main(void)
{
float fosc, Tosc, Tmc, f, T;
unsigned int ntmr1onplusoff, ntmr1on, ntmr1off;
unsigned char t1hon, t1lon, t1hoff, t1loff;
ADCON1=0xF; OSCCON=0x70;
TRISA0 = 0;
PORTAbits.RA0 = 0;
T1CON = 0x0;
fosc=8e6; Tmc=4*1/fosc; f=1e3; T=1.0/f;
ntmr1onplusoff=(unsigned int) (T/Tmc);
ntmr1on=(0xFFFF+1)-ntmr1onplusoff*0.7;
ntmr1off=(0xFFFF+1)-ntmr1onplusoff*0.3;
t1hon=ntmr1on/256; t1lon=ntmr1on%256;
t1hoff=ntmr1off/256; t1loff=ntmr1off%256;
TMR1IF = 0;
T1CONbits.TMR1ON = 1;
while(1)
{
while (TMR1IF == 0);
PORTAbits.RA0 = 1;
TMR1H=t1hon; TMR1L=t1lon;
TMR1IF=0;
while (TMR1IF == 0);
PORTAbits.RA0 = 0;
TMR1H=t1hoff; TMR1L=t1loff;
TMR1IF=0;
}
}
------------
part3: Measuring the ON time
of a square pulse
*measure the ON time of a pulse
(half duration of a square wave)
applied to pin RD0.

ISIS:
pin 25:connected to Virtual terminal
pin 19:to signal generator(sin)
pin 30:to led to res=330 to gnd and
to signal generator (square wave)
-----
code:
#include "ee470.h"
void main(void)
{
unsigned int duration;
float fd;
OSCCON=0x40;
ADCON1=0xF;
serial_init(201,1);
;
TRISD0=1;
TRISD7=0;
RD7=0;
T1CON=0b00000000;
TMR1H=0;
TMR1L=0;
while(RD0==0);
RD7=1;
TMR1ON=1;
while(RD0==1);
TMR1ON=0;
duration=TMR1H*256+TMR1L;
fd=duration*4.0/fosc;
printf("duration in machine cycles=%u and in usec=%f rn",duration, fd);
printf("Frequency in Hz=%frn",1000000.0/fd/2);
while(1);
}
---------------
part 4:Use T1 to measure on-time
and oFF-time of a variable
duty cycle of a periodic signal

ISIS:
RA0: connected to oscilloscope
(pin A)
-----
code:
#include "ee470.h"
void main(void)
{
float ttick, on_time, off_time, period;
unsigned char tonl, tonh, toffl, toffh;
OSCCON=0x70;
ADCON1=0xF;
serial_init(51,1);
ttick=4.0/(fosc);
;
TRISD0=1;
TRISD7=0;
RD7=0;
T1CON=0b00000000;
TMR1ON=1;
while(RD0==1);
while(RD0==0);
RD7=1;
TMR1H=0;
TMR1L=0;
while(RD0==1);
tonl=TMR1L; tonh=TMR1H;
while(RD0==0);
while(RD0==1);
RD7=0;
TMR1H=0;
TMR1L=0;
while(RD0==0);
toffl=TMR1L; toffh=TMR1H;
on_time=(tonh*256+tonl)*ttick;
off_time=(toffh*256+toffl)*ttick;
printf("on time=%g off time=%g nr",on_time,off_time);
period=on_time+off_time;
printf("period in sec = %g, frequency in Hz=%grn",period,1.0/period);
while(1);
}
     
 
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.